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