Mercurial > mplayer.hg
annotate libmpdemux/demux_real.c @ 6069:8e88e92fe331
Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
author | albeu |
---|---|
date | Mon, 13 May 2002 13:15:40 +0000 |
parents | dca3016882cf |
children | 7f612cf06ba5 |
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. | |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
7 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
8 TODO: fix the whole syncing mechanism |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
9 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
10 $Log$ |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
11 Revision 1.11 2002/04/30 23:29:38 alex |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
12 completed real seeking - working very well with audio only files |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
13 |
5810 | 14 Revision 1.10 2002/04/24 15:36:06 albeu |
15 Added demuxer uninit | |
16 | |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
17 Revision 1.9 2002/03/15 15:51:37 alex |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
18 added PRE-ALPHA seeking ability and index table generator (like avi's one) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
19 |
4328
2936f5445e0c
fixed num_of_packets and current_packet handling, bug found by Mike Melanson
alex
parents:
4235
diff
changeset
|
20 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
|
21 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
|
22 |
4235 | 23 Revision 1.7 2002/01/18 11:02:52 alex |
24 fix dnet support | |
25 | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
26 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
|
27 updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes) |
3788 | 28 |
3795 | 29 |
30 Audio codecs: (supported by RealPlayer8 for Linux) | |
4235 | 31 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
|
32 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
|
33 needs fine-tuning too :) |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
34 ATRC - RealAudio 8 (ATRAC3) - www.minidisc.org/atrac3_article.pdf, |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
35 ACM decoder uploaded, needs some fine-tuning to work |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
36 -> RealAudio 8 |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
37 COOK/COKR - Real Cooker -> RealAudio G2 |
3795 | 38 |
39 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
|
40 RV10 - H.263 based, working with libavcodec's decoder |
3795 | 41 RV20 |
42 RV30 | |
3788 | 43 */ |
44 | |
3777 | 45 #include <stdio.h> |
46 #include <stdlib.h> | |
47 #include <unistd.h> | |
48 | |
49 #include "config.h" | |
50 #include "mp_msg.h" | |
51 #include "help_mp.h" | |
52 | |
53 #include "stream.h" | |
54 #include "demuxer.h" | |
55 #include "stheader.h" | |
56 #include "bswap.h" | |
57 | |
58 #define MKTAG(a, b, c, d) (a | (b << 8) | (c << 16) | (d << 24)) | |
59 | |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
60 #define MAX_STREAMS 32 |
3777 | 61 |
62 typedef struct { | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
63 int timestamp; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
64 int offset; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
65 int packetno; |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
66 int len; /* only filled by our index generator */ |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
67 int flags; /* only filled by our index generator */ |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
68 } real_index_table_t; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
69 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
70 typedef struct { |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
71 /* for seeking */ |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
72 int index_chunk_offset; |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
73 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
|
74 // int *index_table[MAX_STREAMS]; |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
75 int index_table_size[MAX_STREAMS]; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
76 int data_chunk_offset; |
3777 | 77 int num_of_packets; |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
78 int current_packet; |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
79 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
80 int current_aid; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
81 int current_vid; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
82 int current_apacket; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
83 int current_vpacket; |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
84 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
85 /* stream id table */ |
3777 | 86 int last_a_stream; |
87 int a_streams[MAX_STREAMS]; | |
88 int last_v_stream; | |
89 int v_streams[MAX_STREAMS]; | |
90 } real_priv_t; | |
91 | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
92 /* originally from FFmpeg */ |
3777 | 93 static void get_str(int isbyte, demuxer_t *demuxer, char *buf, int buf_size) |
94 { | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
95 int len; |
3777 | 96 |
97 if (isbyte) | |
98 len = stream_read_char(demuxer->stream); | |
99 else | |
100 len = stream_read_word(demuxer->stream); | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
101 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
102 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
|
103 if (len > buf_size) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
104 stream_skip(demuxer->stream, len-buf_size); |
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 printf("read_str: %d bytes read\n", len); |
3777 | 107 } |
108 | |
109 static void skip_str(int isbyte, demuxer_t *demuxer) | |
110 { | |
111 int len; | |
112 | |
113 if (isbyte) | |
114 len = stream_read_char(demuxer->stream); | |
115 else | |
116 len = stream_read_word(demuxer->stream); | |
117 | |
118 stream_skip(demuxer->stream, len); | |
119 | |
120 printf("skip_str: %d bytes skipped\n", len); | |
121 } | |
122 | |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
123 static void dump_index(demuxer_t *demuxer, int stream_id) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
124 { |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
125 real_priv_t *priv = demuxer->priv; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
126 real_index_table_t *index; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
127 int i, entries; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
128 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
129 if (!verbose) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
130 return; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
131 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
132 if (stream_id > MAX_STREAMS) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
133 return; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
134 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
135 index = priv->index_table[stream_id]; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
136 entries = priv->index_table_size[stream_id]; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
137 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
138 printf("Index table for stream %d\n", stream_id); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
139 for (i = 0; i < entries; i++) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
140 { |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
141 printf("packetno: %x pos: %x len: %x timestamp: %x flags: %x\n", |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
142 index[i].packetno, index[i].offset, index[i].len, index[i].timestamp, |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
143 index[i].flags); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
144 } |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
145 } |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
146 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
147 static int parse_index_chunk(demuxer_t *demuxer) |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
148 { |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
149 real_priv_t *priv = demuxer->priv; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
150 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
|
151 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
|
152 int i, entries, stream_id; |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
153 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
154 read_index: |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
155 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
|
156 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
157 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
|
158 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
|
159 { |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
160 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
|
161 next_header_pos); |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
162 goto end; |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
163 } |
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("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
|
166 next_header_pos); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
167 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
168 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
|
169 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
|
170 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
171 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
|
172 if (i != 0) |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
173 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
|
174 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
175 entries = stream_read_dword(demuxer->stream); |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
176 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
|
177 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
178 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
|
179 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
|
180 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
181 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
|
182 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
|
183 if (entries <= 0) |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
184 { |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
185 if (next_header_pos) |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
186 goto read_index; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
187 i = entries; |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
188 goto end; |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
189 } |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
190 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
191 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
|
192 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
|
193 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
194 for (i = 0; i < entries; i++) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
195 { |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
196 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
|
197 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
|
198 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
|
199 priv->index_table[stream_id][i].packetno = stream_read_dword(demuxer->stream); |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
200 // printf("Index table: Stream#%d: entry: %d: pos: %d\n", |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
201 // 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
|
202 } |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
203 |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
204 dump_index(demuxer, stream_id); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
205 |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
206 if (next_header_pos > 0) |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
207 goto read_index; |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
208 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
209 end: |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
210 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
|
211 if (i == -256) |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
212 stream_reset(demuxer->stream); |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
213 stream_seek(demuxer->stream, origpos); |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
214 if (i == -256) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
215 return 0; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
216 else |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
217 return 1; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
218 } |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
219 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
220 static int generate_index(demuxer_t *demuxer) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
221 { |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
222 real_priv_t *priv = demuxer->priv; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
223 int origpos = stream_tell(demuxer->stream); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
224 int data_pos = priv->data_chunk_offset-10; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
225 int num_of_packets = 0; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
226 int i, entries = 0; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
227 int len, stream_id = 0, timestamp, flags; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
228 int tab_pos = 0; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
229 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
230 read_index: |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
231 stream_seek(demuxer->stream, data_pos); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
232 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
233 i = stream_read_dword_le(demuxer->stream); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
234 if ((i == -256) || (i != MKTAG('D', 'A', 'T', 'A'))) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
235 { |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
236 printf("Something went wrong, no data chunk found on given address (%d)\n", |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
237 data_pos); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
238 goto end; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
239 } |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
240 stream_skip(demuxer->stream, 4); /* chunk size */ |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
241 stream_skip(demuxer->stream, 2); /* version */ |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
242 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
243 num_of_packets = stream_read_dword(demuxer->stream); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
244 printf("Generating index table from raw data (pos: 0x%x) for %d packets\n", |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
245 data_pos, num_of_packets); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
246 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
247 data_pos = stream_read_dword_le(demuxer->stream)-10; /* next data chunk */ |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
248 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
249 for (i = 0; i < MAX_STREAMS; i++) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
250 { |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
251 priv->index_table_size[i] = num_of_packets; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
252 priv->index_table[i] = malloc(priv->index_table_size[i] * sizeof(real_index_table_t)); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
253 // priv->index_table[stream_id] = realloc(priv->index_table[stream_id], |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
254 // priv->index_table_size[stream_id] * sizeof(real_index_table_t)); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
255 } |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
256 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
257 tab_pos = 0; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
258 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
259 // memset(priv->index_table_size, 0, sizeof(int)*MAX_STREAMS); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
260 // memset(priv->index_table, 0, sizeof(real_index_table_t)*MAX_STREAMS); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
261 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
262 while (tab_pos < num_of_packets) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
263 { |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
264 i = stream_read_char(demuxer->stream); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
265 if (i == -256) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
266 goto end; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
267 stream_skip(demuxer->stream, 1); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
268 // stream_skip(demuxer->stream, 2); /* version */ |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
269 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
270 len = stream_read_word(demuxer->stream); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
271 stream_id = stream_read_word(demuxer->stream); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
272 timestamp = stream_read_dword(demuxer->stream); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
273 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
274 stream_skip(demuxer->stream, 1); /* reserved */ |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
275 flags = stream_read_char(demuxer->stream); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
276 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
277 i = tab_pos; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
278 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
279 // priv->index_table_size[stream_id] = i; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
280 // if (priv->index_table[stream_id] == NULL) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
281 // priv->index_table[stream_id] = malloc(priv->index_table_size[stream_id] * sizeof(real_index_table_t)); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
282 // else |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
283 // priv->index_table[stream_id] = realloc(priv->index_table[stream_id], |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
284 // priv->index_table_size[stream_id] * sizeof(real_index_table_t)); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
285 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
286 priv->index_table[stream_id][i].timestamp = timestamp; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
287 priv->index_table[stream_id][i].offset = stream_tell(demuxer->stream)-12; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
288 priv->index_table[stream_id][i].len = len; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
289 priv->index_table[stream_id][i].packetno = entries; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
290 priv->index_table[stream_id][i].flags = flags; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
291 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
292 tab_pos++; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
293 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
294 /* skip data */ |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
295 stream_skip(demuxer->stream, len-12); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
296 } |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
297 dump_index(demuxer, stream_id); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
298 if (data_pos) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
299 goto read_index; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
300 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
301 end: |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
302 demuxer->seekable = 1; /* got index, we're able to seek */ |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
303 if (i == -256) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
304 stream_reset(demuxer->stream); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
305 stream_seek(demuxer->stream, origpos); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
306 if (i == -256) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
307 return 0; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
308 else |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
309 return 1; |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
310 } |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
311 |
3795 | 312 int real_check_file(demuxer_t* demuxer) |
313 { | |
3777 | 314 real_priv_t *priv; |
315 int c; | |
316 | |
317 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for REAL\n"); | |
318 | |
319 c = stream_read_dword_le(demuxer->stream); | |
320 if (c == -256) | |
321 return 0; /* EOF */ | |
322 if (c != MKTAG('.', 'R', 'M', 'F')) | |
323 return 0; /* bad magic */ | |
324 | |
325 priv = malloc(sizeof(real_priv_t)); | |
326 memset(priv, 0, sizeof(real_priv_t)); | |
327 demuxer->priv = priv; | |
328 | |
329 return 1; | |
330 } | |
331 | |
332 // return value: | |
333 // 0 = EOF or no stream found | |
334 // 1 = successfully read a packet | |
335 int demux_real_fill_buffer(demuxer_t *demuxer) | |
336 { | |
337 real_priv_t *priv = demuxer->priv; | |
338 demux_stream_t *ds = NULL; | |
4235 | 339 sh_audio_t *sh_audio = NULL; |
3777 | 340 int len; |
341 int timestamp; | |
342 int stream_id; | |
343 int i; | |
3795 | 344 int flags; |
3777 | 345 |
346 loop: | |
4328
2936f5445e0c
fixed num_of_packets and current_packet handling, bug found by Mike Melanson
alex
parents:
4235
diff
changeset
|
347 /* 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
|
348 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
|
349 (priv->num_of_packets != -10)) |
3777 | 350 return 0; /* EOF */ |
3795 | 351 stream_skip(demuxer->stream, 2); /* version */ |
3777 | 352 len = stream_read_word(demuxer->stream); |
353 if (len == -256) /* EOF */ | |
354 return 0; | |
355 if (len < 12) | |
356 { | |
357 printf("bad packet len (%d)\n", len); | |
358 stream_skip(demuxer->stream, len); | |
359 goto loop; | |
360 } | |
361 stream_id = stream_read_word(demuxer->stream); | |
362 timestamp = stream_read_dword(demuxer->stream); | |
363 | |
364 stream_skip(demuxer->stream, 1); /* reserved */ | |
3795 | 365 flags = stream_read_char(demuxer->stream); |
366 /* flags: */ | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
367 /* 0x1 - reliable */ |
3795 | 368 /* 0x2 - keyframe */ |
369 | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
370 // 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
|
371 // priv->current_packet, stream_tell(demuxer->stream)-12, len, stream_id, timestamp, flags); |
3777 | 372 |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
373 priv->current_packet++; |
3777 | 374 len -= 12; |
375 | |
376 /* check if stream_id is audio stream */ | |
377 for (i = 0; i < priv->last_a_stream; i++) | |
378 { | |
379 if (priv->a_streams[i] == stream_id) | |
380 { | |
381 // printf("packet is audio (id: %d)\n", stream_id); | |
382 ds = demuxer->audio; /* FIXME */ | |
4235 | 383 sh_audio = ds->sh; |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
384 priv->current_apacket++; |
3777 | 385 break; |
386 } | |
387 } | |
388 /* check if stream_id is video stream */ | |
389 for (i = 0; i < priv->last_v_stream; i++) | |
390 { | |
391 if (priv->v_streams[i] == stream_id) | |
392 { | |
393 // printf("packet is video (id: %d)\n", stream_id); | |
394 ds = demuxer->video; /* FIXME */ | |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
395 priv->current_vpacket++; |
3777 | 396 break; |
397 } | |
398 } | |
399 | |
400 /* id not found */ | |
401 if (ds == NULL) | |
402 { | |
403 printf("unknown stream id (%d)\n", stream_id); | |
404 stream_skip(demuxer->stream, len); | |
405 goto loop; | |
406 } | |
407 | |
408 demuxer->filepos = stream_tell(demuxer->stream); | |
4235 | 409 #if 0 |
3795 | 410 ds_read_packet(ds, demuxer->stream, len, timestamp/90000.0f, |
411 demuxer->filepos, (flags & 0x2) ? 0x10 : 0); | |
4235 | 412 #else |
413 { | |
414 demux_packet_t *dp = new_demux_packet(len); | |
415 | |
416 stream_read(demuxer->stream, dp->buffer, len); | |
417 /* if DNET, swap bytes! */ | |
418 if (sh_audio != NULL) | |
419 if (sh_audio->format == 0x2000) | |
420 { | |
421 char *ptr = dp->buffer; | |
422 | |
423 for (i = 0; i < len; i += 2) | |
424 { | |
425 const char tmp = ptr[0]; | |
426 ptr[0] = ptr[1]; | |
427 ptr[1] = tmp; | |
428 ptr += 2; | |
429 } | |
430 } | |
431 dp->pts = timestamp/90000.0f; | |
432 dp->pos = demuxer->filepos; | |
433 dp->flags = (flags & 0x2) ? 0x10 : 0; | |
434 ds_add_packet(ds, dp); | |
435 } | |
436 #endif | |
3777 | 437 |
438 return 1; | |
439 } | |
440 | |
441 void demux_open_real(demuxer_t* demuxer) | |
442 { | |
443 real_priv_t* priv = demuxer->priv; | |
444 int num_of_headers; | |
445 int i; | |
446 | |
447 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
|
448 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
|
449 // stream_skip(demuxer->stream, 4); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
450 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
|
451 printf("File version: %d\n", i); |
3777 | 452 num_of_headers = stream_read_dword(demuxer->stream); |
453 // stream_skip(demuxer->stream, 4); /* number of headers */ | |
454 | |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
455 priv->current_vid = priv->current_aid = -1; |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
456 |
3777 | 457 /* parse chunks */ |
458 for (i = 1; i < num_of_headers; i++) | |
459 { | |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
460 int chunk_id, chunk_pos, chunk_size; |
3777 | 461 |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
462 chunk_pos = stream_tell(demuxer->stream); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
463 chunk_id = stream_read_dword_le(demuxer->stream); |
3777 | 464 chunk_size = stream_read_dword(demuxer->stream); |
465 | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
466 stream_skip(demuxer->stream, 2); /* version */ |
3777 | 467 |
468 if (chunk_size < 10) | |
469 goto fail; | |
470 | |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
471 printf("Chunk: %.4s (%x) (size: 0x%x, offset: 0x%x)\n", |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
472 (char *)&chunk_id, chunk_id, chunk_size, chunk_pos); |
3777 | 473 |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
474 switch(chunk_id) |
3777 | 475 { |
476 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
|
477 /* Properties header */ |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
478 |
3777 | 479 stream_skip(demuxer->stream, 4); /* max bitrate */ |
480 stream_skip(demuxer->stream, 4); /* avg bitrate */ | |
481 stream_skip(demuxer->stream, 4); /* max packet size */ | |
482 stream_skip(demuxer->stream, 4); /* avg packet size */ | |
483 stream_skip(demuxer->stream, 4); /* nb packets */ | |
484 stream_skip(demuxer->stream, 4); /* duration */ | |
485 stream_skip(demuxer->stream, 4); /* preroll */ | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
486 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
|
487 printf("First index chunk offset: 0x%x\n", priv->index_chunk_offset); |
3795 | 488 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
|
489 printf("First data chunk offset: 0x%x\n", priv->data_chunk_offset); |
3777 | 490 stream_skip(demuxer->stream, 2); /* nb streams */ |
3795 | 491 #if 0 |
3777 | 492 stream_skip(demuxer->stream, 2); /* flags */ |
3795 | 493 #else |
494 { | |
495 int flags = stream_read_word(demuxer->stream); | |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
496 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
497 if (flags) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
498 { |
3795 | 499 printf("Flags (%x): ", flags); |
500 if (flags & 0x1) | |
501 printf("[save allowed] "); | |
502 if (flags & 0x2) | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
503 printf("[perfect play (more buffers)] "); |
3795 | 504 if (flags & 0x4) |
505 printf("[live broadcast] "); | |
506 printf("\n"); | |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
507 } |
3795 | 508 } |
509 #endif | |
3777 | 510 break; |
511 case MKTAG('C', 'O', 'N', 'T'): | |
3788 | 512 { |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
513 /* Content description header */ |
3788 | 514 char *buf; |
515 int len; | |
516 | |
517 len = stream_read_word(demuxer->stream); | |
518 if (len > 0) | |
519 { | |
520 buf = malloc(len+1); | |
521 stream_read(demuxer->stream, buf, len); | |
5810 | 522 buf[len] = 0; |
3788 | 523 demux_info_add(demuxer, "name", buf); |
524 free(buf); | |
525 } | |
526 | |
527 len = stream_read_word(demuxer->stream); | |
528 if (len > 0) | |
529 { | |
530 buf = malloc(len+1); | |
531 stream_read(demuxer->stream, buf, len); | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
532 buf[len] = 0; |
3788 | 533 demux_info_add(demuxer, "author", buf); |
534 free(buf); | |
535 } | |
536 | |
537 len = stream_read_word(demuxer->stream); | |
538 if (len > 0) | |
539 { | |
540 buf = malloc(len+1); | |
541 stream_read(demuxer->stream, buf, len); | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
542 buf[len] = 0; |
3788 | 543 demux_info_add(demuxer, "copyright", buf); |
544 free(buf); | |
545 } | |
546 | |
547 len = stream_read_word(demuxer->stream); | |
548 if (len > 0) | |
549 { | |
550 buf = malloc(len+1); | |
551 stream_read(demuxer->stream, buf, len); | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
552 buf[len] = 0; |
3788 | 553 demux_info_add(demuxer, "comment", buf); |
554 free(buf); | |
555 } | |
3777 | 556 break; |
3788 | 557 } |
3777 | 558 case MKTAG('M', 'D', 'P', 'R'): |
559 { | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
560 /* Media properties header */ |
3777 | 561 int stream_id; |
562 int bitrate; | |
563 int codec_data_size; | |
564 int codec_pos; | |
3795 | 565 int tmp; |
3777 | 566 |
567 stream_id = stream_read_word(demuxer->stream); | |
568 printf("Found new stream (id: %d)\n", stream_id); | |
569 | |
570 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
|
571 bitrate = stream_read_dword(demuxer->stream); /* avg bitrate */ |
3777 | 572 stream_skip(demuxer->stream, 4); /* max packet size */ |
573 stream_skip(demuxer->stream, 4); /* avg packet size */ | |
574 stream_skip(demuxer->stream, 4); /* start time */ | |
575 stream_skip(demuxer->stream, 4); /* preroll */ | |
576 stream_skip(demuxer->stream, 4); /* duration */ | |
577 | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
578 skip_str(1, demuxer); /* stream description (name) */ |
3777 | 579 skip_str(1, demuxer); /* mimetype */ |
580 | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
581 /* Type specific header */ |
3777 | 582 codec_data_size = stream_read_dword(demuxer->stream); |
583 codec_pos = stream_tell(demuxer->stream); | |
584 | |
3795 | 585 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
|
586 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
587 if (tmp == MKTAG(0xfd, 'a', 'r', '.')) |
3777 | 588 { |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
589 /* audio header */ |
3777 | 590 sh_audio_t *sh = new_sh_audio(demuxer, stream_id); |
3795 | 591 char buf[128]; /* for codec name */ |
592 int frame_size; | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
593 int version; |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
594 |
3777 | 595 printf("Found audio stream!\n"); |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
596 version = stream_read_word(demuxer->stream); |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
597 printf("version: %d\n", version); |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
598 // stream_skip(demuxer->stream, 2); /* version (4 or 5) */ |
3788 | 599 stream_skip(demuxer->stream, 2); |
600 stream_skip(demuxer->stream, 4); /* .ra4 or .ra5 */ | |
3777 | 601 stream_skip(demuxer->stream, 4); |
3788 | 602 stream_skip(demuxer->stream, 2); /* version (4 or 5) */ |
3777 | 603 stream_skip(demuxer->stream, 4); /* header size */ |
604 stream_skip(demuxer->stream, 2); /* add codec info */ | |
605 stream_skip(demuxer->stream, 4); /* coded frame size */ | |
606 stream_skip(demuxer->stream, 4); | |
607 stream_skip(demuxer->stream, 4); | |
608 stream_skip(demuxer->stream, 4); | |
609 stream_skip(demuxer->stream, 2); /* 1 */ | |
3795 | 610 // stream_skip(demuxer->stream, 2); /* coded frame size */ |
611 frame_size = stream_read_word(demuxer->stream); | |
612 printf("frame_size: %d\n", frame_size); | |
3777 | 613 stream_skip(demuxer->stream, 4); |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
614 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
615 if (version == 5) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
616 stream_skip(demuxer->stream, 6); |
3777 | 617 |
618 sh->samplerate = stream_read_word(demuxer->stream); | |
619 stream_skip(demuxer->stream, 4); | |
620 sh->channels = stream_read_word(demuxer->stream); | |
3877 | 621 printf("samplerate: %d, channels: %d\n", |
622 sh->samplerate, sh->channels); | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
623 |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
624 if (version == 5) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
625 { |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
626 stream_skip(demuxer->stream, 4); |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
627 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
|
628 buf[4] = 0; |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
629 } |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
630 else |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
631 { |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
632 /* Desc #1 */ |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
633 skip_str(1, demuxer); |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
634 /* Desc #2 */ |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
635 get_str(1, demuxer, buf, sizeof(buf)); |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
636 } |
3777 | 637 |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
638 /* Emulate WAVEFORMATEX struct: */ |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
639 sh->wf = malloc(sizeof(WAVEFORMATEX)); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
640 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
|
641 sh->wf->nChannels = sh->channels; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
642 sh->wf->wBitsPerSample = 16; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
643 sh->wf->nSamplesPerSec = sh->samplerate; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
644 sh->wf->nAvgBytesPerSec = bitrate; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
645 sh->wf->nBlockAlign = frame_size; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
646 sh->wf->cbSize = 0; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
647 |
3795 | 648 tmp = 1; /* supported audio codec */ |
649 switch (MKTAG(buf[0], buf[1], buf[2], buf[3])) | |
650 { | |
651 case MKTAG('d', 'n', 'e', 't'): | |
652 printf("Audio: DNET -> AC3\n"); | |
653 sh->format = 0x2000; | |
654 break; | |
655 case MKTAG('s', 'i', 'p', 'r'): | |
656 printf("Audio: SiproLab's ACELP.net\n"); | |
3788 | 657 sh->format = 0x130; |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
658 /* for buggy directshow loader */ |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
659 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
|
660 sh->wf->wBitsPerSample = 0; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
661 sh->wf->nAvgBytesPerSec = 1055; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
662 sh->wf->nBlockAlign = 19; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
663 // 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
|
664 sh->wf->cbSize = 4; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
665 buf[0] = 30; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
666 buf[1] = 1; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
667 buf[2] = 1; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
668 buf[3] = 0; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
669 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
|
670 // 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
|
671 // 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
|
672 // 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
|
673 // sh->wf[sizeof(WAVEFORMATEX)+4] = 0; |
3795 | 674 break; |
675 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
|
676 printf("Audio: Real's GeneralCooker (?) (RealAudio G2?) (unsupported)\n"); |
3795 | 677 tmp = 0; |
678 break; | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
679 case MKTAG('a', 't', 'r', 'c'): |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
680 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
|
681 sh->format = 0x270; |
4235 | 682 |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
683 sh->wf->nAvgBytesPerSec = 16537; // 8268 |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
684 sh->wf->nBlockAlign = 384; // 192 |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
685 sh->wf->wBitsPerSample = 0; /* from AVI created by VirtualDub */ |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
686 /* 14 bytes extra header needed ! */ |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
687 sh->wf->cbSize = 14; |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
688 sh->wf = realloc(sh->wf, 18+sh->wf->cbSize); |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
689 break; |
3795 | 690 default: |
691 printf("Audio: Unknown (%s)\n", buf); | |
692 tmp = 0; | |
693 sh->format = MKTAG(buf[0], buf[1], buf[2], buf[3]); | |
3777 | 694 } |
695 | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
696 sh->wf->wFormatTag = sh->format; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
697 |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
698 print_wave_header(sh->wf); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
699 |
3795 | 700 if (tmp) |
3777 | 701 { |
3795 | 702 /* insert as stream */ |
703 demuxer->audio->sh = sh; | |
704 sh->ds = demuxer->audio; | |
705 demuxer->audio->id = stream_id; | |
3788 | 706 |
3795 | 707 if (priv->last_a_stream+1 < MAX_STREAMS) |
708 { | |
709 priv->a_streams[priv->last_a_stream] = stream_id; | |
710 priv->last_a_stream++; | |
711 } | |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
712 priv->current_aid = stream_id; |
3777 | 713 } |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
714 else |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
715 free(sh->wf); |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
716 // break; |
3777 | 717 } |
718 else | |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
719 // case MKTAG('V', 'I', 'D', 'O'): |
3777 | 720 { |
721 /* video header */ | |
722 sh_video_t *sh = new_sh_video(demuxer, stream_id); | |
723 | |
3795 | 724 tmp = stream_read_dword_le(demuxer->stream); |
725 printf("video: %.4s (%x)\n", (char *)&tmp, tmp); | |
726 if (tmp != MKTAG('V', 'I', 'D', 'O')) | |
3777 | 727 { |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
728 mp_msg(MSGT_DEMUX, MSGL_ERR, "Not audio/video stream or unsupported!\n"); |
3777 | 729 goto skip_this_chunk; |
730 } | |
731 | |
732 sh->format = stream_read_dword_le(demuxer->stream); /* fourcc */ | |
733 printf("video fourcc: %.4s (%x)\n", (char *)&sh->format, sh->format); | |
734 | |
3795 | 735 /* emulate BITMAPINFOHEADER */ |
3777 | 736 sh->bih = malloc(sizeof(BITMAPINFOHEADER)); |
737 memset(sh->bih, 0, sizeof(BITMAPINFOHEADER)); | |
738 sh->bih->biSize = 40; | |
739 sh->disp_w = sh->bih->biWidth = stream_read_word(demuxer->stream); | |
740 sh->disp_h = sh->bih->biHeight = stream_read_word(demuxer->stream); | |
741 sh->bih->biPlanes = 1; | |
742 sh->bih->biBitCount = 24; | |
743 sh->bih->biCompression = sh->format; | |
744 sh->bih->biSizeImage= sh->bih->biWidth*sh->bih->biHeight*3; | |
745 | |
746 sh->fps = stream_read_word(demuxer->stream); | |
747 sh->frametime = 1.0f/sh->fps; | |
748 | |
749 stream_skip(demuxer->stream, 4); | |
750 stream_skip(demuxer->stream, 2); | |
751 stream_skip(demuxer->stream, 4); | |
752 stream_skip(demuxer->stream, 2); | |
753 | |
754 /* h263 hack */ | |
3795 | 755 tmp = stream_read_dword(demuxer->stream); |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
756 printf("H.263 ID: %x\n", tmp); |
3795 | 757 switch (tmp) |
3777 | 758 { |
759 case 0x10000000: | |
760 /* sub id: 0 */ | |
761 /* codec id: rv10 */ | |
762 break; | |
763 case 0x10003000: | |
764 case 0x10003001: | |
765 /* sub id: 3 */ | |
766 /* codec id: rv10 */ | |
3877 | 767 sh->bih->biCompression = sh->format = mmioFOURCC('R', 'V', '1', '3'); |
3777 | 768 break; |
769 case 0x20001000: | |
3788 | 770 case 0x20100001: |
3777 | 771 /* codec id: rv20 */ |
772 break; | |
773 default: | |
774 /* codec id: none */ | |
3795 | 775 printf("unknown id: %x\n", tmp); |
3777 | 776 } |
777 | |
778 /* insert as stream */ | |
779 demuxer->video->sh = sh; | |
780 sh->ds = demuxer->video; | |
781 demuxer->video->id = stream_id; | |
782 if (priv->last_v_stream+1 < MAX_STREAMS) | |
783 { | |
784 priv->v_streams[priv->last_v_stream] = stream_id; | |
785 priv->last_v_stream++; | |
786 } | |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
787 priv->current_vid = stream_id; |
3777 | 788 } |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
789 // break; |
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
790 // default: |
3777 | 791 skip_this_chunk: |
792 /* skip codec info */ | |
3795 | 793 tmp = stream_tell(demuxer->stream) - codec_pos; |
794 stream_skip(demuxer->stream, codec_data_size - tmp); | |
3777 | 795 break; |
3985
701d18898835
updated/extended some parts, based on RMFF (also initial ATRAC3 hackings and notes)
alex
parents:
3882
diff
changeset
|
796 // } |
3777 | 797 } |
798 case MKTAG('D', 'A', 'T', 'A'): | |
799 goto header_end; | |
3795 | 800 case MKTAG('I', 'N', 'D', 'X'): |
3777 | 801 default: |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
802 printf("Unknown chunk: %x\n", chunk_id); |
3777 | 803 stream_skip(demuxer->stream, chunk_size - 10); |
804 break; | |
805 } | |
806 } | |
807 | |
808 header_end: | |
809 priv->num_of_packets = stream_read_dword(demuxer->stream); | |
810 // stream_skip(demuxer->stream, 4); /* number of packets */ | |
811 stream_skip(demuxer->stream, 4); /* next data header */ | |
812 | |
813 printf("Packets in file: %d\n", priv->num_of_packets); | |
814 | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
815 if (priv->num_of_packets == 0) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
816 priv->num_of_packets = -10; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
817 |
3777 | 818 /* disable seeking */ |
819 demuxer->seekable = 0; | |
820 | |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
821 if (index_mode == 2) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
822 generate_index(demuxer); |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
823 else 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
|
824 parse_index_chunk(demuxer); |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
825 |
3777 | 826 fail: |
827 return; | |
828 } | |
829 | |
830 void demux_close_real(demuxer_t *demuxer) | |
831 { | |
832 real_priv_t* priv = demuxer->priv; | |
833 | |
834 if (priv) | |
835 free(priv); | |
836 | |
837 return; | |
838 } | |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
839 |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
840 /* please upload RV10 samples WITH INDEX CHUNK */ |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
841 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
|
842 { |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
843 real_priv_t *priv = demuxer->priv; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
844 demux_stream_t *d_audio = demuxer->audio; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
845 demux_stream_t *d_video = demuxer->video; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
846 sh_audio_t *sh_audio = d_audio->sh; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
847 sh_video_t *sh_video = d_video->sh; |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
848 int video_chunk_pos = d_video->pos; |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
849 int vid = priv->current_vid, aid = priv->current_aid; |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
850 int next_offset; |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
851 int rel_seek_frames = 0; |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
852 int streams = 0; |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
853 |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
854 if ((index_mode != 1) && (index_mode != 2)) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
855 return 0; |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
856 |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
857 if (sh_video) |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
858 streams |= 1; |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
859 if (sh_audio) |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
860 streams |= 2; |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
861 |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
862 // printf("streams: %d\n", streams); |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
863 |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
864 if (!streams) |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
865 return 0; |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
866 |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
867 if (flags & 1) |
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
868 /* seek absolute */ |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
869 priv->current_apacket = priv->current_vpacket = 0; |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
870 |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
871 /* flags & 2 ? */ |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
872 if (streams & 1) |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
873 rel_seek_frames = (int)(sh_video->fps*rel_seek_secs); |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
874 else if (streams & 2) |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
875 rel_seek_frames = (int)(rel_seek_secs); |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
876 |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
877 // printf("rel_seek_frames: %d\n", rel_seek_frames); |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
878 |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
879 if (streams & 2) |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
880 priv->current_apacket += rel_seek_frames; |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
881 if (streams & 1) |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
882 priv->current_vpacket += rel_seek_frames; |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
883 |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
884 if ( |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
885 ((streams & 2) && (priv->current_apacket > priv->index_table_size[aid])) || |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
886 ((streams & 1) && (priv->current_vpacket > priv->index_table_size[vid])) ) |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
887 return 0; |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
888 |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
889 /* both video and audio stream */ |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
890 if (streams == 3) |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
891 { |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
892 // if (priv->current_apacket > priv->current_vpacket) |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
893 // { |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
894 /* search keyframe */ |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
895 while (!(priv->index_table[vid][priv->current_vpacket].flags & 0x2)) |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
896 priv->current_vpacket++; |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
897 next_offset = priv->index_table[vid][priv->current_vpacket].offset; |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
898 // } |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
899 // else |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
900 // { |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
901 // next_offset = priv->index_table[aid][priv->current_apacket].offset; |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
902 // } |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
903 } |
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
904 else |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
905 { |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
906 if (streams & 1) |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
907 { |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
908 /* search keyframe */ |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
909 while (!(priv->index_table[vid][priv->current_vpacket].flags & 0x2)) |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
910 priv->current_vpacket++; |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
911 next_offset = priv->index_table[vid][priv->current_vpacket].offset; |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
912 } |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
913 else if (streams & 2) |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
914 { |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
915 next_offset = priv->index_table[aid][priv->current_apacket].offset; |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
916 } |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
917 } |
5083
ce6952225939
added PRE-ALPHA seeking ability and index table generator (like avi's one)
alex
parents:
4328
diff
changeset
|
918 |
5918
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
919 // printf("seek: pos: %d, current packets: a: %d, v: %d\n", |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
920 // next_offset, priv->current_apacket, priv->current_vpacket); |
dca3016882cf
completed real seeking - working very well with audio only files
alex
parents:
5810
diff
changeset
|
921 stream_seek(demuxer->stream, next_offset); |
3882
c5cefeb78c40
added read_index_chunk, fixed audio_header parser for version5
alex
parents:
3877
diff
changeset
|
922 } |