annotate asf.c @ 268:ff7fb0eb0828 libavformat

the correct data type is offset_t
author tmmm
date Thu, 02 Oct 2003 03:53:52 +0000
parents 3d92f793fd67
children a313e1080322
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 #define PACKET_SIZE 3200
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 #define PACKET_HEADER_SIZE 12
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 #define FRAME_HEADER_SIZE 17
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 typedef struct {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 int num;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 int seq;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 /* use for reading */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 AVPacket pkt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 int frag_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 int timestamp;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
34 int64_t duration;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 int ds_span; /* descrambling */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 int ds_packet_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 int ds_chunk_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 int ds_data_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 int ds_silence_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 } ASFStream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 typedef struct {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
45 uint32_t v1;
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
46 uint16_t v2;
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
47 uint16_t v3;
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
48 uint8_t v4[8];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 } GUID;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50
188
6c9d6422a2f6 update duration and start_time - add av_new_stream() usage
bellard
parents: 136
diff changeset
51 typedef struct {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 GUID guid; // generated by client computer
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 uint64_t file_size; // in bytes
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 // invalid if broadcasting
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 uint64_t create_time; // time of creation, in 100-nanosecond units since 1.1.1601
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 // invalid if broadcasting
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 uint64_t packets_count; // how many packets are there in the file
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 // invalid if broadcasting
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 uint64_t play_time; // play time, in 100-nanosecond units
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 // invalid if broadcasting
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 uint64_t send_time; // time to send file, in 100-nanosecond units
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 // invalid if broadcasting (could be ignored)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 uint32_t preroll; // timestamp of the first packet, in milliseconds
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 // if nonzero - substract from time
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 uint32_t ignore; // preroll is 64bit - but let's just ignore it
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 uint32_t flags; // 0x01 - broadcast
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 // 0x02 - seekable
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 // rest is reserved should be 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 uint32_t min_pktsize; // size of a data packet
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 // invalid if broadcasting
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 uint32_t max_pktsize; // shall be the same as for min_pktsize
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 // invalid if broadcasting
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 uint32_t max_bitrate; // bandwith of stream in bps
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 // should be the sum of bitrates of the
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 // individual media streams
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 } ASFMainHeader;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 typedef struct {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 int seqno;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 int packet_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 int is_streamed;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 int asfid2avid[128]; /* conversion table from asf ID 2 AVStream ID */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 ASFStream streams[128]; /* it's max number and it's not that big */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 /* non streamed additonnal info */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
86 int64_t nb_packets;
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
87 int64_t duration; /* in 100ns units */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 /* packet filling */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 int packet_size_left;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 int packet_timestamp_start;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 int packet_timestamp_end;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 int packet_nb_frames;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
93 uint8_t packet_buf[PACKET_SIZE];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 ByteIOContext pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 /* only for reading */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 uint64_t data_offset; /* begining of the first data packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 ASFMainHeader hdr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 int packet_flags;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 int packet_property;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 int packet_timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 int packet_segsizetype;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 int packet_segments;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 int packet_seq;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 int packet_replic_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 int packet_key_frame;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 int packet_padsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 int packet_frag_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 int packet_frag_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 int packet_frag_timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 int packet_multi_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 int packet_obj_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 int packet_time_delta;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 int packet_time_start;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 int stream_index;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 ASFStream* asf_st; /* currently decoded stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 } ASFContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 static const GUID asf_header = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 0x75B22630, 0x668E, 0x11CF, { 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 static const GUID file_header = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 0x8CABDCA1, 0xA947, 0x11CF, { 0x8E, 0xE4, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 static const GUID stream_header = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 0xB7DC0791, 0xA9B7, 0x11CF, { 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 static const GUID audio_stream = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 0xF8699E40, 0x5B4D, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 static const GUID audio_conceal_none = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 // 0x49f1a440, 0x4ece, 0x11d0, { 0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 // New value lifted from avifile
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 0x20fb5700, 0x5b55, 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 video_stream = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 0xBC19EFC0, 0x5B4D, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 static const GUID video_conceal_none = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 0x20FB5700, 0x5B55, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152 static const GUID comment_header = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 0x75b22633, 0x668e, 0x11cf, { 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 static const GUID codec_comment_header = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157 0x86D15240, 0x311D, 0x11D0, { 0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 static const GUID codec_comment1_header = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 0x86d15241, 0x311d, 0x11d0, { 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 static const GUID data_header = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 0x75b22636, 0x668e, 0x11cf, { 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 static const GUID index_guid = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 0x33000890, 0xe5b1, 0x11cf, { 0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 static const GUID head1_guid = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 0x5fbf03b5, 0xa92e, 0x11cf, { 0x8e, 0xe3, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 static const GUID head2_guid = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 0xabd3d211, 0xa9ba, 0x11cf, { 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 /* 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
180 generate the stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181 static const GUID my_guid = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 static void put_guid(ByteIOContext *s, const GUID *g)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 put_le32(s, g->v1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 put_le16(s, g->v2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 put_le16(s, g->v3);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 for(i=0;i<8;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 put_byte(s, g->v4[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 static void put_str16(ByteIOContext *s, const char *tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 int c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 put_le16(s,strlen(tag) + 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 for(;;) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
202 c = (uint8_t)*tag++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 put_le16(s, c);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 if (c == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 static void put_str16_nolen(ByteIOContext *s, const char *tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 int c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 for(;;) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
214 c = (uint8_t)*tag++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 put_le16(s, c);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 if (c == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 break;
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
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
221 static int64_t put_header(ByteIOContext *pb, const GUID *g)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
223 int64_t pos;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 put_guid(pb, g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 put_le64(pb, 24);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 return pos;
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 /* update header size */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
232 static void end_header(ByteIOContext *pb, int64_t pos)
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 pos1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 pos1 = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 url_fseek(pb, pos + 16, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 put_le64(pb, pos1 - pos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 url_fseek(pb, pos1, SEEK_SET);
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 /* write an asf chunk (only used in streaming case) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 int length;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 length = payload_length + 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 put_le16(pb, type);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 put_le16(pb, length);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 put_le32(pb, asf->seqno);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 put_le16(pb, flags); /* unknown bytes */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 put_le16(pb, length);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 asf->seqno++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 /* convert from unix to windows time */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
259 static int64_t unix_to_file_time(int ti)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
261 int64_t t;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
263 t = ti * int64_t_C(10000000);
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
264 t += int64_t_C(116444736000000000);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 return t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
268 /* write the header (used two times if non streamed) */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
269 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
270 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273 int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 int has_title;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275 AVCodecContext *enc;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
276 int64_t header_offset, cur_pos, hpos;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 int bit_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279 has_title = (s->title[0] || s->author[0] || s->copyright[0] || s->comment[0]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281 bit_rate = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282 for(n=0;n<s->nb_streams;n++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283 enc = &s->streams[n]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285 bit_rate += enc->bit_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289 put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292 put_guid(pb, &asf_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293 put_le64(pb, -1); /* header length, will be patched after */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 put_le32(pb, 3 + has_title + s->nb_streams); /* number of chunks in header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295 put_byte(pb, 1); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
296 put_byte(pb, 2); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
297
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
298 /* file header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
299 header_offset = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300 hpos = put_header(pb, &file_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301 put_guid(pb, &my_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
302 put_le64(pb, file_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303 file_time = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
304 put_le64(pb, unix_to_file_time(file_time));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
305 put_le64(pb, asf->nb_packets); /* number of packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306 put_le64(pb, asf->duration); /* end time stamp (in 100ns units) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307 put_le64(pb, asf->duration); /* duration (in 100ns units) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
308 put_le32(pb, 0); /* start time stamp */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309 put_le32(pb, 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310 put_le32(pb, asf->is_streamed ? 1 : 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
311 put_le32(pb, asf->packet_size); /* packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
312 put_le32(pb, asf->packet_size); /* packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
313 put_le32(pb, bit_rate); /* Nominal data rate in bps */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
314 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316 /* unknown headers */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
317 hpos = put_header(pb, &head1_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318 put_guid(pb, &head2_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
319 put_le32(pb, 6);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
320 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
321 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
322
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
323 /* title and other infos */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
324 if (has_title) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
325 hpos = put_header(pb, &comment_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326 put_le16(pb, 2 * (strlen(s->title) + 1));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 put_le16(pb, 2 * (strlen(s->author) + 1));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328 put_le16(pb, 2 * (strlen(s->copyright) + 1));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
329 put_le16(pb, 2 * (strlen(s->comment) + 1));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331 put_str16_nolen(pb, s->title);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332 put_str16_nolen(pb, s->author);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333 put_str16_nolen(pb, s->copyright);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334 put_str16_nolen(pb, s->comment);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
336 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 /* stream headers */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339 for(n=0;n<s->nb_streams;n++) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
340 int64_t es_pos;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
341 // ASFStream *stream = &asf->streams[n];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343 enc = &s->streams[n]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
344 asf->streams[n].num = n + 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
345 asf->streams[n].seq = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
346
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347 switch(enc->codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349 wav_extra_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350 extra_size = 18 + wav_extra_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351 extra_size2 = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
353 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
354 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
355 wav_extra_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356 extra_size = 0x33;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357 extra_size2 = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
358 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361 hpos = put_header(pb, &stream_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
362 if (enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363 put_guid(pb, &audio_stream);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364 put_guid(pb, &audio_conceal_none);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
365 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
366 put_guid(pb, &video_stream);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
367 put_guid(pb, &video_conceal_none);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
368 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
369 put_le64(pb, 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
370 es_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
371 put_le32(pb, extra_size); /* wav header len */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
372 put_le32(pb, extra_size2); /* additional data len */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
373 put_le16(pb, n + 1); /* stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
374 put_le32(pb, 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 if (enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
377 /* WAVEFORMATEX header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
378 int wavsize = put_wav_header(pb, enc);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
379
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
380 if (wavsize < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
381 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
382 if (wavsize != extra_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
383 cur_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
384 url_fseek(pb, es_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
385 put_le32(pb, wavsize); /* wav header len */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
386 url_fseek(pb, cur_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
387 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
388 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
389 put_le32(pb, enc->width);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
390 put_le32(pb, enc->height);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
391 put_byte(pb, 2); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392 put_le16(pb, 40); /* size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
393
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 /* BITMAPINFOHEADER header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395 put_bmp_header(pb, enc, codec_bmp_tags, 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
397 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
398 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
400 /* media comments */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
401
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
402 hpos = put_header(pb, &codec_comment_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403 put_guid(pb, &codec_comment1_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404 put_le32(pb, s->nb_streams);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405 for(n=0;n<s->nb_streams;n++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
406 AVCodec *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
407
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
408 enc = &s->streams[n]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
409 p = avcodec_find_encoder(enc->codec_id);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
411 put_le16(pb, asf->streams[n].num);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412 put_str16(pb, p ? p->name : enc->codec_name);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 put_le16(pb, 0); /* no parameters */
196
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
414
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
415
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 /* id */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 if (enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 put_le16(pb, 2);
196
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
419 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
420 enc->codec_tag = codec_get_tag(codec_wav_tags, enc->codec_id);
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
421 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
422 return -1;
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
423 put_le16(pb, enc->codec_tag);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
425 put_le16(pb, 4);
196
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
426 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
427 enc->codec_tag = codec_get_tag(codec_bmp_tags, enc->codec_id);
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
428 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
429 return -1;
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
430 put_le32(pb, enc->codec_tag);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
431 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
433 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
434
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435 /* patch the header size fields */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 cur_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 header_size = cur_pos - header_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 header_size += 8 + 30 + 50;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 url_fseek(pb, header_offset - 10 - 30, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 put_le16(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 url_fseek(pb, header_offset - 2 - 30, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445 put_le16(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447 header_size -= 8 + 30 + 50;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449 header_size += 24 + 6;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450 url_fseek(pb, header_offset - 14, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451 put_le64(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452 url_fseek(pb, cur_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
454 /* movie chunk, followed by packets of packet_size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455 asf->data_offset = cur_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
456 put_guid(pb, &data_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
457 put_le64(pb, data_chunk_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
458 put_guid(pb, &my_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459 put_le64(pb, asf->nb_packets); /* nb packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
460 put_byte(pb, 1); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461 put_byte(pb, 1); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
462 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
464
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
465 static int asf_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
466 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469 av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
471 asf->packet_size = PACKET_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472 asf->nb_packets = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
473
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
474 if (asf_write_header1(s, 0, 50) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
475 //av_free(asf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
476 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
477 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
478
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
479 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
480
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
481 asf->packet_nb_frames = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
482 asf->packet_timestamp_start = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
483 asf->packet_timestamp_end = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
484 asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
485 init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
486 NULL, NULL, NULL, NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
487
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
488 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
489 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
490
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
491 static int asf_write_stream_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
492 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
493 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
494
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
495 asf->is_streamed = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
496
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
497 return asf_write_header(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
498 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
499
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
500 /* write a fixed size packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
501 static int put_packet(AVFormatContext *s,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
502 unsigned int timestamp, unsigned int duration,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
503 int nb_frames, int padsize)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
504 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
505 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
506 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
507 int flags;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
508
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
509 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
510 put_chunk(s, 0x4424, asf->packet_size, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
511 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
512
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
513 put_byte(pb, 0x82);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
514 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
515
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
516 flags = 0x01; /* nb segments present */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
517 if (padsize > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
518 if (padsize < 256)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
519 flags |= 0x08;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
520 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
521 flags |= 0x10;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
522 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
523 put_byte(pb, flags); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
524 put_byte(pb, 0x5d);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
525 if (flags & 0x10)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
526 put_le16(pb, padsize - 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
527 if (flags & 0x08)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
528 put_byte(pb, padsize - 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
529 put_le32(pb, timestamp);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
530 put_le16(pb, duration);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
531 put_byte(pb, nb_frames | 0x80);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
532
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
533 return PACKET_HEADER_SIZE + ((flags & 0x18) >> 3);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
534 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
535
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
536 static void flush_packet(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
537 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
538 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
539 int hdr_size, ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
540
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
541 hdr_size = put_packet(s, asf->packet_timestamp_start,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
542 asf->packet_timestamp_end - asf->packet_timestamp_start,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
543 asf->packet_nb_frames, asf->packet_size_left);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
544
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
545 /* Clear out the padding bytes */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
546 ptr = asf->packet_size - hdr_size - asf->packet_size_left;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
547 memset(asf->packet_buf + ptr, 0, asf->packet_size_left);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
548
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
549 put_buffer(&s->pb, asf->packet_buf, asf->packet_size - hdr_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
550
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
551 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
552 asf->nb_packets++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
553 asf->packet_nb_frames = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
554 asf->packet_timestamp_start = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
555 asf->packet_timestamp_end = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
556 asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
557 init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
558 NULL, NULL, NULL, NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
559 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
560
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
561 static void put_frame_header(AVFormatContext *s, ASFStream *stream, int timestamp,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
562 int payload_size, int frag_offset, int frag_len)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
563 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
564 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
565 ByteIOContext *pb = &asf->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
566 int val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
567
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
568 val = stream->num;
7
47e502ac6349 AVVideoFrame -> AVFrame
michaelni
parents: 5
diff changeset
569 if (s->streams[val - 1]->codec.coded_frame->key_frame /* && frag_offset == 0 */)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
570 val |= 0x80;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
571 put_byte(pb, val);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
572 put_byte(pb, stream->seq);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
573 put_le32(pb, frag_offset); /* fragment offset */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
574 put_byte(pb, 0x08); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
575 put_le32(pb, payload_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
576 put_le32(pb, timestamp);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
577 put_le16(pb, frag_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
578 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
579
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
580
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
581 /* Output a frame. We suppose that payload_size <= PACKET_SIZE.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
582
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
583 It is there that you understand that the ASF format is really
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
584 crap. They have misread the MPEG Systems spec !
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
585 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
586 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
587 const uint8_t *buf, int payload_size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
588 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
589 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
590 int frag_pos, frag_len, frag_len1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
591
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
592 frag_pos = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
593 while (frag_pos < payload_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
594 frag_len = payload_size - frag_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
595 frag_len1 = asf->packet_size_left - FRAME_HEADER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
596 if (frag_len1 > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
597 if (frag_len > frag_len1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
598 frag_len = frag_len1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
599 put_frame_header(s, stream, timestamp+1, payload_size, frag_pos, frag_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
600 put_buffer(&asf->pb, buf, frag_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
601 asf->packet_size_left -= (frag_len + FRAME_HEADER_SIZE);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
602 asf->packet_timestamp_end = timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
603 if (asf->packet_timestamp_start == -1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
604 asf->packet_timestamp_start = timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
605 asf->packet_nb_frames++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
606 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
607 frag_len = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
608 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
609 frag_pos += frag_len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
610 buf += frag_len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
611 /* output the frame if filled */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
612 if (asf->packet_size_left <= FRAME_HEADER_SIZE)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
613 flush_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
614 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
615 stream->seq++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
616 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
617
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
618
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
619 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
620 const uint8_t *buf, int size, int64_t timestamp)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
621 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
622 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
623 ASFStream *stream;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
624 int64_t duration;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
625 AVCodecContext *codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
626
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
627 codec = &s->streams[stream_index]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
628 stream = &asf->streams[stream_index];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
629
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
630 if (codec->codec_type == CODEC_TYPE_AUDIO) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
631 duration = (codec->frame_number * codec->frame_size * int64_t_C(10000000)) /
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
632 codec->sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
633 } else {
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 84
diff changeset
634 duration = av_rescale(codec->frame_number * codec->frame_rate_base, 10000000, codec->frame_rate);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
635 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
636 if (duration > asf->duration)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
637 asf->duration = duration;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
638
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
639 put_frame(s, stream, timestamp, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
640 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
641 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
642
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
643 static int asf_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
644 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
645 ASFContext *asf = s->priv_data;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
646 int64_t file_size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
647
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
648 /* flush the current packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
649 if (asf->pb.buf_ptr > asf->pb.buffer)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
650 flush_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
651
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
652 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
653 put_chunk(s, 0x4524, 0, 0); /* end of stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
654 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
655 /* rewrite an updated header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
656 file_size = url_ftell(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
657 url_fseek(&s->pb, 0, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
658 asf_write_header1(s, file_size, file_size - asf->data_offset);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
659 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
660
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
661 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
662 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
663 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
664
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
665 /**********************************/
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
666 /* decoding */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
667
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
668 //#define DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
669
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
670 #ifdef DEBUG
69
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
671 #define PRINT_IF_GUID(g,cmp) \
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
672 if (!memcmp(g, &cmp, sizeof(GUID))) \
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
673 printf("(GUID: %s) ", #cmp)
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
674
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
675 static void print_guid(const GUID *g)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
676 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
677 int i;
69
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
678 PRINT_IF_GUID(g, asf_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
679 else PRINT_IF_GUID(g, file_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
680 else PRINT_IF_GUID(g, stream_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
681 else PRINT_IF_GUID(g, audio_stream);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
682 else PRINT_IF_GUID(g, audio_conceal_none);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
683 else PRINT_IF_GUID(g, video_stream);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
684 else PRINT_IF_GUID(g, video_conceal_none);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
685 else PRINT_IF_GUID(g, comment_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
686 else PRINT_IF_GUID(g, codec_comment_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
687 else PRINT_IF_GUID(g, codec_comment1_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
688 else PRINT_IF_GUID(g, data_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
689 else PRINT_IF_GUID(g, index_guid);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
690 else PRINT_IF_GUID(g, head1_guid);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
691 else PRINT_IF_GUID(g, head2_guid);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
692 else PRINT_IF_GUID(g, my_guid);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
693 else
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
694 printf("(GUID: unknown) ");
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
695 printf("0x%08x, 0x%04x, 0x%04x, {", g->v1, g->v2, g->v3);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
696 for(i=0;i<8;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
697 printf(" 0x%02x,", g->v4[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
698 printf("}\n");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
699 }
69
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
700 #undef PRINT_IF_GUID(g,cmp)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
701 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
702
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
703 static void get_guid(ByteIOContext *s, GUID *g)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
704 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
705 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
706
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
707 g->v1 = get_le32(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
708 g->v2 = get_le16(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
709 g->v3 = get_le16(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
710 for(i=0;i<8;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
711 g->v4[i] = get_byte(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
712 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
713
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
714 #if 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
715 static void get_str16(ByteIOContext *pb, char *buf, int buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
716 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
717 int len, c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
718 char *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
719
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
720 len = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
721 q = buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
722 while (len > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
723 c = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
724 if ((q - buf) < buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
725 *q++ = c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
726 len--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
727 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
728 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
729 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
730 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
731
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
732 static void get_str16_nolen(ByteIOContext *pb, int len, char *buf, int buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
733 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
734 int c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
735 char *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
736
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
737 q = buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
738 while (len > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
739 c = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
740 if ((q - buf) < buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
741 *q++ = c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
742 len-=2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
743 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
744 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
745 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
746
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
747 static int asf_probe(AVProbeData *pd)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
748 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
749 GUID g;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
750 const unsigned char *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
751 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
752
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
753 /* check file header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
754 if (pd->buf_size <= 32)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
755 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
756 p = pd->buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
757 g.v1 = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
758 p += 4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
759 g.v2 = p[0] | (p[1] << 8);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
760 p += 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
761 g.v3 = p[0] | (p[1] << 8);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
762 p += 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
763 for(i=0;i<8;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
764 g.v4[i] = *p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
765
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
766 if (!memcmp(&g, &asf_header, sizeof(GUID)))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
767 return AVPROBE_SCORE_MAX;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
768 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
769 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
770 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
771
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
772 static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
773 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
774 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
775 GUID g;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
776 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
777 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
778 ASFStream *asf_st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
779 int size, i;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
780 int64_t gsize;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
781
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
782 av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
783
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
784 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
785 if (memcmp(&g, &asf_header, sizeof(GUID)))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
786 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
787 get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
788 get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
789 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
790 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
791 memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
792 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
793 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
794 gsize = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
795 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
796 printf("%08Lx: ", url_ftell(pb) - 24);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
797 print_guid(&g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
798 printf(" size=0x%Lx\n", gsize);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
799 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
800 if (gsize < 24)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
801 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
802 if (!memcmp(&g, &file_header, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
803 get_guid(pb, &asf->hdr.guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
804 asf->hdr.file_size = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
805 asf->hdr.create_time = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
806 asf->hdr.packets_count = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
807 asf->hdr.play_time = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
808 asf->hdr.send_time = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
809 asf->hdr.preroll = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
810 asf->hdr.ignore = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
811 asf->hdr.flags = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
812 asf->hdr.min_pktsize = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
813 asf->hdr.max_pktsize = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
814 asf->hdr.max_bitrate = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
815 asf->packet_size = asf->hdr.max_pktsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
816 asf->nb_packets = asf->hdr.packets_count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
817 } 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
818 int type, total_size, type_specific_size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
819 unsigned int tag1;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
820 int64_t pos1, pos2;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
821
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
822 pos1 = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
823
188
6c9d6422a2f6 update duration and start_time - add av_new_stream() usage
bellard
parents: 136
diff changeset
824 st = av_new_stream(s, 0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
825 if (!st)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
826 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
827 asf_st = av_mallocz(sizeof(ASFStream));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
828 if (!asf_st)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
829 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
830 st->priv_data = asf_st;
188
6c9d6422a2f6 update duration and start_time - add av_new_stream() usage
bellard
parents: 136
diff changeset
831 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
832 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
833 (10000000 / AV_TIME_BASE);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
834 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
835 if (!memcmp(&g, &audio_stream, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
836 type = CODEC_TYPE_AUDIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
837 } else if (!memcmp(&g, &video_stream, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
838 type = CODEC_TYPE_VIDEO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
839 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
840 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
841 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
842 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
843 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
844 type_specific_size = get_le32(pb);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
845 get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
846 st->id = get_le16(pb) & 0x7f; /* stream id */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
847 // 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
848 asf->asfid2avid[st->id] = s->nb_streams - 1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
849
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
850 get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
851 st->codec.codec_type = type;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
852 st->codec.frame_rate = 15 * s->pts_den / s->pts_num; // 15 fps default
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
853 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
854 get_wav_header(pb, &st->codec, type_specific_size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
855 /* We have to init the frame size at some point .... */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
856 pos2 = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
857 if (gsize > (pos2 + 8 - pos1 + 24)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
858 asf_st->ds_span = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
859 asf_st->ds_packet_size = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
860 asf_st->ds_chunk_size = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
861 asf_st->ds_data_size = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
862 asf_st->ds_silence_data = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
863 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
864 //printf("Descrambling: ps:%d cs:%d ds:%d s:%d sd:%d\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
865 // asf_st->ds_packet_size, asf_st->ds_chunk_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
866 // asf_st->ds_data_size, asf_st->ds_span, asf_st->ds_silence_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
867 if (asf_st->ds_span > 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
868 if (!asf_st->ds_chunk_size
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
869 || (asf_st->ds_packet_size/asf_st->ds_chunk_size <= 1))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
870 asf_st->ds_span = 0; // disable descrambling
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
871 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
872 switch (st->codec.codec_id) {
232
eb90c0a5a1ba CODEC_ID_MP3LAME is obsolete
bellard
parents: 196
diff changeset
873 case CODEC_ID_MP3:
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
874 st->codec.frame_size = MPA_FRAME_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
875 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
876 case CODEC_ID_PCM_S16LE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
877 case CODEC_ID_PCM_S16BE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
878 case CODEC_ID_PCM_U16LE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
879 case CODEC_ID_PCM_U16BE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
880 case CODEC_ID_PCM_S8:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
881 case CODEC_ID_PCM_U8:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
882 case CODEC_ID_PCM_ALAW:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
883 case CODEC_ID_PCM_MULAW:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
884 st->codec.frame_size = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
885 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
886 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
887 /* This is probably wrong, but it prevents a crash later */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
888 st->codec.frame_size = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
889 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
890 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
891 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
892 get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
893 get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
894 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
895 size = get_le16(pb); /* size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
896 get_le32(pb); /* size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
897 st->codec.width = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
898 st->codec.height = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
899 /* not available for asf */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
900 get_le16(pb); /* panes */
117
497ae2790081 * filling bitdepth
kabi
parents: 85
diff changeset
901 st->codec.bits_per_sample = get_le16(pb); /* depth */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
902 tag1 = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
903 url_fskip(pb, 20);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
904 if (size > 40) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
905 st->codec.extradata_size = size - 40;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
906 st->codec.extradata = av_mallocz(st->codec.extradata_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
907 get_buffer(pb, st->codec.extradata, st->codec.extradata_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
908 }
74
4b501fe1539c merging fourcc with codec_tag
michaelni
parents: 69
diff changeset
909 st->codec.codec_tag = tag1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
910 st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
911 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
912 pos2 = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
913 url_fskip(pb, gsize - (pos2 - pos1 + 24));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
914 } else if (!memcmp(&g, &data_header, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
915 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
916 } else if (!memcmp(&g, &comment_header, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
917 int len1, len2, len3, len4, len5;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
918
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
919 len1 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
920 len2 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
921 len3 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
922 len4 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
923 len5 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
924 get_str16_nolen(pb, len1, s->title, sizeof(s->title));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
925 get_str16_nolen(pb, len2, s->author, sizeof(s->author));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
926 get_str16_nolen(pb, len3, s->copyright, sizeof(s->copyright));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
927 get_str16_nolen(pb, len4, s->comment, sizeof(s->comment));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
928 url_fskip(pb, len5);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
929 #if 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
930 } else if (!memcmp(&g, &head1_guid, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
931 int v1, v2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
932 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
933 v1 = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
934 v2 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
935 } else if (!memcmp(&g, &codec_comment_header, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
936 int len, v1, n, num;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
937 char str[256], *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
938 char tag[16];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
939
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
940 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
941 print_guid(&g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
942
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
943 n = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
944 for(i=0;i<n;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
945 num = get_le16(pb); /* stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
946 get_str16(pb, str, sizeof(str));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
947 get_str16(pb, str, sizeof(str));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
948 len = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
949 q = tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
950 while (len > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
951 v1 = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
952 if ((q - tag) < sizeof(tag) - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
953 *q++ = v1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
954 len--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
955 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
956 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
957 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
958 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
959 } else if (url_feof(pb)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
960 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
961 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
962 url_fseek(pb, gsize - 24, SEEK_CUR);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
963 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
964 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
965 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
966 get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
967 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
968 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
969 if (url_feof(pb))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
970 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
971 asf->data_offset = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
972 asf->packet_size_left = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
973
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
974 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
975
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
976 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
977 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
978 AVStream *st = s->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
979 if (st) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
980 av_free(st->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
981 av_free(st->codec.extradata);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
982 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
983 av_free(st);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
984 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
985 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
986 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
987
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
988 #define DO_2BITS(bits, var, defval) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
989 switch (bits & 3) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
990 { \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
991 case 3: var = get_le32(pb); rsize += 4; break; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
992 case 2: var = get_le16(pb); rsize += 2; break; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
993 case 1: var = get_byte(pb); rsize++; break; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
994 default: var = defval; break; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
995 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
996
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
997 static int asf_get_packet(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
998 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
999 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1000 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1001 uint32_t packet_length, padsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1002 int rsize = 11;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1003 int c = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1004 if (c != 0x82) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1005 if (!url_feof(pb))
136
6b74809d2496 Warning and compatibility fixes.
mellum
parents: 117
diff changeset
1006 printf("ff asf bad header %x at:%lld\n", c, url_ftell(pb));
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1007 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1008 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1009 if ((c & 0x0f) == 2) { // always true for now
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1010 if (get_le16(pb) != 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1011 if (!url_feof(pb))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1012 printf("ff asf bad non zero\n");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1013 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1014 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1015 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1016
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1017 asf->packet_flags = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1018 asf->packet_property = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1019
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1020 DO_2BITS(asf->packet_flags >> 5, packet_length, asf->packet_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1021 DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence ignored
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1022 DO_2BITS(asf->packet_flags >> 3, padsize, 0); // padding length
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1023
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1024 asf->packet_timestamp = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1025 get_le16(pb); /* duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1026 // rsize has at least 11 bytes which have to be present
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1027
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1028 if (asf->packet_flags & 0x01) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1029 asf->packet_segsizetype = get_byte(pb); rsize++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1030 asf->packet_segments = asf->packet_segsizetype & 0x3f;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1031 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1032 asf->packet_segments = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1033 asf->packet_segsizetype = 0x80;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1034 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1035 asf->packet_size_left = packet_length - padsize - rsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1036 if (packet_length < asf->hdr.min_pktsize)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1037 padsize += asf->hdr.min_pktsize - packet_length;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1038 asf->packet_padsize = padsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1039 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1040 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
1041 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1042 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1043 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1044
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1045 static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1046 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1047 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1048 ASFStream *asf_st = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1049 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1050 //static int pc = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1051 for (;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1052 int rsize = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1053 if (asf->packet_size_left < FRAME_HEADER_SIZE
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1054 || asf->packet_segments < 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1055 //asf->packet_size_left <= asf->packet_padsize) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1056 int ret = asf->packet_size_left + asf->packet_padsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1057 //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
1058 /* fail safe */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1059 url_fskip(pb, ret);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1060 ret = asf_get_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1061 //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
1062 if (ret < 0 || url_feof(pb))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1063 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1064 asf->packet_time_start = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1065 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1066 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1067 if (asf->packet_time_start == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1068 /* read frame header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1069 int num = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1070 asf->packet_segments--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1071 rsize++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1072 asf->packet_key_frame = (num & 0x80) >> 7;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1073 asf->stream_index = asf->asfid2avid[num & 0x7f];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1074 // sequence should be ignored!
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1075 DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1076 DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1077 DO_2BITS(asf->packet_property, asf->packet_replic_size, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1078
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1079 if (asf->packet_replic_size > 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1080 // it should be always at least 8 bytes - FIXME validate
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1081 asf->packet_obj_size = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1082 asf->packet_frag_timestamp = get_le32(pb); // timestamp
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1083 if (asf->packet_replic_size > 8)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1084 url_fskip(pb, asf->packet_replic_size - 8);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1085 rsize += asf->packet_replic_size; // FIXME - check validity
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1086 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1087 // multipacket - frag_offset is begining timestamp
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1088 asf->packet_time_start = asf->packet_frag_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1089 asf->packet_frag_offset = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1090 asf->packet_frag_timestamp = asf->packet_timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1091
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1092 if (asf->packet_replic_size == 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1093 asf->packet_time_delta = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1094 rsize++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1095 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1096 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1097 if (asf->packet_flags & 0x01) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1098 DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1099 #undef DO_2BITS
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1100 //printf("Fragsize %d\n", asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1101 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1102 asf->packet_frag_size = asf->packet_size_left - rsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1103 //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
1104 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1105 if (asf->packet_replic_size == 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1106 asf->packet_multi_size = asf->packet_frag_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1107 if (asf->packet_multi_size > asf->packet_size_left) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1108 asf->packet_segments = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1109 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1110 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1111 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1112 asf->packet_size_left -= rsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1113 //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
1114
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1115 if (asf->stream_index < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1116 asf->packet_time_start = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1117 /* unhandled packet (should not happen) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1118 url_fskip(pb, asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1119 asf->packet_size_left -= asf->packet_frag_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1120 printf("ff asf skip %d %d\n", asf->packet_frag_size, num & 0x7f);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1121 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1122 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1123 asf->asf_st = s->streams[asf->stream_index]->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1124 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1125 asf_st = asf->asf_st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1126
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1127 if ((asf->packet_frag_offset != asf_st->frag_offset
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1128 || (asf->packet_frag_offset
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1129 && asf->packet_seq != asf_st->seq)) // seq should be ignored
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1130 ) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1131 /* cannot continue current packet: free it */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1132 // FIXME better check if packet was already allocated
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1133 printf("ff asf parser skips: %d - %d o:%d - %d %d %d fl:%d\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1134 asf_st->pkt.size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1135 asf->packet_obj_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1136 asf->packet_frag_offset, asf_st->frag_offset,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1137 asf->packet_seq, asf_st->seq, asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1138 if (asf_st->pkt.size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1139 av_free_packet(&asf_st->pkt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1140 asf_st->frag_offset = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1141 if (asf->packet_frag_offset != 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1142 url_fskip(pb, asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1143 printf("ff asf parser skiping %db\n", asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1144 asf->packet_size_left -= asf->packet_frag_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1145 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1146 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1147 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1148 if (asf->packet_replic_size == 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1149 // frag_offset is here used as the begining timestamp
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1150 asf->packet_frag_timestamp = asf->packet_time_start;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1151 asf->packet_time_start += asf->packet_time_delta;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1152 asf->packet_obj_size = asf->packet_frag_size = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1153 asf->packet_size_left--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1154 asf->packet_multi_size--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1155 if (asf->packet_multi_size < asf->packet_obj_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1156 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1157 asf->packet_time_start = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1158 url_fskip(pb, asf->packet_multi_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1159 asf->packet_size_left -= asf->packet_multi_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1160 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1161 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1162 asf->packet_multi_size -= asf->packet_obj_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1163 //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
1164 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1165 if (asf_st->frag_offset == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1166 /* new packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1167 av_new_packet(&asf_st->pkt, asf->packet_obj_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1168 asf_st->seq = asf->packet_seq;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1169 asf_st->pkt.pts = asf->packet_frag_timestamp - asf->hdr.preroll;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1170 asf_st->pkt.stream_index = asf->stream_index;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1171 if (asf->packet_key_frame)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1172 asf_st->pkt.flags |= PKT_FLAG_KEY;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1173 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1174
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1175 /* read data */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1176 //printf("READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1177 // asf->packet_size, asf_st->pkt.size, asf->packet_frag_offset,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1178 // asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1179 asf->packet_size_left -= asf->packet_frag_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1180 if (asf->packet_size_left < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1181 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1182 get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1183 asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1184 asf_st->frag_offset += asf->packet_frag_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1185 /* test if whole packet is read */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1186 if (asf_st->frag_offset == asf_st->pkt.size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1187 /* return packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1188 if (asf_st->ds_span > 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1189 /* packet descrambling */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1190 char* newdata = av_malloc(asf_st->pkt.size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1191 if (newdata) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1192 int offset = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1193 while (offset < asf_st->pkt.size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1194 int off = offset / asf_st->ds_chunk_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1195 int row = off / asf_st->ds_span;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1196 int col = off % asf_st->ds_span;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1197 int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1198 //printf("off:%d row:%d col:%d idx:%d\n", off, row, col, idx);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1199 memcpy(newdata + offset,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1200 asf_st->pkt.data + idx * asf_st->ds_chunk_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1201 asf_st->ds_chunk_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1202 offset += asf_st->ds_chunk_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1203 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1204 av_free(asf_st->pkt.data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1205 asf_st->pkt.data = newdata;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1206 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1207 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1208 asf_st->frag_offset = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1209 memcpy(pkt, &asf_st->pkt, sizeof(AVPacket));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1210 //printf("packet %d %d\n", asf_st->pkt.size, asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1211 asf_st->pkt.size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1212 asf_st->pkt.data = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1213 break; // packet completed
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1214 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1215 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1216 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1217 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1218
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1219 static int asf_read_close(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1220 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1221 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1222
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1223 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1224 AVStream *st = s->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1225 av_free(st->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1226 av_free(st->codec.extradata);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1227 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1228 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1229 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1230
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1231 static int asf_read_seek(AVFormatContext *s, int64_t pts)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1232 {
136
6b74809d2496 Warning and compatibility fixes.
mellum
parents: 117
diff changeset
1233 printf("SEEK TO %lld", pts);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1234 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1235 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1236
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1237 static AVInputFormat asf_iformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1238 "asf",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1239 "asf format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1240 sizeof(ASFContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1241 asf_probe,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1242 asf_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1243 asf_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1244 asf_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1245 asf_read_seek,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1246 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1247
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1248 static AVOutputFormat asf_oformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1249 "asf",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1250 "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
1251 "video/x-ms-asf",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1252 "asf,wmv",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1253 sizeof(ASFContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1254 #ifdef CONFIG_MP3LAME
232
eb90c0a5a1ba CODEC_ID_MP3LAME is obsolete
bellard
parents: 196
diff changeset
1255 CODEC_ID_MP3,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1256 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1257 CODEC_ID_MP2,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1258 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1259 CODEC_ID_MSMPEG4V3,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1260 asf_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1261 asf_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1262 asf_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1263 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1264
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1265 static AVOutputFormat asf_stream_oformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1266 "asf_stream",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1267 "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
1268 "video/x-ms-asf",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1269 "asf,wmv",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1270 sizeof(ASFContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1271 #ifdef CONFIG_MP3LAME
232
eb90c0a5a1ba CODEC_ID_MP3LAME is obsolete
bellard
parents: 196
diff changeset
1272 CODEC_ID_MP3,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1273 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1274 CODEC_ID_MP2,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1275 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1276 CODEC_ID_MSMPEG4V3,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1277 asf_write_stream_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1278 asf_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1279 asf_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1280 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1281
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1282 int asf_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1283 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1284 av_register_input_format(&asf_iformat);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1285 av_register_output_format(&asf_oformat);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1286 av_register_output_format(&asf_stream_oformat);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1287 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1288 }