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