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