Mercurial > mplayer.hg
annotate libmpdemux/demux_real.c @ 4039:3949bfd612fd
I was missing it ...
author | jaf |
---|---|
date | Mon, 07 Jan 2002 20:13:20 +0000 |
parents | 701d18898835 |
children | c6a61c091222 |
rev | line source |
---|---|
3777 | 1 /* |
2 Real parser & demuxer | |
3 | |
4 (C) Alex Beregszaszi <alex@naxine.org> | |
5 | |
6 Based on FFmpeg's libav/rm.c. | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
7 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
8 $Log$ |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
9 Revision 1.6 2002/01/04 19:32:58 alex |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
10 updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes) |
3788 | 11 |
3795 | 12 |
13 Audio codecs: (supported by RealPlayer8 for Linux) | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
14 ATRC - RealAudio 8 (ATRAC3) - www.minidisc.org/atrac3_article.pdf, |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
15 ACM decoder uploaded, needs some fine-tuning to work |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
16 COOK/COKR - RealAudio G2 |
3795 | 17 DNET - RealAudio 3.0 |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
18 SIPR - SiproLab's audio codec, ACELP decoder working with MPlayer, |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
19 needs fine-tuning too :) |
3795 | 20 |
21 Video codecs: (supported by RealPlayer8 for Linux) | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
22 RV10 - H.263 based, working with libavcodec's decoder |
3795 | 23 RV20 |
24 RV30 | |
3788 | 25 */ |
26 | |
3777 | 27 #include <stdio.h> |
28 #include <stdlib.h> | |
29 #include <unistd.h> | |
30 | |
31 #include "config.h" | |
32 #include "mp_msg.h" | |
33 #include "help_mp.h" | |
34 | |
35 #include "stream.h" | |
36 #include "demuxer.h" | |
37 #include "stheader.h" | |
38 #include "bswap.h" | |
39 | |
40 #define MKTAG(a, b, c, d) (a | (b << 8) | (c << 16) | (d << 24)) | |
41 | |
42 #define MAX_STREAMS 10 | |
43 | |
44 typedef struct { | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
45 int timestamp; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
46 int offset; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
47 int packetno; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
48 } real_index_table_t; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
49 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
50 typedef struct { |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
51 /* for seeking */ |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
52 int index_chunk_offset; |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
53 real_index_table_t *index_table[MAX_STREAMS]; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
54 // int *index_table[MAX_STREAMS]; |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
55 int index_table_size[MAX_STREAMS]; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
56 int data_chunk_offset; |
3777 | 57 int num_of_packets; |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
58 int current_packet; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
59 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
60 /* stream id table */ |
3777 | 61 int last_a_stream; |
62 int a_streams[MAX_STREAMS]; | |
63 int last_v_stream; | |
64 int v_streams[MAX_STREAMS]; | |
65 } real_priv_t; | |
66 | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
67 /* originally from FFmpeg */ |
3777 | 68 static void get_str(int isbyte, demuxer_t *demuxer, char *buf, int buf_size) |
69 { | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
70 int len; |
3777 | 71 |
72 if (isbyte) | |
73 len = stream_read_char(demuxer->stream); | |
74 else | |
75 len = stream_read_word(demuxer->stream); | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
76 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
77 stream_read(demuxer->stream, buf, (len > buf_size) ? buf_size : len); |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
78 if (len > buf_size) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
79 stream_skip(demuxer->stream, len-buf_size); |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
80 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
81 printf("read_str: %d bytes read\n", len); |
3777 | 82 } |
83 | |
84 static void skip_str(int isbyte, demuxer_t *demuxer) | |
85 { | |
86 int len; | |
87 | |
88 if (isbyte) | |
89 len = stream_read_char(demuxer->stream); | |
90 else | |
91 len = stream_read_word(demuxer->stream); | |
92 | |
93 stream_skip(demuxer->stream, len); | |
94 | |
95 printf("skip_str: %d bytes skipped\n", len); | |
96 } | |
97 | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
98 static void parse_index_chunk(demuxer_t *demuxer) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
99 { |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
100 real_priv_t *priv = demuxer->priv; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
101 int origpos = stream_tell(demuxer->stream); |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
102 int next_header_pos = priv->index_chunk_offset; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
103 int i, entries, stream_id; |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
104 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
105 read_index: |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
106 stream_seek(demuxer->stream, next_header_pos); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
107 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
108 i = stream_read_dword_le(demuxer->stream); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
109 if ((i == -256) || (i != MKTAG('I', 'N', 'D', 'X'))) |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
110 { |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
111 printf("Something went wrong, no index chunk found on given address (%d)\n", |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
112 next_header_pos); |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
113 goto end; |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
114 } |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
115 |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
116 printf("Reading index table from index chunk (%d)\n", |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
117 next_header_pos); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
118 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
119 i = stream_read_dword(demuxer->stream); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
120 printf("size: %d bytes\n", i); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
121 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
122 i = stream_read_word(demuxer->stream); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
123 if (i != 0) |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
124 printf("Hmm, index table with unknown version (%d), please report it to MPlayer developers!\n", i); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
125 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
126 entries = stream_read_dword(demuxer->stream); |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
127 printf("entries: %d\n", entries); |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
128 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
129 stream_id = stream_read_word(demuxer->stream); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
130 printf("stream_id: %d\n", stream_id); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
131 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
132 next_header_pos = stream_read_dword(demuxer->stream); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
133 printf("next_header_pos: %d\n", next_header_pos); |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
134 if (entries <= 0) |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
135 { |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
136 if (next_header_pos) |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
137 goto read_index; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
138 i = entries; |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
139 goto end; |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
140 } |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
141 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
142 priv->index_table_size[stream_id] = entries; |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
143 priv->index_table[stream_id] = malloc(priv->index_table_size[stream_id] * sizeof(real_index_table_t)); |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
144 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
145 for (i = 0; i < entries; i++) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
146 { |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
147 stream_skip(demuxer->stream, 2); /* version */ |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
148 priv->index_table[stream_id][i].timestamp = stream_read_dword(demuxer->stream); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
149 priv->index_table[stream_id][i].offset = stream_read_dword(demuxer->stream); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
150 priv->index_table[stream_id][i].packetno = stream_read_dword(demuxer->stream); |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
151 printf("Index table: Stream#%d: entry: %d: pos: %d\n", |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
152 stream_id, i, priv->index_table[stream_id][i].offset); |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
153 } |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
154 demuxer->seekable = 1; /* got index, we're able to seek */ |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
155 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
156 if (next_header_pos > 0) |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
157 goto read_index; |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
158 |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
159 printf("End of index tables\n"); |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
160 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
161 end: |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
162 if (i == -256) |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
163 stream_reset(demuxer->stream); |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
164 stream_seek(demuxer->stream, origpos); |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
165 } |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
166 |
3795 | 167 int real_check_file(demuxer_t* demuxer) |
168 { | |
3777 | 169 real_priv_t *priv; |
170 int c; | |
171 | |
172 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for REAL\n"); | |
173 | |
174 c = stream_read_dword_le(demuxer->stream); | |
175 if (c == -256) | |
176 return 0; /* EOF */ | |
177 if (c != MKTAG('.', 'R', 'M', 'F')) | |
178 return 0; /* bad magic */ | |
179 | |
180 priv = malloc(sizeof(real_priv_t)); | |
181 memset(priv, 0, sizeof(real_priv_t)); | |
182 demuxer->priv = priv; | |
183 | |
184 return 1; | |
185 } | |
186 | |
187 // return value: | |
188 // 0 = EOF or no stream found | |
189 // 1 = successfully read a packet | |
190 int demux_real_fill_buffer(demuxer_t *demuxer) | |
191 { | |
192 real_priv_t *priv = demuxer->priv; | |
193 demux_stream_t *ds = NULL; | |
194 int len; | |
195 int timestamp; | |
196 int stream_id; | |
197 int i; | |
3795 | 198 int flags; |
3777 | 199 |
200 // printf("num_of_packets: %d\n", priv->num_of_packets); | |
201 | |
202 loop: | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
203 if ((priv->num_of_packets == 0) && (priv->num_of_packets != -10)) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
204 return 0; /* EOF */ |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
205 if (priv->current_packet > priv->num_of_packets) |
3777 | 206 return 0; /* EOF */ |
3795 | 207 stream_skip(demuxer->stream, 2); /* version */ |
3777 | 208 len = stream_read_word(demuxer->stream); |
209 if (len == -256) /* EOF */ | |
210 return 0; | |
211 if (len < 12) | |
212 { | |
213 printf("bad packet len (%d)\n", len); | |
214 stream_skip(demuxer->stream, len); | |
215 goto loop; | |
216 } | |
217 stream_id = stream_read_word(demuxer->stream); | |
218 timestamp = stream_read_dword(demuxer->stream); | |
219 | |
220 stream_skip(demuxer->stream, 1); /* reserved */ | |
3795 | 221 flags = stream_read_char(demuxer->stream); |
222 /* flags: */ | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
223 /* 0x1 - reliable */ |
3795 | 224 /* 0x2 - keyframe */ |
225 | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
226 // printf("packet#%d: pos: %d, len: %d, stream_id: %d, timestamp: %d, flags: %x\n", |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
227 // priv->current_packet, stream_tell(demuxer->stream)-12, len, stream_id, timestamp, flags); |
3777 | 228 |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
229 // if (priv->num_of_packets != -10) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
230 // priv->num_of_packets--; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
231 priv->current_packet++; |
3777 | 232 len -= 12; |
233 | |
234 /* check if stream_id is audio stream */ | |
235 for (i = 0; i < priv->last_a_stream; i++) | |
236 { | |
237 if (priv->a_streams[i] == stream_id) | |
238 { | |
239 // printf("packet is audio (id: %d)\n", stream_id); | |
240 ds = demuxer->audio; /* FIXME */ | |
241 break; | |
242 } | |
243 } | |
244 /* check if stream_id is video stream */ | |
245 for (i = 0; i < priv->last_v_stream; i++) | |
246 { | |
247 if (priv->v_streams[i] == stream_id) | |
248 { | |
249 // printf("packet is video (id: %d)\n", stream_id); | |
250 ds = demuxer->video; /* FIXME */ | |
251 break; | |
252 } | |
253 } | |
254 | |
255 /* id not found */ | |
256 if (ds == NULL) | |
257 { | |
258 printf("unknown stream id (%d)\n", stream_id); | |
259 stream_skip(demuxer->stream, len); | |
260 goto loop; | |
261 } | |
262 | |
263 demuxer->filepos = stream_tell(demuxer->stream); | |
3795 | 264 ds_read_packet(ds, demuxer->stream, len, timestamp/90000.0f, |
265 demuxer->filepos, (flags & 0x2) ? 0x10 : 0); | |
3777 | 266 |
267 return 1; | |
268 } | |
269 | |
270 void demux_open_real(demuxer_t* demuxer) | |
271 { | |
272 real_priv_t* priv = demuxer->priv; | |
273 int num_of_headers; | |
274 int i; | |
275 | |
276 stream_skip(demuxer->stream, 4); /* header size */ | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
277 stream_skip(demuxer->stream, 2); /* version */ |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
278 // stream_skip(demuxer->stream, 4); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
279 i = stream_read_dword(demuxer->stream); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
280 printf("File version: %d\n", i); |
3777 | 281 num_of_headers = stream_read_dword(demuxer->stream); |
282 // stream_skip(demuxer->stream, 4); /* number of headers */ | |
283 | |
284 /* parse chunks */ | |
285 for (i = 1; i < num_of_headers; i++) | |
286 { | |
287 int chunk, chunk_size; | |
288 | |
289 chunk = stream_read_dword_le(demuxer->stream); | |
290 chunk_size = stream_read_dword(demuxer->stream); | |
291 | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
292 stream_skip(demuxer->stream, 2); /* version */ |
3777 | 293 |
294 if (chunk_size < 10) | |
295 goto fail; | |
296 | |
297 printf("Chunk: %.4s (size: %d)\n", | |
298 (char *)&chunk, chunk_size); | |
299 | |
300 switch(chunk) | |
301 { | |
302 case MKTAG('P', 'R', 'O', 'P'): | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
303 /* Properties header */ |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
304 |
3777 | 305 stream_skip(demuxer->stream, 4); /* max bitrate */ |
306 stream_skip(demuxer->stream, 4); /* avg bitrate */ | |
307 stream_skip(demuxer->stream, 4); /* max packet size */ | |
308 stream_skip(demuxer->stream, 4); /* avg packet size */ | |
309 stream_skip(demuxer->stream, 4); /* nb packets */ | |
310 stream_skip(demuxer->stream, 4); /* duration */ | |
311 stream_skip(demuxer->stream, 4); /* preroll */ | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
312 priv->index_chunk_offset = stream_read_dword(demuxer->stream); |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
313 printf("First index chunk offset: 0x%x\n", priv->index_chunk_offset); |
3795 | 314 priv->data_chunk_offset = stream_read_dword(demuxer->stream)+10; |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
315 printf("First data chunk offset: 0x%x\n", priv->data_chunk_offset); |
3777 | 316 stream_skip(demuxer->stream, 2); /* nb streams */ |
3795 | 317 #if 0 |
3777 | 318 stream_skip(demuxer->stream, 2); /* flags */ |
3795 | 319 #else |
320 { | |
321 int flags = stream_read_word(demuxer->stream); | |
322 printf("Flags (%x): ", flags); | |
323 if (flags & 0x1) | |
324 printf("[save allowed] "); | |
325 if (flags & 0x2) | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
326 printf("[perfect play (more buffers)] "); |
3795 | 327 if (flags & 0x4) |
328 printf("[live broadcast] "); | |
329 printf("\n"); | |
330 } | |
331 #endif | |
3777 | 332 break; |
333 case MKTAG('C', 'O', 'N', 'T'): | |
3788 | 334 { |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
335 /* Content description header */ |
3788 | 336 char *buf; |
337 int len; | |
338 | |
339 len = stream_read_word(demuxer->stream); | |
340 if (len > 0) | |
341 { | |
342 buf = malloc(len+1); | |
343 stream_read(demuxer->stream, buf, len); | |
344 demux_info_add(demuxer, "name", buf); | |
345 free(buf); | |
346 } | |
347 | |
348 len = stream_read_word(demuxer->stream); | |
349 if (len > 0) | |
350 { | |
351 buf = malloc(len+1); | |
352 stream_read(demuxer->stream, buf, len); | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
353 buf[len] = 0; |
3788 | 354 demux_info_add(demuxer, "author", buf); |
355 free(buf); | |
356 } | |
357 | |
358 len = stream_read_word(demuxer->stream); | |
359 if (len > 0) | |
360 { | |
361 buf = malloc(len+1); | |
362 stream_read(demuxer->stream, buf, len); | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
363 buf[len] = 0; |
3788 | 364 demux_info_add(demuxer, "copyright", buf); |
365 free(buf); | |
366 } | |
367 | |
368 len = stream_read_word(demuxer->stream); | |
369 if (len > 0) | |
370 { | |
371 buf = malloc(len+1); | |
372 stream_read(demuxer->stream, buf, len); | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
373 buf[len] = 0; |
3788 | 374 demux_info_add(demuxer, "comment", buf); |
375 free(buf); | |
376 } | |
3777 | 377 break; |
3788 | 378 } |
3777 | 379 case MKTAG('M', 'D', 'P', 'R'): |
380 { | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
381 /* Media properties header */ |
3777 | 382 int stream_id; |
383 int bitrate; | |
384 int codec_data_size; | |
385 int codec_pos; | |
3795 | 386 int tmp; |
3777 | 387 |
388 stream_id = stream_read_word(demuxer->stream); | |
389 printf("Found new stream (id: %d)\n", stream_id); | |
390 | |
391 stream_skip(demuxer->stream, 4); /* max bitrate */ | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
392 bitrate = stream_read_dword(demuxer->stream); /* avg bitrate */ |
3777 | 393 stream_skip(demuxer->stream, 4); /* max packet size */ |
394 stream_skip(demuxer->stream, 4); /* avg packet size */ | |
395 stream_skip(demuxer->stream, 4); /* start time */ | |
396 stream_skip(demuxer->stream, 4); /* preroll */ | |
397 stream_skip(demuxer->stream, 4); /* duration */ | |
398 | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
399 skip_str(1, demuxer); /* stream description (name) */ |
3777 | 400 skip_str(1, demuxer); /* mimetype */ |
401 | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
402 /* Type specific header */ |
3777 | 403 codec_data_size = stream_read_dword(demuxer->stream); |
404 codec_pos = stream_tell(demuxer->stream); | |
405 | |
3795 | 406 tmp = stream_read_dword(demuxer->stream); |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
407 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
408 if (tmp == MKTAG(0xfd, 'a', 'r', '.')) |
3777 | 409 { |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
410 /* audio header */ |
3777 | 411 sh_audio_t *sh = new_sh_audio(demuxer, stream_id); |
3795 | 412 char buf[128]; /* for codec name */ |
413 int frame_size; | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
414 int version; |
3777 | 415 |
416 printf("Found audio stream!\n"); | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
417 version = stream_read_word(demuxer->stream); |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
418 printf("version: %d\n", version); |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
419 // stream_skip(demuxer->stream, 2); /* version (4 or 5) */ |
3788 | 420 stream_skip(demuxer->stream, 2); |
421 stream_skip(demuxer->stream, 4); /* .ra4 or .ra5 */ | |
3777 | 422 stream_skip(demuxer->stream, 4); |
3788 | 423 stream_skip(demuxer->stream, 2); /* version (4 or 5) */ |
3777 | 424 stream_skip(demuxer->stream, 4); /* header size */ |
425 stream_skip(demuxer->stream, 2); /* add codec info */ | |
426 stream_skip(demuxer->stream, 4); /* coded frame size */ | |
427 stream_skip(demuxer->stream, 4); | |
428 stream_skip(demuxer->stream, 4); | |
429 stream_skip(demuxer->stream, 4); | |
430 stream_skip(demuxer->stream, 2); /* 1 */ | |
3795 | 431 // stream_skip(demuxer->stream, 2); /* coded frame size */ |
432 frame_size = stream_read_word(demuxer->stream); | |
433 printf("frame_size: %d\n", frame_size); | |
3777 | 434 stream_skip(demuxer->stream, 4); |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
435 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
436 if (version == 5) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
437 stream_skip(demuxer->stream, 6); |
3777 | 438 |
439 sh->samplerate = stream_read_word(demuxer->stream); | |
440 stream_skip(demuxer->stream, 4); | |
441 sh->channels = stream_read_word(demuxer->stream); | |
3877 | 442 printf("samplerate: %d, channels: %d\n", |
443 sh->samplerate, sh->channels); | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
444 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
445 if (version == 5) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
446 { |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
447 stream_skip(demuxer->stream, 4); |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
448 stream_read(demuxer->stream, buf, 4); |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
449 buf[4] = 0; |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
450 } |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
451 else |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
452 { |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
453 /* Desc #1 */ |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
454 skip_str(1, demuxer); |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
455 /* Desc #2 */ |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
456 get_str(1, demuxer, buf, sizeof(buf)); |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
457 } |
3777 | 458 |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
459 /* Emulate WAVEFORMATEX struct: */ |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
460 sh->wf = malloc(sizeof(WAVEFORMATEX)); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
461 memset(sh->wf, 0, sizeof(WAVEFORMATEX)); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
462 sh->wf->nChannels = sh->channels; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
463 sh->wf->wBitsPerSample = 16; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
464 sh->wf->nSamplesPerSec = sh->samplerate; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
465 sh->wf->nAvgBytesPerSec = bitrate; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
466 sh->wf->nBlockAlign = frame_size; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
467 sh->wf->cbSize = 0; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
468 |
3795 | 469 tmp = 1; /* supported audio codec */ |
470 switch (MKTAG(buf[0], buf[1], buf[2], buf[3])) | |
471 { | |
472 case MKTAG('d', 'n', 'e', 't'): | |
473 printf("Audio: DNET -> AC3\n"); | |
474 sh->format = 0x2000; | |
475 break; | |
476 case MKTAG('s', 'i', 'p', 'r'): | |
477 printf("Audio: SiproLab's ACELP.net\n"); | |
3788 | 478 sh->format = 0x130; |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
479 /* for buggy directshow loader */ |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
480 sh->wf = realloc(sh->wf, 18+4); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
481 sh->wf->wBitsPerSample = 0; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
482 sh->wf->nAvgBytesPerSec = 1055; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
483 sh->wf->nBlockAlign = 19; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
484 // sh->wf->nBlockAlign = frame_size / 288; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
485 sh->wf->cbSize = 4; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
486 buf[0] = 30; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
487 buf[1] = 1; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
488 buf[2] = 1; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
489 buf[3] = 0; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
490 memcpy((sh->wf+18), (char *)&buf[0], 4); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
491 // sh->wf[sizeof(WAVEFORMATEX)+1] = 30; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
492 // sh->wf[sizeof(WAVEFORMATEX)+2] = 1; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
493 // sh->wf[sizeof(WAVEFORMATEX)+3] = 1; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
494 // sh->wf[sizeof(WAVEFORMATEX)+4] = 0; |
3795 | 495 break; |
496 case MKTAG('c', 'o', 'o', 'k'): | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
497 printf("Audio: Real's GeneralCooker (?) (RealAudio G2?) (unsupported)\n"); |
3795 | 498 tmp = 0; |
499 break; | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
500 case MKTAG('a', 't', 'r', 'c'): |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
501 printf("Audio: ATRAC3 (RealAudio 8?) (unsupported)\n"); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
502 sh->format = 0x270; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
503 break; |
3795 | 504 default: |
505 printf("Audio: Unknown (%s)\n", buf); | |
506 tmp = 0; | |
507 sh->format = MKTAG(buf[0], buf[1], buf[2], buf[3]); | |
3777 | 508 } |
509 | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
510 sh->wf->wFormatTag = sh->format; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
511 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
512 print_wave_header(sh->wf); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
513 |
3795 | 514 if (tmp) |
3777 | 515 { |
3795 | 516 /* insert as stream */ |
517 demuxer->audio->sh = sh; | |
518 sh->ds = demuxer->audio; | |
519 demuxer->audio->id = stream_id; | |
3788 | 520 |
3795 | 521 if (priv->last_a_stream+1 < MAX_STREAMS) |
522 { | |
523 priv->a_streams[priv->last_a_stream] = stream_id; | |
524 priv->last_a_stream++; | |
525 } | |
3777 | 526 } |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
527 else |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
528 free(sh->wf); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
529 // break; |
3777 | 530 } |
531 else | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
532 // case MKTAG('V', 'I', 'D', 'O'): |
3777 | 533 { |
534 /* video header */ | |
535 sh_video_t *sh = new_sh_video(demuxer, stream_id); | |
536 | |
3795 | 537 tmp = stream_read_dword_le(demuxer->stream); |
538 printf("video: %.4s (%x)\n", (char *)&tmp, tmp); | |
539 if (tmp != MKTAG('V', 'I', 'D', 'O')) | |
3777 | 540 { |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
541 mp_msg(MSGT_DEMUX, MSGL_ERR, "Not audio/video stream or unsupported!\n"); |
3777 | 542 goto skip_this_chunk; |
543 } | |
544 | |
545 sh->format = stream_read_dword_le(demuxer->stream); /* fourcc */ | |
546 printf("video fourcc: %.4s (%x)\n", (char *)&sh->format, sh->format); | |
547 | |
3795 | 548 /* emulate BITMAPINFOHEADER */ |
3777 | 549 sh->bih = malloc(sizeof(BITMAPINFOHEADER)); |
550 memset(sh->bih, 0, sizeof(BITMAPINFOHEADER)); | |
551 sh->bih->biSize = 40; | |
552 sh->disp_w = sh->bih->biWidth = stream_read_word(demuxer->stream); | |
553 sh->disp_h = sh->bih->biHeight = stream_read_word(demuxer->stream); | |
554 sh->bih->biPlanes = 1; | |
555 sh->bih->biBitCount = 24; | |
556 sh->bih->biCompression = sh->format; | |
557 sh->bih->biSizeImage= sh->bih->biWidth*sh->bih->biHeight*3; | |
558 | |
559 sh->fps = stream_read_word(demuxer->stream); | |
560 sh->frametime = 1.0f/sh->fps; | |
561 | |
562 stream_skip(demuxer->stream, 4); | |
563 stream_skip(demuxer->stream, 2); | |
564 stream_skip(demuxer->stream, 4); | |
565 stream_skip(demuxer->stream, 2); | |
566 | |
567 /* h263 hack */ | |
3795 | 568 tmp = stream_read_dword(demuxer->stream); |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
569 printf("H.263 ID: %x\n", tmp); |
3795 | 570 switch (tmp) |
3777 | 571 { |
572 case 0x10000000: | |
573 /* sub id: 0 */ | |
574 /* codec id: rv10 */ | |
575 break; | |
576 case 0x10003000: | |
577 case 0x10003001: | |
578 /* sub id: 3 */ | |
579 /* codec id: rv10 */ | |
3877 | 580 sh->bih->biCompression = sh->format = mmioFOURCC('R', 'V', '1', '3'); |
3777 | 581 break; |
582 case 0x20001000: | |
3788 | 583 case 0x20100001: |
3777 | 584 /* codec id: rv20 */ |
585 break; | |
586 default: | |
587 /* codec id: none */ | |
3795 | 588 printf("unknown id: %x\n", tmp); |
3777 | 589 } |
590 | |
591 /* insert as stream */ | |
592 demuxer->video->sh = sh; | |
593 sh->ds = demuxer->video; | |
594 demuxer->video->id = stream_id; | |
595 if (priv->last_v_stream+1 < MAX_STREAMS) | |
596 { | |
597 priv->v_streams[priv->last_v_stream] = stream_id; | |
598 priv->last_v_stream++; | |
599 } | |
600 } | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
601 // break; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
602 // default: |
3777 | 603 skip_this_chunk: |
604 /* skip codec info */ | |
3795 | 605 tmp = stream_tell(demuxer->stream) - codec_pos; |
606 stream_skip(demuxer->stream, codec_data_size - tmp); | |
3777 | 607 break; |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
608 // } |
3777 | 609 } |
610 case MKTAG('D', 'A', 'T', 'A'): | |
611 goto header_end; | |
3795 | 612 case MKTAG('I', 'N', 'D', 'X'): |
3777 | 613 default: |
614 printf("Unknown chunk: %x\n", chunk); | |
615 stream_skip(demuxer->stream, chunk_size - 10); | |
616 break; | |
617 } | |
618 } | |
619 | |
620 header_end: | |
621 priv->num_of_packets = stream_read_dword(demuxer->stream); | |
622 // stream_skip(demuxer->stream, 4); /* number of packets */ | |
623 stream_skip(demuxer->stream, 4); /* next data header */ | |
624 | |
625 printf("Packets in file: %d\n", priv->num_of_packets); | |
626 | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
627 if (priv->num_of_packets == 0) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
628 priv->num_of_packets = -10; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
629 |
3777 | 630 /* disable seeking */ |
631 demuxer->seekable = 0; | |
632 | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
633 if (priv->index_chunk_offset && ((index_mode == 1) || (index_mode == 2))) |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
634 parse_index_chunk(demuxer); |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
635 |
3777 | 636 fail: |
637 return; | |
638 } | |
639 | |
640 void demux_close_real(demuxer_t *demuxer) | |
641 { | |
642 real_priv_t* priv = demuxer->priv; | |
643 | |
644 if (priv) | |
645 free(priv); | |
646 | |
647 return; | |
648 } | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
649 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
650 #if 0 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
651 /* will complete it later - please upload RV10 samples WITH INDEX CHUNK */ |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
652 int demux_seek_real(demuxer_t *demuxer, float rel_seek_secs, int flags) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
653 { |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
654 real_priv_t *priv = demuxer->priv; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
655 demux_stream_t *d_audio = demuxer->audio; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
656 demux_stream_t *d_video = demuxer->video; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
657 sh_audio_t *sh_audio = d_audio->sh; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
658 sh_video_t *sh_video = d_video->sh; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
659 int rel_seek_frames = sh->fps*rel_seek_secs; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
660 int video_chunk_pos = d_video->pos; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
661 int stream_id = 0; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
662 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
663 #if 0 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
664 if (flags & 1) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
665 /* seek absolute */ |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
666 video_chunk_pos = 0; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
667 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
668 if (flags & 2) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
669 { |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
670 int total = sh_video->video.dwLength; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
671 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
672 rel_seek_frames |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
673 } |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
674 #endif |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
675 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
676 if (rel_seek_frames > 0) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
677 { |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
678 /* seek forward */ |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
679 for (i = 0; i < index_table_size[stream_id]; i++) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
680 { |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
681 if (index_table[stream_id][i] |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
682 } |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
683 } |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
684 } |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
685 #endif |