annotate asf.c @ 360:81e90b91f457 libavformat

no limits!, warning is enough
author michael
date Sat, 07 Feb 2004 00:03:11 +0000
parents 46029c682234
children 845f9de2c883
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * ASF compatible encoder and decoder.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2000, 2001 Fabrice Bellard.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
19 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 #include "avi.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 #include "mpegaudio.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22
348
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
23 #undef NDEBUG
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
24 #include <assert.h>
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
25
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 #define PACKET_SIZE 3200
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 #define PACKET_HEADER_SIZE 12
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 #define FRAME_HEADER_SIZE 17
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 typedef struct {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 int num;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 int seq;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 /* use for reading */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 AVPacket pkt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 int frag_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 int timestamp;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
37 int64_t duration;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 int ds_span; /* descrambling */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 int ds_packet_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 int ds_chunk_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 int ds_data_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 int ds_silence_data;
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
44
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
45 int packet_pos;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 } ASFStream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 typedef struct {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
50 uint32_t v1;
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
51 uint16_t v2;
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
52 uint16_t v3;
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
53 uint8_t v4[8];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 } GUID;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55
188
6c9d6422a2f6 update duration and start_time - add av_new_stream() usage
bellard
parents: 136
diff changeset
56 typedef struct {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 GUID guid; // generated by client computer
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 uint64_t file_size; // in bytes
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 // invalid if broadcasting
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 uint64_t create_time; // time of creation, in 100-nanosecond units since 1.1.1601
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 // invalid if broadcasting
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 uint64_t packets_count; // how many packets are there in the file
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 // invalid if broadcasting
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 uint64_t play_time; // play time, in 100-nanosecond units
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 // invalid if broadcasting
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 uint64_t send_time; // time to send file, in 100-nanosecond units
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 // invalid if broadcasting (could be ignored)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 uint32_t preroll; // timestamp of the first packet, in milliseconds
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 // if nonzero - substract from time
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 uint32_t ignore; // preroll is 64bit - but let's just ignore it
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 uint32_t flags; // 0x01 - broadcast
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 // 0x02 - seekable
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 // rest is reserved should be 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 uint32_t min_pktsize; // size of a data packet
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 // invalid if broadcasting
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 uint32_t max_pktsize; // shall be the same as for min_pktsize
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 // invalid if broadcasting
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 uint32_t max_bitrate; // bandwith of stream in bps
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 // should be the sum of bitrates of the
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 // individual media streams
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 } ASFMainHeader;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 typedef struct {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 int seqno;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 int packet_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 int is_streamed;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 int asfid2avid[128]; /* conversion table from asf ID 2 AVStream ID */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 ASFStream streams[128]; /* it's max number and it's not that big */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 /* non streamed additonnal info */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
91 int64_t nb_packets;
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
92 int64_t duration; /* in 100ns units */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 /* packet filling */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 int packet_size_left;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 int packet_timestamp_start;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 int packet_timestamp_end;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 int packet_nb_frames;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
98 uint8_t packet_buf[PACKET_SIZE];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 ByteIOContext pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 /* only for reading */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 uint64_t data_offset; /* begining of the first data packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 ASFMainHeader hdr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 int packet_flags;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 int packet_property;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 int packet_timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 int packet_segsizetype;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 int packet_segments;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 int packet_seq;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 int packet_replic_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 int packet_key_frame;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 int packet_padsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 int packet_frag_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 int packet_frag_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 int packet_frag_timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 int packet_multi_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 int packet_obj_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 int packet_time_delta;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 int packet_time_start;
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
121 int packet_pos;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 int stream_index;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 ASFStream* asf_st; /* currently decoded stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 } ASFContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 static const GUID asf_header = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 0x75B22630, 0x668E, 0x11CF, { 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 static const GUID file_header = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 0x8CABDCA1, 0xA947, 0x11CF, { 0x8E, 0xE4, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 static const GUID stream_header = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 0xB7DC0791, 0xA9B7, 0x11CF, { 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 static const GUID audio_stream = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 0xF8699E40, 0x5B4D, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 static const GUID audio_conceal_none = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 // 0x49f1a440, 0x4ece, 0x11d0, { 0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 // New value lifted from avifile
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 0x20fb5700, 0x5b55, 0x11cf, { 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 static const GUID video_stream = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150 0xBC19EFC0, 0x5B4D, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 static const GUID video_conceal_none = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 0x20FB5700, 0x5B55, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 static const GUID comment_header = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 0x75b22633, 0x668e, 0x11cf, { 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 static const GUID codec_comment_header = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 0x86D15240, 0x311D, 0x11D0, { 0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 static const GUID codec_comment1_header = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166 0x86d15241, 0x311d, 0x11d0, { 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 static const GUID data_header = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 0x75b22636, 0x668e, 0x11cf, { 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 static const GUID index_guid = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 0x33000890, 0xe5b1, 0x11cf, { 0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 static const GUID head1_guid = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 0x5fbf03b5, 0xa92e, 0x11cf, { 0x8e, 0xe3, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181 static const GUID head2_guid = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 0xabd3d211, 0xa9ba, 0x11cf, { 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184
341
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
185 static const GUID extended_content_header = {
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
186 0xD2D0A440, 0xE307, 0x11D2, { 0x97, 0xF0, 0x00, 0xA0, 0xC9, 0x5E, 0xA8, 0x50 },
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
187 };
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
188
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 /* I am not a number !!! This GUID is the one found on the PC used to
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 generate the stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 static const GUID my_guid = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
195 #ifdef CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 static void put_guid(ByteIOContext *s, const GUID *g)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 put_le32(s, g->v1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 put_le16(s, g->v2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 put_le16(s, g->v3);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 for(i=0;i<8;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 put_byte(s, g->v4[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 static void put_str16(ByteIOContext *s, const char *tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 int c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 put_le16(s,strlen(tag) + 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 for(;;) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
213 c = (uint8_t)*tag++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 put_le16(s, c);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 if (c == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 static void put_str16_nolen(ByteIOContext *s, const char *tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 int c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 for(;;) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
225 c = (uint8_t)*tag++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 put_le16(s, c);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 if (c == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
232 static int64_t put_header(ByteIOContext *pb, const GUID *g)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
234 int64_t pos;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 put_guid(pb, g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 put_le64(pb, 24);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 return pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 /* update header size */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
243 static void end_header(ByteIOContext *pb, int64_t pos)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
245 int64_t pos1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 pos1 = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 url_fseek(pb, pos + 16, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 put_le64(pb, pos1 - pos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 url_fseek(pb, pos1, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 /* write an asf chunk (only used in streaming case) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 int length;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 length = payload_length + 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 put_le16(pb, type);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 put_le16(pb, length);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 put_le32(pb, asf->seqno);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 put_le16(pb, flags); /* unknown bytes */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 put_le16(pb, length);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 asf->seqno++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
268
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 /* convert from unix to windows time */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
270 static int64_t unix_to_file_time(int ti)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
272 int64_t t;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
274 t = ti * int64_t_C(10000000);
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
275 t += int64_t_C(116444736000000000);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276 return t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279 /* write the header (used two times if non streamed) */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
280 static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285 int has_title;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 AVCodecContext *enc;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
287 int64_t header_offset, cur_pos, hpos;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288 int bit_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 has_title = (s->title[0] || s->author[0] || s->copyright[0] || s->comment[0]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292 bit_rate = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293 for(n=0;n<s->nb_streams;n++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 enc = &s->streams[n]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
296 bit_rate += enc->bit_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
297 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
298
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
299 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300 put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
302
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303 put_guid(pb, &asf_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
304 put_le64(pb, -1); /* header length, will be patched after */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
305 put_le32(pb, 3 + has_title + s->nb_streams); /* number of chunks in header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306 put_byte(pb, 1); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307 put_byte(pb, 2); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
308
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309 /* file header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310 header_offset = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
311 hpos = put_header(pb, &file_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
312 put_guid(pb, &my_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
313 put_le64(pb, file_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
314 file_time = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315 put_le64(pb, unix_to_file_time(file_time));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316 put_le64(pb, asf->nb_packets); /* number of packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
317 put_le64(pb, asf->duration); /* end time stamp (in 100ns units) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318 put_le64(pb, asf->duration); /* duration (in 100ns units) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
319 put_le32(pb, 0); /* start time stamp */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
320 put_le32(pb, 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
321 put_le32(pb, asf->is_streamed ? 1 : 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
322 put_le32(pb, asf->packet_size); /* packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
323 put_le32(pb, asf->packet_size); /* packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
324 put_le32(pb, bit_rate); /* Nominal data rate in bps */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
325 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 /* unknown headers */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328 hpos = put_header(pb, &head1_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
329 put_guid(pb, &head2_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330 put_le32(pb, 6);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334 /* title and other infos */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335 if (has_title) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
336 hpos = put_header(pb, &comment_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337 put_le16(pb, 2 * (strlen(s->title) + 1));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 put_le16(pb, 2 * (strlen(s->author) + 1));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339 put_le16(pb, 2 * (strlen(s->copyright) + 1));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
340 put_le16(pb, 2 * (strlen(s->comment) + 1));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
341 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342 put_str16_nolen(pb, s->title);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343 put_str16_nolen(pb, s->author);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
344 put_str16_nolen(pb, s->copyright);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
345 put_str16_nolen(pb, s->comment);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
346 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349 /* stream headers */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350 for(n=0;n<s->nb_streams;n++) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
351 int64_t es_pos;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 // ASFStream *stream = &asf->streams[n];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
353
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
354 enc = &s->streams[n]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
355 asf->streams[n].num = n + 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356 asf->streams[n].seq = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
358 switch(enc->codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360 wav_extra_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361 extra_size = 18 + wav_extra_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
362 extra_size2 = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
365 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
366 wav_extra_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
367 extra_size = 0x33;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
368 extra_size2 = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
369 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
370 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
371
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
372 hpos = put_header(pb, &stream_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
373 if (enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
374 put_guid(pb, &audio_stream);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375 put_guid(pb, &audio_conceal_none);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
377 put_guid(pb, &video_stream);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
378 put_guid(pb, &video_conceal_none);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
379 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
380 put_le64(pb, 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
381 es_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
382 put_le32(pb, extra_size); /* wav header len */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
383 put_le32(pb, extra_size2); /* additional data len */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
384 put_le16(pb, n + 1); /* stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
385 put_le32(pb, 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
386
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
387 if (enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
388 /* WAVEFORMATEX header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
389 int wavsize = put_wav_header(pb, enc);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
390
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
391 if (wavsize < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
393 if (wavsize != extra_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 cur_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395 url_fseek(pb, es_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396 put_le32(pb, wavsize); /* wav header len */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
397 url_fseek(pb, cur_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
398 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
400 put_le32(pb, enc->width);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
401 put_le32(pb, enc->height);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
402 put_byte(pb, 2); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403 put_le16(pb, 40); /* size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405 /* BITMAPINFOHEADER header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
406 put_bmp_header(pb, enc, codec_bmp_tags, 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
407 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
408 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
409 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
411 /* media comments */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 hpos = put_header(pb, &codec_comment_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 put_guid(pb, &codec_comment1_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415 put_le32(pb, s->nb_streams);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 for(n=0;n<s->nb_streams;n++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 AVCodec *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419 enc = &s->streams[n]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420 p = avcodec_find_encoder(enc->codec_id);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
421
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
422 put_le16(pb, asf->streams[n].num);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 put_str16(pb, p ? p->name : enc->codec_name);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424 put_le16(pb, 0); /* no parameters */
196
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
425
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
426
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427 /* id */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
428 if (enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429 put_le16(pb, 2);
196
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
430 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
431 enc->codec_tag = codec_get_tag(codec_wav_tags, enc->codec_id);
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
432 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
433 return -1;
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
434 put_le16(pb, enc->codec_tag);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 put_le16(pb, 4);
196
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
437 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
438 enc->codec_tag = codec_get_tag(codec_bmp_tags, enc->codec_id);
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
439 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
440 return -1;
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
441 put_le32(pb, enc->codec_tag);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446 /* patch the header size fields */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 cur_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449 header_size = cur_pos - header_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451 header_size += 8 + 30 + 50;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453 url_fseek(pb, header_offset - 10 - 30, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
454 put_le16(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455 url_fseek(pb, header_offset - 2 - 30, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
456 put_le16(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
457
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
458 header_size -= 8 + 30 + 50;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
460 header_size += 24 + 6;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461 url_fseek(pb, header_offset - 14, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
462 put_le64(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463 url_fseek(pb, cur_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
464
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
465 /* movie chunk, followed by packets of packet_size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
466 asf->data_offset = cur_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467 put_guid(pb, &data_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468 put_le64(pb, data_chunk_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469 put_guid(pb, &my_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470 put_le64(pb, asf->nb_packets); /* nb packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
471 put_byte(pb, 1); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472 put_byte(pb, 1); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
473 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
474 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
475
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
476 static int asf_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
477 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
478 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
479
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
480 av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
481
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
482 asf->packet_size = PACKET_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
483 asf->nb_packets = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
484
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
485 if (asf_write_header1(s, 0, 50) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
486 //av_free(asf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
487 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
488 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
489
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
490 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
491
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
492 asf->packet_nb_frames = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
493 asf->packet_timestamp_start = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
494 asf->packet_timestamp_end = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
495 asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
496 init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
497 NULL, NULL, NULL, NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
498
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
499 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
500 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
501
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
502 static int asf_write_stream_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
503 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
504 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
505
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
506 asf->is_streamed = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
507
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
508 return asf_write_header(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
509 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
510
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
511 /* write a fixed size packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
512 static int put_packet(AVFormatContext *s,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
513 unsigned int timestamp, unsigned int duration,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
514 int nb_frames, int padsize)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
515 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
516 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
517 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
518 int flags;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
519
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
520 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
521 put_chunk(s, 0x4424, asf->packet_size, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
522 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
523
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
524 put_byte(pb, 0x82);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
525 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
526
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
527 flags = 0x01; /* nb segments present */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
528 if (padsize > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
529 if (padsize < 256)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
530 flags |= 0x08;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
531 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
532 flags |= 0x10;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
533 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
534 put_byte(pb, flags); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
535 put_byte(pb, 0x5d);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
536 if (flags & 0x10)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
537 put_le16(pb, padsize - 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
538 if (flags & 0x08)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
539 put_byte(pb, padsize - 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
540 put_le32(pb, timestamp);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
541 put_le16(pb, duration);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
542 put_byte(pb, nb_frames | 0x80);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
543
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
544 return PACKET_HEADER_SIZE + ((flags & 0x18) >> 3);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
545 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
546
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
547 static void flush_packet(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
548 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
549 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
550 int hdr_size, ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
551
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
552 hdr_size = put_packet(s, asf->packet_timestamp_start,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
553 asf->packet_timestamp_end - asf->packet_timestamp_start,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
554 asf->packet_nb_frames, asf->packet_size_left);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
555
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
556 /* Clear out the padding bytes */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
557 ptr = asf->packet_size - hdr_size - asf->packet_size_left;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
558 memset(asf->packet_buf + ptr, 0, asf->packet_size_left);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
559
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
560 put_buffer(&s->pb, asf->packet_buf, asf->packet_size - hdr_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
561
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
562 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
563 asf->nb_packets++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
564 asf->packet_nb_frames = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
565 asf->packet_timestamp_start = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
566 asf->packet_timestamp_end = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
567 asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
568 init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
569 NULL, NULL, NULL, NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
570 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
571
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
572 static void put_frame_header(AVFormatContext *s, ASFStream *stream, int timestamp,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
573 int payload_size, int frag_offset, int frag_len)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
574 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
575 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
576 ByteIOContext *pb = &asf->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
577 int val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
578
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
579 val = stream->num;
7
47e502ac6349 AVVideoFrame -> AVFrame
michaelni
parents: 5
diff changeset
580 if (s->streams[val - 1]->codec.coded_frame->key_frame /* && frag_offset == 0 */)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
581 val |= 0x80;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
582 put_byte(pb, val);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
583 put_byte(pb, stream->seq);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
584 put_le32(pb, frag_offset); /* fragment offset */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
585 put_byte(pb, 0x08); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
586 put_le32(pb, payload_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
587 put_le32(pb, timestamp);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
588 put_le16(pb, frag_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
589 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
590
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
591
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
592 /* Output a frame. We suppose that payload_size <= PACKET_SIZE.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
593
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
594 It is there that you understand that the ASF format is really
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
595 crap. They have misread the MPEG Systems spec !
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
596 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
597 static void put_frame(AVFormatContext *s, ASFStream *stream, int timestamp,
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 232
diff changeset
598 const uint8_t *buf, int payload_size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
599 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
600 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
601 int frag_pos, frag_len, frag_len1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
602
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
603 frag_pos = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
604 while (frag_pos < payload_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
605 frag_len = payload_size - frag_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
606 frag_len1 = asf->packet_size_left - FRAME_HEADER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
607 if (frag_len1 > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
608 if (frag_len > frag_len1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
609 frag_len = frag_len1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
610 put_frame_header(s, stream, timestamp+1, payload_size, frag_pos, frag_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
611 put_buffer(&asf->pb, buf, frag_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
612 asf->packet_size_left -= (frag_len + FRAME_HEADER_SIZE);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
613 asf->packet_timestamp_end = timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
614 if (asf->packet_timestamp_start == -1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
615 asf->packet_timestamp_start = timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
616 asf->packet_nb_frames++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
617 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
618 frag_len = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
619 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
620 frag_pos += frag_len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
621 buf += frag_len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
622 /* output the frame if filled */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
623 if (asf->packet_size_left <= FRAME_HEADER_SIZE)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
624 flush_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
625 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
626 stream->seq++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
627 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
628
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
629
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
630 static int asf_write_packet(AVFormatContext *s, int stream_index,
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 232
diff changeset
631 const uint8_t *buf, int size, int64_t timestamp)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
632 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
633 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
634 ASFStream *stream;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
635 int64_t duration;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
636 AVCodecContext *codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
637
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
638 codec = &s->streams[stream_index]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
639 stream = &asf->streams[stream_index];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
640
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
641 if (codec->codec_type == CODEC_TYPE_AUDIO) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
642 duration = (codec->frame_number * codec->frame_size * int64_t_C(10000000)) /
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
643 codec->sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
644 } else {
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 84
diff changeset
645 duration = av_rescale(codec->frame_number * codec->frame_rate_base, 10000000, codec->frame_rate);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
646 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
647 if (duration > asf->duration)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
648 asf->duration = duration;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
649
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
650 put_frame(s, stream, timestamp, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
651 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
652 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
653
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
654 static int asf_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
655 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
656 ASFContext *asf = s->priv_data;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
657 int64_t file_size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
658
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
659 /* flush the current packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
660 if (asf->pb.buf_ptr > asf->pb.buffer)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
661 flush_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
662
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
663 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
664 put_chunk(s, 0x4524, 0, 0); /* end of stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
665 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
666 /* rewrite an updated header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
667 file_size = url_ftell(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
668 url_fseek(&s->pb, 0, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
669 asf_write_header1(s, file_size, file_size - asf->data_offset);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
670 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
671
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
672 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
673 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
674 }
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
675 #endif //CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
676
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
677 /**********************************/
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
678 /* decoding */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
679
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
680 //#define DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
681
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
682 #ifdef DEBUG
69
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
683 #define PRINT_IF_GUID(g,cmp) \
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
684 if (!memcmp(g, &cmp, sizeof(GUID))) \
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
685 printf("(GUID: %s) ", #cmp)
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
686
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
687 static void print_guid(const GUID *g)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
688 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
689 int i;
69
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
690 PRINT_IF_GUID(g, asf_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
691 else PRINT_IF_GUID(g, file_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
692 else PRINT_IF_GUID(g, stream_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
693 else PRINT_IF_GUID(g, audio_stream);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
694 else PRINT_IF_GUID(g, audio_conceal_none);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
695 else PRINT_IF_GUID(g, video_stream);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
696 else PRINT_IF_GUID(g, video_conceal_none);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
697 else PRINT_IF_GUID(g, comment_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
698 else PRINT_IF_GUID(g, codec_comment_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
699 else PRINT_IF_GUID(g, codec_comment1_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
700 else PRINT_IF_GUID(g, data_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
701 else PRINT_IF_GUID(g, index_guid);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
702 else PRINT_IF_GUID(g, head1_guid);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
703 else PRINT_IF_GUID(g, head2_guid);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
704 else PRINT_IF_GUID(g, my_guid);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
705 else
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
706 printf("(GUID: unknown) ");
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
707 printf("0x%08x, 0x%04x, 0x%04x, {", g->v1, g->v2, g->v3);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
708 for(i=0;i<8;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
709 printf(" 0x%02x,", g->v4[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
710 printf("}\n");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
711 }
69
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
712 #undef PRINT_IF_GUID(g,cmp)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
713 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
714
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
715 static void get_guid(ByteIOContext *s, GUID *g)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
716 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
717 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
718
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
719 g->v1 = get_le32(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
720 g->v2 = get_le16(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
721 g->v3 = get_le16(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
722 for(i=0;i<8;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
723 g->v4[i] = get_byte(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
724 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
725
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
726 #if 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
727 static void get_str16(ByteIOContext *pb, char *buf, int buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
728 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
729 int len, c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
730 char *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
731
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
732 len = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
733 q = buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
734 while (len > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
735 c = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
736 if ((q - buf) < buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
737 *q++ = c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
738 len--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
739 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
740 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
741 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
742 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
743
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
744 static void get_str16_nolen(ByteIOContext *pb, int len, char *buf, int buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
745 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
746 int c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
747 char *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
748
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
749 q = buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
750 while (len > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
751 c = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
752 if ((q - buf) < buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
753 *q++ = c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
754 len-=2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
755 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
756 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
757 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
758
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
759 static int asf_probe(AVProbeData *pd)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
760 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
761 GUID g;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
762 const unsigned char *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
763 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
764
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
765 /* check file header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
766 if (pd->buf_size <= 32)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
767 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
768 p = pd->buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
769 g.v1 = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
770 p += 4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
771 g.v2 = p[0] | (p[1] << 8);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
772 p += 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
773 g.v3 = p[0] | (p[1] << 8);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
774 p += 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
775 for(i=0;i<8;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
776 g.v4[i] = *p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
777
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
778 if (!memcmp(&g, &asf_header, sizeof(GUID)))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
779 return AVPROBE_SCORE_MAX;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
780 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
781 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
782 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
783
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
784 static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
785 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
786 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
787 GUID g;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
788 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
789 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
790 ASFStream *asf_st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
791 int size, i;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
792 int64_t gsize;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
793
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
794 av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
795
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
796 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
797 if (memcmp(&g, &asf_header, sizeof(GUID)))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
798 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
799 get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
800 get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
801 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
802 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
803 memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
804 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
805 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
806 gsize = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
807 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
808 printf("%08Lx: ", url_ftell(pb) - 24);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
809 print_guid(&g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
810 printf(" size=0x%Lx\n", gsize);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
811 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
812 if (gsize < 24)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
813 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
814 if (!memcmp(&g, &file_header, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
815 get_guid(pb, &asf->hdr.guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
816 asf->hdr.file_size = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
817 asf->hdr.create_time = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
818 asf->hdr.packets_count = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
819 asf->hdr.play_time = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
820 asf->hdr.send_time = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
821 asf->hdr.preroll = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
822 asf->hdr.ignore = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
823 asf->hdr.flags = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
824 asf->hdr.min_pktsize = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
825 asf->hdr.max_pktsize = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
826 asf->hdr.max_bitrate = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
827 asf->packet_size = asf->hdr.max_pktsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
828 asf->nb_packets = asf->hdr.packets_count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
829 } else if (!memcmp(&g, &stream_header, sizeof(GUID))) {
84
0068a6902911 correct AUDIO strf parsing patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 74
diff changeset
830 int type, total_size, type_specific_size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
831 unsigned int tag1;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
832 int64_t pos1, pos2;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
833
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
834 pos1 = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
835
188
6c9d6422a2f6 update duration and start_time - add av_new_stream() usage
bellard
parents: 136
diff changeset
836 st = av_new_stream(s, 0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
837 if (!st)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
838 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
839 asf_st = av_mallocz(sizeof(ASFStream));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
840 if (!asf_st)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
841 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
842 st->priv_data = asf_st;
188
6c9d6422a2f6 update duration and start_time - add av_new_stream() usage
bellard
parents: 136
diff changeset
843 st->start_time = asf->hdr.preroll / (10000000 / AV_TIME_BASE);
6c9d6422a2f6 update duration and start_time - add av_new_stream() usage
bellard
parents: 136
diff changeset
844 st->duration = (asf->hdr.send_time - asf->hdr.preroll) /
6c9d6422a2f6 update duration and start_time - add av_new_stream() usage
bellard
parents: 136
diff changeset
845 (10000000 / AV_TIME_BASE);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
846 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
847 if (!memcmp(&g, &audio_stream, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
848 type = CODEC_TYPE_AUDIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
849 } else if (!memcmp(&g, &video_stream, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
850 type = CODEC_TYPE_VIDEO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
851 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
852 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
853 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
854 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
855 total_size = get_le64(pb);
84
0068a6902911 correct AUDIO strf parsing patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 74
diff changeset
856 type_specific_size = get_le32(pb);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
857 get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
858 st->id = get_le16(pb) & 0x7f; /* stream id */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
859 // mapping of asf ID to AV stream ID;
188
6c9d6422a2f6 update duration and start_time - add av_new_stream() usage
bellard
parents: 136
diff changeset
860 asf->asfid2avid[st->id] = s->nb_streams - 1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
861
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
862 get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
863 st->codec.codec_type = type;
312
8a04d2e1be2f frame rate should be completely disabled in asf (closer now) - disabled seek
bellard
parents: 300
diff changeset
864 /* 1 fps default (XXX: put 0 fps instead) */
8a04d2e1be2f frame rate should be completely disabled in asf (closer now) - disabled seek
bellard
parents: 300
diff changeset
865 st->codec.frame_rate = 1;
8a04d2e1be2f frame rate should be completely disabled in asf (closer now) - disabled seek
bellard
parents: 300
diff changeset
866 st->codec.frame_rate_base = 1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
867 if (type == CODEC_TYPE_AUDIO) {
84
0068a6902911 correct AUDIO strf parsing patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 74
diff changeset
868 get_wav_header(pb, &st->codec, type_specific_size);
312
8a04d2e1be2f frame rate should be completely disabled in asf (closer now) - disabled seek
bellard
parents: 300
diff changeset
869 st->need_parsing = 1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
870 /* We have to init the frame size at some point .... */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
871 pos2 = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
872 if (gsize > (pos2 + 8 - pos1 + 24)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
873 asf_st->ds_span = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
874 asf_st->ds_packet_size = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
875 asf_st->ds_chunk_size = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
876 asf_st->ds_data_size = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
877 asf_st->ds_silence_data = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
878 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
879 //printf("Descrambling: ps:%d cs:%d ds:%d s:%d sd:%d\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
880 // asf_st->ds_packet_size, asf_st->ds_chunk_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
881 // asf_st->ds_data_size, asf_st->ds_span, asf_st->ds_silence_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
882 if (asf_st->ds_span > 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
883 if (!asf_st->ds_chunk_size
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
884 || (asf_st->ds_packet_size/asf_st->ds_chunk_size <= 1))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
885 asf_st->ds_span = 0; // disable descrambling
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
886 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
887 switch (st->codec.codec_id) {
232
eb90c0a5a1ba CODEC_ID_MP3LAME is obsolete
bellard
parents: 196
diff changeset
888 case CODEC_ID_MP3:
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
889 st->codec.frame_size = MPA_FRAME_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
890 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
891 case CODEC_ID_PCM_S16LE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
892 case CODEC_ID_PCM_S16BE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
893 case CODEC_ID_PCM_U16LE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
894 case CODEC_ID_PCM_U16BE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
895 case CODEC_ID_PCM_S8:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
896 case CODEC_ID_PCM_U8:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
897 case CODEC_ID_PCM_ALAW:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
898 case CODEC_ID_PCM_MULAW:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
899 st->codec.frame_size = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
900 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
901 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
902 /* This is probably wrong, but it prevents a crash later */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
903 st->codec.frame_size = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
904 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
905 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
906 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
907 get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
908 get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
909 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
910 size = get_le16(pb); /* size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
911 get_le32(pb); /* size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
912 st->codec.width = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
913 st->codec.height = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
914 /* not available for asf */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
915 get_le16(pb); /* panes */
117
497ae2790081 * filling bitdepth
kabi
parents: 85
diff changeset
916 st->codec.bits_per_sample = get_le16(pb); /* depth */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
917 tag1 = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
918 url_fskip(pb, 20);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
919 if (size > 40) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
920 st->codec.extradata_size = size - 40;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
921 st->codec.extradata = av_mallocz(st->codec.extradata_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
922 get_buffer(pb, st->codec.extradata, st->codec.extradata_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
923 }
297
85d558a18134 Make avi and asf demuxer export palette in palctrl
rtognimp
parents: 277
diff changeset
924
85d558a18134 Make avi and asf demuxer export palette in palctrl
rtognimp
parents: 277
diff changeset
925 /* Extract palette from extradata if bpp <= 8 */
85d558a18134 Make avi and asf demuxer export palette in palctrl
rtognimp
parents: 277
diff changeset
926 /* This code assumes that extradata contains only palette */
85d558a18134 Make avi and asf demuxer export palette in palctrl
rtognimp
parents: 277
diff changeset
927 /* This is true for all paletted codecs implemented in ffmpeg */
85d558a18134 Make avi and asf demuxer export palette in palctrl
rtognimp
parents: 277
diff changeset
928 if (st->codec.extradata_size && (st->codec.bits_per_sample <= 8)) {
85d558a18134 Make avi and asf demuxer export palette in palctrl
rtognimp
parents: 277
diff changeset
929 st->codec.palctrl = av_mallocz(sizeof(AVPaletteControl));
85d558a18134 Make avi and asf demuxer export palette in palctrl
rtognimp
parents: 277
diff changeset
930 #ifdef WORDS_BIGENDIAN
300
6ee1b02f9b2a * fixes for broken builds on Solaris, OS2 and all bingendian
romansh
parents: 297
diff changeset
931 for (i = 0; i < FFMIN(st->codec.extradata_size, AVPALETTE_SIZE)/4; i++)
6ee1b02f9b2a * fixes for broken builds on Solaris, OS2 and all bingendian
romansh
parents: 297
diff changeset
932 st->codec.palctrl->palette[i] = bswap_32(((uint32_t*)st->codec.extradata)[i]);
297
85d558a18134 Make avi and asf demuxer export palette in palctrl
rtognimp
parents: 277
diff changeset
933 #else
85d558a18134 Make avi and asf demuxer export palette in palctrl
rtognimp
parents: 277
diff changeset
934 memcpy(st->codec.palctrl->palette, st->codec.extradata,
85d558a18134 Make avi and asf demuxer export palette in palctrl
rtognimp
parents: 277
diff changeset
935 FFMIN(st->codec.extradata_size, AVPALETTE_SIZE));
85d558a18134 Make avi and asf demuxer export palette in palctrl
rtognimp
parents: 277
diff changeset
936 #endif
85d558a18134 Make avi and asf demuxer export palette in palctrl
rtognimp
parents: 277
diff changeset
937 st->codec.palctrl->palette_changed = 1;
85d558a18134 Make avi and asf demuxer export palette in palctrl
rtognimp
parents: 277
diff changeset
938 }
85d558a18134 Make avi and asf demuxer export palette in palctrl
rtognimp
parents: 277
diff changeset
939
74
4b501fe1539c merging fourcc with codec_tag
michaelni
parents: 69
diff changeset
940 st->codec.codec_tag = tag1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
941 st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
942 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
943 pos2 = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
944 url_fskip(pb, gsize - (pos2 - pos1 + 24));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
945 } else if (!memcmp(&g, &data_header, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
946 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
947 } else if (!memcmp(&g, &comment_header, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
948 int len1, len2, len3, len4, len5;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
949
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
950 len1 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
951 len2 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
952 len3 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
953 len4 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
954 len5 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
955 get_str16_nolen(pb, len1, s->title, sizeof(s->title));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
956 get_str16_nolen(pb, len2, s->author, sizeof(s->author));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
957 get_str16_nolen(pb, len3, s->copyright, sizeof(s->copyright));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
958 get_str16_nolen(pb, len4, s->comment, sizeof(s->comment));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
959 url_fskip(pb, len5);
341
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
960 } else if (!memcmp(&g, &extended_content_header, sizeof(GUID))) {
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
961 int desc_count, i;
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
962
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
963 desc_count = get_le16(pb);
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
964 for(i=0;i<desc_count;i++)
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
965 {
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
966 int name_len,value_type,value_len,value_num = 0;
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
967 char *name, *value;
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
968
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
969 name_len = get_le16(pb);
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
970 name = (char *)av_mallocz(name_len);
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
971 get_str16_nolen(pb, name_len, name, name_len);
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
972 value_type = get_le16(pb);
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
973 value_len = get_le16(pb);
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
974 if ((value_type == 0) || (value_type == 1)) // unicode or byte
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
975 {
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
976 value = (char *)av_mallocz(value_len);
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
977 get_str16_nolen(pb, value_len, value, value_len);
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
978 if (strcmp(name,"WM/AlbumTitle")==0) { strcpy(s->album, value); }
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
979 av_free(value);
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
980 }
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
981 if ((value_type >= 2) || (value_type <= 5)) // boolean or DWORD or QWORD or WORD
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
982 {
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
983 if (value_type==2) value_num = get_le32(pb);
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
984 if (value_type==3) value_num = get_le32(pb);
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
985 if (value_type==4) value_num = get_le64(pb);
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
986 if (value_type==5) value_num = get_le16(pb);
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
987 if (strcmp(name,"WM/Track")==0) s->track = value_num + 1;
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
988 if (strcmp(name,"WM/TrackNumber")==0) s->track = value_num;
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
989 }
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
990 av_free(name);
ad2a57c5467a ASF extended header parsing patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 312
diff changeset
991 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
992 #if 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
993 } else if (!memcmp(&g, &head1_guid, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
994 int v1, v2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
995 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
996 v1 = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
997 v2 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
998 } else if (!memcmp(&g, &codec_comment_header, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
999 int len, v1, n, num;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1000 char str[256], *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1001 char tag[16];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1002
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1003 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1004 print_guid(&g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1005
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1006 n = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1007 for(i=0;i<n;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1008 num = get_le16(pb); /* stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1009 get_str16(pb, str, sizeof(str));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1010 get_str16(pb, str, sizeof(str));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1011 len = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1012 q = tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1013 while (len > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1014 v1 = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1015 if ((q - tag) < sizeof(tag) - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1016 *q++ = v1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1017 len--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1018 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1019 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1020 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1021 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1022 } else if (url_feof(pb)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1023 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1024 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1025 url_fseek(pb, gsize - 24, SEEK_CUR);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1026 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1027 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1028 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1029 get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1030 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1031 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1032 if (url_feof(pb))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1033 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1034 asf->data_offset = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1035 asf->packet_size_left = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1036
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1037 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1038
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1039 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1040 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1041 AVStream *st = s->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1042 if (st) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1043 av_free(st->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1044 av_free(st->codec.extradata);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1045 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1046 av_free(st);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1047 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1048 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1049 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1050
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1051 #define DO_2BITS(bits, var, defval) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1052 switch (bits & 3) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1053 { \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1054 case 3: var = get_le32(pb); rsize += 4; break; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1055 case 2: var = get_le16(pb); rsize += 2; break; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1056 case 1: var = get_byte(pb); rsize++; break; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1057 default: var = defval; break; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1058 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1059
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1060 static int asf_get_packet(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1061 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1062 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1063 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1064 uint32_t packet_length, padsize;
353
0778b93924cb header parser fix
michael
parents: 352
diff changeset
1065 int rsize = 9;
0778b93924cb header parser fix
michael
parents: 352
diff changeset
1066 int c;
0778b93924cb header parser fix
michael
parents: 352
diff changeset
1067
0778b93924cb header parser fix
michael
parents: 352
diff changeset
1068 assert((url_ftell(&s->pb) - s->data_offset) % asf->packet_size == 0);
0778b93924cb header parser fix
michael
parents: 352
diff changeset
1069
0778b93924cb header parser fix
michael
parents: 352
diff changeset
1070 c = get_byte(pb);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1071 if (c != 0x82) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1072 if (!url_feof(pb))
136
6b74809d2496 Warning and compatibility fixes.
mellum
parents: 117
diff changeset
1073 printf("ff asf bad header %x at:%lld\n", c, url_ftell(pb));
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1074 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1075 if ((c & 0x0f) == 2) { // always true for now
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1076 if (get_le16(pb) != 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1077 if (!url_feof(pb))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1078 printf("ff asf bad non zero\n");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1079 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1080 }
353
0778b93924cb header parser fix
michael
parents: 352
diff changeset
1081 rsize+=2;
0778b93924cb header parser fix
michael
parents: 352
diff changeset
1082 /* }else{
0778b93924cb header parser fix
michael
parents: 352
diff changeset
1083 if (!url_feof(pb))
0778b93924cb header parser fix
michael
parents: 352
diff changeset
1084 printf("ff asf bad header %x at:%lld\n", c, url_ftell(pb));
0778b93924cb header parser fix
michael
parents: 352
diff changeset
1085 return -EIO;*/
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1086 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1087
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1088 asf->packet_flags = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1089 asf->packet_property = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1090
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1091 DO_2BITS(asf->packet_flags >> 5, packet_length, asf->packet_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1092 DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence ignored
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1093 DO_2BITS(asf->packet_flags >> 3, padsize, 0); // padding length
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1094
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1095 asf->packet_timestamp = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1096 get_le16(pb); /* duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1097 // rsize has at least 11 bytes which have to be present
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1098
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1099 if (asf->packet_flags & 0x01) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1100 asf->packet_segsizetype = get_byte(pb); rsize++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1101 asf->packet_segments = asf->packet_segsizetype & 0x3f;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1102 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1103 asf->packet_segments = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1104 asf->packet_segsizetype = 0x80;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1105 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1106 asf->packet_size_left = packet_length - padsize - rsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1107 if (packet_length < asf->hdr.min_pktsize)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1108 padsize += asf->hdr.min_pktsize - packet_length;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1109 asf->packet_padsize = padsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1110 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1111 printf("packet: size=%d padsize=%d left=%d\n", asf->packet_size, asf->packet_padsize, asf->packet_size_left);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1112 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1113 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1114 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1115
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1116 static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1117 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1118 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1119 ASFStream *asf_st = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1120 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1121 //static int pc = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1122 for (;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1123 int rsize = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1124 if (asf->packet_size_left < FRAME_HEADER_SIZE
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1125 || asf->packet_segments < 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1126 //asf->packet_size_left <= asf->packet_padsize) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1127 int ret = asf->packet_size_left + asf->packet_padsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1128 //printf("PacketLeftSize:%d Pad:%d Pos:%Ld\n", asf->packet_size_left, asf->packet_padsize, url_ftell(pb));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1129 /* fail safe */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1130 url_fskip(pb, ret);
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1131 asf->packet_pos= url_ftell(&s->pb);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1132 ret = asf_get_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1133 //printf("READ ASF PACKET %d r:%d c:%d\n", ret, asf->packet_size_left, pc++);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1134 if (ret < 0 || url_feof(pb))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1135 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1136 asf->packet_time_start = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1137 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1138 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1139 if (asf->packet_time_start == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1140 /* read frame header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1141 int num = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1142 asf->packet_segments--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1143 rsize++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1144 asf->packet_key_frame = (num & 0x80) >> 7;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1145 asf->stream_index = asf->asfid2avid[num & 0x7f];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1146 // sequence should be ignored!
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1147 DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1148 DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1149 DO_2BITS(asf->packet_property, asf->packet_replic_size, 0);
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1150 //printf("key:%d stream:%d seq:%d offset:%d replic_size:%d\n", asf->packet_key_frame, asf->stream_index, asf->packet_seq, //asf->packet_frag_offset, asf->packet_replic_size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1151 if (asf->packet_replic_size > 1) {
352
c5ea5cdb5b58 replic_size==0 fix, needed so that G.726 asf file, so ffmpeg can at least decode the video without segfaulting
michael
parents: 351
diff changeset
1152 assert(asf->packet_replic_size >= 8);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1153 // it should be always at least 8 bytes - FIXME validate
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1154 asf->packet_obj_size = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1155 asf->packet_frag_timestamp = get_le32(pb); // timestamp
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1156 if (asf->packet_replic_size > 8)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1157 url_fskip(pb, asf->packet_replic_size - 8);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1158 rsize += asf->packet_replic_size; // FIXME - check validity
352
c5ea5cdb5b58 replic_size==0 fix, needed so that G.726 asf file, so ffmpeg can at least decode the video without segfaulting
michael
parents: 351
diff changeset
1159 } else if (asf->packet_replic_size==1){
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1160 // multipacket - frag_offset is begining timestamp
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1161 asf->packet_time_start = asf->packet_frag_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1162 asf->packet_frag_offset = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1163 asf->packet_frag_timestamp = asf->packet_timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1164
352
c5ea5cdb5b58 replic_size==0 fix, needed so that G.726 asf file, so ffmpeg can at least decode the video without segfaulting
michael
parents: 351
diff changeset
1165 asf->packet_time_delta = get_byte(pb);
c5ea5cdb5b58 replic_size==0 fix, needed so that G.726 asf file, so ffmpeg can at least decode the video without segfaulting
michael
parents: 351
diff changeset
1166 rsize++;
c5ea5cdb5b58 replic_size==0 fix, needed so that G.726 asf file, so ffmpeg can at least decode the video without segfaulting
michael
parents: 351
diff changeset
1167 }else{
c5ea5cdb5b58 replic_size==0 fix, needed so that G.726 asf file, so ffmpeg can at least decode the video without segfaulting
michael
parents: 351
diff changeset
1168 assert(asf->packet_replic_size==0);
c5ea5cdb5b58 replic_size==0 fix, needed so that G.726 asf file, so ffmpeg can at least decode the video without segfaulting
michael
parents: 351
diff changeset
1169 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1170 if (asf->packet_flags & 0x01) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1171 DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1172 #undef DO_2BITS
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1173 //printf("Fragsize %d\n", asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1174 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1175 asf->packet_frag_size = asf->packet_size_left - rsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1176 //printf("Using rest %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1177 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1178 if (asf->packet_replic_size == 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1179 asf->packet_multi_size = asf->packet_frag_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1180 if (asf->packet_multi_size > asf->packet_size_left) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1181 asf->packet_segments = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1182 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1183 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1184 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1185 asf->packet_size_left -= rsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1186 //printf("___objsize____ %d %d rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1187
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1188 if (asf->stream_index < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1189 asf->packet_time_start = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1190 /* unhandled packet (should not happen) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1191 url_fskip(pb, asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1192 asf->packet_size_left -= asf->packet_frag_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1193 printf("ff asf skip %d %d\n", asf->packet_frag_size, num & 0x7f);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1194 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1195 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1196 asf->asf_st = s->streams[asf->stream_index]->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1197 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1198 asf_st = asf->asf_st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1199
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1200 if ((asf->packet_frag_offset != asf_st->frag_offset
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1201 || (asf->packet_frag_offset
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1202 && asf->packet_seq != asf_st->seq)) // seq should be ignored
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1203 ) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1204 /* cannot continue current packet: free it */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1205 // FIXME better check if packet was already allocated
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1206 printf("ff asf parser skips: %d - %d o:%d - %d %d %d fl:%d\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1207 asf_st->pkt.size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1208 asf->packet_obj_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1209 asf->packet_frag_offset, asf_st->frag_offset,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1210 asf->packet_seq, asf_st->seq, asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1211 if (asf_st->pkt.size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1212 av_free_packet(&asf_st->pkt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1213 asf_st->frag_offset = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1214 if (asf->packet_frag_offset != 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1215 url_fskip(pb, asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1216 printf("ff asf parser skiping %db\n", asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1217 asf->packet_size_left -= asf->packet_frag_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1218 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1219 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1220 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1221 if (asf->packet_replic_size == 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1222 // frag_offset is here used as the begining timestamp
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1223 asf->packet_frag_timestamp = asf->packet_time_start;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1224 asf->packet_time_start += asf->packet_time_delta;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1225 asf->packet_obj_size = asf->packet_frag_size = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1226 asf->packet_size_left--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1227 asf->packet_multi_size--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1228 if (asf->packet_multi_size < asf->packet_obj_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1229 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1230 asf->packet_time_start = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1231 url_fskip(pb, asf->packet_multi_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1232 asf->packet_size_left -= asf->packet_multi_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1233 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1234 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1235 asf->packet_multi_size -= asf->packet_obj_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1236 //printf("COMPRESS size %d %d %d ms:%d\n", asf->packet_obj_size, asf->packet_frag_timestamp, asf->packet_size_left, asf->packet_multi_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1237 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1238 if (asf_st->frag_offset == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1239 /* new packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1240 av_new_packet(&asf_st->pkt, asf->packet_obj_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1241 asf_st->seq = asf->packet_seq;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1242 asf_st->pkt.pts = asf->packet_frag_timestamp - asf->hdr.preroll;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1243 asf_st->pkt.stream_index = asf->stream_index;
352
c5ea5cdb5b58 replic_size==0 fix, needed so that G.726 asf file, so ffmpeg can at least decode the video without segfaulting
michael
parents: 351
diff changeset
1244 asf_st->packet_pos= asf->packet_pos;
c5ea5cdb5b58 replic_size==0 fix, needed so that G.726 asf file, so ffmpeg can at least decode the video without segfaulting
michael
parents: 351
diff changeset
1245 //printf("new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n",
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1246 //asf->stream_index, asf->packet_key_frame, asf_st->pkt.flags & PKT_FLAG_KEY,
352
c5ea5cdb5b58 replic_size==0 fix, needed so that G.726 asf file, so ffmpeg can at least decode the video without segfaulting
michael
parents: 351
diff changeset
1247 //s->streams[asf->stream_index]->codec.codec_type == CODEC_TYPE_AUDIO, asf->packet_obj_size);
347
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1248 if (s->streams[asf->stream_index]->codec.codec_type == CODEC_TYPE_AUDIO)
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1249 asf->packet_key_frame = 1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1250 if (asf->packet_key_frame)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1251 asf_st->pkt.flags |= PKT_FLAG_KEY;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1252 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1253
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1254 /* read data */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1255 //printf("READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1256 // asf->packet_size, asf_st->pkt.size, asf->packet_frag_offset,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1257 // asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1258 asf->packet_size_left -= asf->packet_frag_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1259 if (asf->packet_size_left < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1260 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1261 get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1262 asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1263 asf_st->frag_offset += asf->packet_frag_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1264 /* test if whole packet is read */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1265 if (asf_st->frag_offset == asf_st->pkt.size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1266 /* return packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1267 if (asf_st->ds_span > 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1268 /* packet descrambling */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1269 char* newdata = av_malloc(asf_st->pkt.size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1270 if (newdata) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1271 int offset = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1272 while (offset < asf_st->pkt.size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1273 int off = offset / asf_st->ds_chunk_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1274 int row = off / asf_st->ds_span;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1275 int col = off % asf_st->ds_span;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1276 int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1277 //printf("off:%d row:%d col:%d idx:%d\n", off, row, col, idx);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1278 memcpy(newdata + offset,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1279 asf_st->pkt.data + idx * asf_st->ds_chunk_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1280 asf_st->ds_chunk_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1281 offset += asf_st->ds_chunk_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1282 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1283 av_free(asf_st->pkt.data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1284 asf_st->pkt.data = newdata;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1285 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1286 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1287 asf_st->frag_offset = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1288 memcpy(pkt, &asf_st->pkt, sizeof(AVPacket));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1289 //printf("packet %d %d\n", asf_st->pkt.size, asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1290 asf_st->pkt.size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1291 asf_st->pkt.data = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1292 break; // packet completed
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1293 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1294 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1295 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1296 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1297
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1298 static int asf_read_close(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1299 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1300 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1301
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1302 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1303 AVStream *st = s->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1304 av_free(st->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1305 av_free(st->codec.extradata);
297
85d558a18134 Make avi and asf demuxer export palette in palctrl
rtognimp
parents: 277
diff changeset
1306 av_free(st->codec.palctrl);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1307 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1308 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1309 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1310
347
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1311 // Added to support seeking after packets have been read
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1312 // If information is not reset, read_packet fails due to
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1313 // leftover information from previous reads
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1314 static void asf_reset_header(AVFormatContext *s)
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1315 {
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1316 ASFContext *asf = s->priv_data;
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1317 ASFStream *asf_st;
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1318 int i;
347
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1319
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1320 asf->packet_nb_frames = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1321 asf->packet_timestamp_start = -1;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1322 asf->packet_timestamp_end = -1;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1323 asf->packet_size_left = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1324 asf->packet_segments = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1325 asf->packet_flags = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1326 asf->packet_property = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1327 asf->packet_timestamp = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1328 asf->packet_segsizetype = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1329 asf->packet_segments = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1330 asf->packet_seq = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1331 asf->packet_replic_size = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1332 asf->packet_key_frame = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1333 asf->packet_padsize = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1334 asf->packet_frag_offset = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1335 asf->packet_frag_size = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1336 asf->packet_frag_timestamp = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1337 asf->packet_multi_size = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1338 asf->packet_obj_size = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1339 asf->packet_time_delta = 0;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1340 asf->packet_time_start = 0;
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1341
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1342 for(i=0; i<s->nb_streams; i++){
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1343 asf_st= s->streams[i]->priv_data;
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1344 av_free_packet(&asf_st->pkt);
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1345 asf_st->frag_offset=0;
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1346 asf_st->seq=0;
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1347 }
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1348 asf->asf_st= NULL;
347
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1349 }
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1350
348
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
1351 static int64_t asf_read_pts(AVFormatContext *s, int64_t *ppos, int stream_index)
347
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1352 {
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1353 ASFContext *asf = s->priv_data;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1354 AVPacket pkt1, *pkt = &pkt1;
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1355 ASFStream *asf_st;
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1356 int64_t pts;
348
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
1357 int64_t pos= *ppos;
354
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1358 int i;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1359 int64_t start_pos[s->nb_streams];
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1360
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1361 for(i=0; i<s->nb_streams; i++){
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1362 start_pos[i]= pos;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1363 }
348
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
1364
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1365 //printf("asf_read_pts\n");
351
c072833fe7f4 use packet number instead of byte number internally for seeking
michael
parents: 350
diff changeset
1366 url_fseek(&s->pb, pos*asf->packet_size + s->data_offset, SEEK_SET);
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1367 asf_reset_header(s);
354
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1368 for(;;){
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1369 if (av_read_frame(s, pkt) < 0){
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1370 printf("seek failed\n");
348
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
1371 return AV_NOPTS_VALUE;
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1372 }
348
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
1373 pts= pkt->pts;
347
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1374
348
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
1375 av_free_packet(pkt);
354
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1376 if(pkt->flags&PKT_FLAG_KEY){
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1377 i= pkt->stream_index;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1378
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1379 asf_st= s->streams[i]->priv_data;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1380
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1381 assert((asf_st->packet_pos - s->data_offset) % asf->packet_size == 0);
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1382 pos= (asf_st->packet_pos - s->data_offset) / asf->packet_size;
351
c072833fe7f4 use packet number instead of byte number internally for seeking
michael
parents: 350
diff changeset
1383
354
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1384 av_add_index_entry(s->streams[i], pos, pts, pos - start_pos[i] + 1, AVINDEX_KEYFRAME);
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1385 start_pos[i]= pos + 1;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1386
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1387 if(pkt->stream_index == stream_index)
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1388 break;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1389 }
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1390 }
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1391
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1392 *ppos= pos;
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1393 //printf("found keyframe at %Ld stream %d stamp:%Ld\n", *ppos, stream_index, pts);
348
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
1394
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
1395 return pts;
347
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1396 }
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1397
312
8a04d2e1be2f frame rate should be completely disabled in asf (closer now) - disabled seek
bellard
parents: 300
diff changeset
1398 static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1399 {
312
8a04d2e1be2f frame rate should be completely disabled in asf (closer now) - disabled seek
bellard
parents: 300
diff changeset
1400 ASFContext *asf = s->priv_data;
354
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1401 AVStream *st;
347
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1402 int64_t pos;
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1403 int64_t pos_min, pos_max, pts_min, pts_max, cur_pts, pos_limit;
355
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1404 int no_change;
354
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1405
347
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1406 if (stream_index == -1)
348
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
1407 stream_index= av_find_default_stream_index(s);
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
1408
350
michael
parents: 349
diff changeset
1409 if (asf->packet_size <= 0)
347
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1410 return -1;
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1411
354
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1412 pts_max=
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1413 pts_min= AV_NOPTS_VALUE;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1414 pos_max= pos_limit= -1; // gcc thinks its uninitalized
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1415
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1416 st= s->streams[stream_index];
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1417 if(st->index_entries){
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1418 AVIndexEntry *e;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1419 int index;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1420
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1421 index= av_index_search_timestamp(st, pts);
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1422 e= &st->index_entries[index];
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1423 if(e->timestamp <= pts){
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1424 pos_min= e->pos;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1425 pts_min= e->timestamp;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1426 #ifdef DEBUG_SEEK
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1427 printf("unsing cached pos_min=0x%llx dts_min=%0.3f\n",
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1428 pos_min,pts_min / 90000.0);
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1429 #endif
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1430 }else{
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1431 assert(index==0);
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1432 }
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1433 index++;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1434 if(index < st->nb_index_entries){
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1435 e= &st->index_entries[index];
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1436 assert(e->timestamp >= pts);
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1437 pos_max= e->pos;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1438 pts_max= e->timestamp;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1439 pos_limit= pos_max - e->min_distance;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1440 #ifdef DEBUG_SEEK
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1441 printf("unsing cached pos_max=0x%llx dts_max=%0.3f\n",
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1442 pos_max,pts_max / 90000.0);
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1443 #endif
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1444 }
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1445 }
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1446
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1447 if(pts_min == AV_NOPTS_VALUE){
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1448 pos_min = 0;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1449 pts_min = asf_read_pts(s, &pos_min, stream_index);
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1450 if (pts_min == AV_NOPTS_VALUE) return -1;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1451 }
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1452 if(pts_max == AV_NOPTS_VALUE){
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1453 pos_max = (url_filesize(url_fileno(&s->pb)) - 1 - s->data_offset) / asf->packet_size; //FIXME wrong
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1454 pts_max = s->duration; //FIXME wrong
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1455 pos_limit= pos_max;
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1456 }
347
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1457
355
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1458 no_change=0;
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1459 while (pos_min < pos_limit) {
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1460 int64_t start_pos;
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1461 assert(pos_limit <= pos_max);
312
8a04d2e1be2f frame rate should be completely disabled in asf (closer now) - disabled seek
bellard
parents: 300
diff changeset
1462
355
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1463 if(no_change==0){
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1464 int64_t approximate_keyframe_distance= pos_max - pos_limit;
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1465 // interpolate position (better than dichotomy)
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1466 pos = (int64_t)((double)(pos_max - pos_min) *
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1467 (double)(pts - pts_min) /
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1468 (double)(pts_max - pts_min)) + pos_min - approximate_keyframe_distance;
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1469 }else if(no_change==1){
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1470 // bisection, if interpolation failed to change min or max pos last time
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1471 pos = (pos_min + pos_limit)>>1;
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1472 }else{
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1473 // linear search if bisection failed, can only happen if there are very few or no keyframes between min/max
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1474 pos=pos_min;
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1475 }
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1476 if(pos <= pos_min)
351
c072833fe7f4 use packet number instead of byte number internally for seeking
michael
parents: 350
diff changeset
1477 pos= pos_min + 1;
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1478 else if(pos > pos_limit)
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1479 pos= pos_limit;
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1480 start_pos= pos;
347
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1481
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1482 // read the next timestamp
348
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
1483 cur_pts = asf_read_pts(s, &pos, stream_index);
355
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1484 if(pos == pos_max)
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1485 no_change++;
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1486 else
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1487 no_change=0;
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1488
354
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1489 #ifdef DEBUG_SEEK
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1490 printf("%Ld %Ld %Ld / %Ld %Ld %Ld target:%Ld limit:%Ld start:%Ld\n", pos_min, pos, pos_max, pts_min, cur_pts, pts_max, pts, pos_limit, start_pos);
6770ca07abe2 store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents: 353
diff changeset
1491 #endif
355
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1492 assert (cur_pts != AV_NOPTS_VALUE);
46029c682234 seeking stuff
michael
parents: 354
diff changeset
1493 if (pts < cur_pts) {
351
c072833fe7f4 use packet number instead of byte number internally for seeking
michael
parents: 350
diff changeset
1494 pos_limit = start_pos - 1;
347
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1495 pos_max = pos;
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1496 pts_max = cur_pts;
347
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1497 } else {
349
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1498 pos_min = pos;
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1499 pts_min = cur_pts;
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1500 /* check if we are lucky */
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1501 if (pts == cur_pts)
2bed194f8362 seeking fixes
michael
parents: 348
diff changeset
1502 break;
347
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1503 }
312
8a04d2e1be2f frame rate should be completely disabled in asf (closer now) - disabled seek
bellard
parents: 300
diff changeset
1504 }
347
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1505 pos = pos_min;
351
c072833fe7f4 use packet number instead of byte number internally for seeking
michael
parents: 350
diff changeset
1506 url_fseek(&s->pb, pos*asf->packet_size + s->data_offset, SEEK_SET);
347
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1507 asf_reset_header(s);
2b485a3c5cfb seeking in single stream asf patch by ("Kevin Kuphal" <kevin dot kuphal at sitecity dot net>)
michael
parents: 341
diff changeset
1508 return 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1509 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1510
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1511 static AVInputFormat asf_iformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1512 "asf",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1513 "asf format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1514 sizeof(ASFContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1515 asf_probe,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1516 asf_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1517 asf_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1518 asf_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1519 asf_read_seek,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1520 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1521
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
1522 #ifdef CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1523 static AVOutputFormat asf_oformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1524 "asf",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1525 "asf format",
14
b167760cd0aa mimetype fixes patch by (Ryutaroh Matsumoto <ryutaroh at it dot ss dot titech dot ac dot jp>)
michaelni
parents: 7
diff changeset
1526 "video/x-ms-asf",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1527 "asf,wmv",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1528 sizeof(ASFContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1529 #ifdef CONFIG_MP3LAME
232
eb90c0a5a1ba CODEC_ID_MP3LAME is obsolete
bellard
parents: 196
diff changeset
1530 CODEC_ID_MP3,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1531 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1532 CODEC_ID_MP2,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1533 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1534 CODEC_ID_MSMPEG4V3,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1535 asf_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1536 asf_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1537 asf_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1538 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1539
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1540 static AVOutputFormat asf_stream_oformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1541 "asf_stream",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1542 "asf format",
14
b167760cd0aa mimetype fixes patch by (Ryutaroh Matsumoto <ryutaroh at it dot ss dot titech dot ac dot jp>)
michaelni
parents: 7
diff changeset
1543 "video/x-ms-asf",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1544 "asf,wmv",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1545 sizeof(ASFContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1546 #ifdef CONFIG_MP3LAME
232
eb90c0a5a1ba CODEC_ID_MP3LAME is obsolete
bellard
parents: 196
diff changeset
1547 CODEC_ID_MP3,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1548 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1549 CODEC_ID_MP2,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1550 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1551 CODEC_ID_MSMPEG4V3,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1552 asf_write_stream_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1553 asf_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1554 asf_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1555 };
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
1556 #endif //CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1557
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1558 int asf_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1559 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1560 av_register_input_format(&asf_iformat);
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
1561 #ifdef CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1562 av_register_output_format(&asf_oformat);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1563 av_register_output_format(&asf_stream_oformat);
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
1564 #endif //CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1565 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1566 }