annotate asf.c @ 106:4da5d55b3690 libavformat

we really shouldnt use M$* as default codec -> use MPEG4 as default
author michaelni
date Thu, 17 Apr 2003 19:56:33 +0000
parents 25062c9b1f86
children 497ae2790081
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 typedef struct __attribute__((packed)) {
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 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 /* id */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415 if (enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 put_le16(pb, 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 put_le16(pb, codec_get_tag(codec_wav_tags, enc->codec_id));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419 put_le16(pb, 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420 put_le32(pb, codec_get_tag(codec_bmp_tags, enc->codec_id));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
421 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
422 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
425 /* patch the header size fields */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
426
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427 cur_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
428 header_size = cur_pos - header_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
430 header_size += 8 + 30 + 50;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
431
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432 url_fseek(pb, header_offset - 10 - 30, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
433 put_le16(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
434 url_fseek(pb, header_offset - 2 - 30, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435 put_le16(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 header_size -= 8 + 30 + 50;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439 header_size += 24 + 6;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 url_fseek(pb, header_offset - 14, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441 put_le64(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 url_fseek(pb, cur_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 /* movie chunk, followed by packets of packet_size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445 asf->data_offset = cur_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446 put_guid(pb, &data_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447 put_le64(pb, data_chunk_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 put_guid(pb, &my_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449 put_le64(pb, asf->nb_packets); /* nb packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450 put_byte(pb, 1); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451 put_byte(pb, 1); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
454
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455 static int asf_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
456 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
457 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
458
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459 av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
460
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461 asf->packet_size = PACKET_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
462 asf->nb_packets = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
464 if (asf_write_header1(s, 0, 50) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
465 //av_free(asf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
466 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
471 asf->packet_nb_frames = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472 asf->packet_timestamp_start = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
473 asf->packet_timestamp_end = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
474 asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
475 init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
476 NULL, NULL, NULL, NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
477
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
478 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
479 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
480
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
481 static int asf_write_stream_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
482 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
483 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
484
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
485 asf->is_streamed = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
486
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
487 return asf_write_header(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
488 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
489
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
490 /* write a fixed size packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
491 static int put_packet(AVFormatContext *s,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
492 unsigned int timestamp, unsigned int duration,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
493 int nb_frames, int padsize)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
494 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
495 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
496 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
497 int flags;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
498
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
499 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
500 put_chunk(s, 0x4424, asf->packet_size, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
501 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
502
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
503 put_byte(pb, 0x82);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
504 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
505
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
506 flags = 0x01; /* nb segments present */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
507 if (padsize > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
508 if (padsize < 256)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
509 flags |= 0x08;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
510 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
511 flags |= 0x10;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
512 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
513 put_byte(pb, flags); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
514 put_byte(pb, 0x5d);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
515 if (flags & 0x10)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
516 put_le16(pb, padsize - 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
517 if (flags & 0x08)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
518 put_byte(pb, padsize - 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
519 put_le32(pb, timestamp);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
520 put_le16(pb, duration);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
521 put_byte(pb, nb_frames | 0x80);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
522
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
523 return PACKET_HEADER_SIZE + ((flags & 0x18) >> 3);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
524 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
525
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
526 static void flush_packet(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
527 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
528 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
529 int hdr_size, ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
530
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
531 hdr_size = put_packet(s, asf->packet_timestamp_start,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
532 asf->packet_timestamp_end - asf->packet_timestamp_start,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
533 asf->packet_nb_frames, asf->packet_size_left);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
534
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
535 /* Clear out the padding bytes */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
536 ptr = asf->packet_size - hdr_size - asf->packet_size_left;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
537 memset(asf->packet_buf + ptr, 0, asf->packet_size_left);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
538
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
539 put_buffer(&s->pb, asf->packet_buf, asf->packet_size - hdr_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
540
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
541 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
542 asf->nb_packets++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
543 asf->packet_nb_frames = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
544 asf->packet_timestamp_start = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
545 asf->packet_timestamp_end = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
546 asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
547 init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
548 NULL, NULL, NULL, NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
549 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
550
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
551 static void put_frame_header(AVFormatContext *s, ASFStream *stream, int timestamp,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
552 int payload_size, int frag_offset, int frag_len)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
553 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
554 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
555 ByteIOContext *pb = &asf->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
556 int val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
557
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
558 val = stream->num;
7
47e502ac6349 AVVideoFrame -> AVFrame
michaelni
parents: 5
diff changeset
559 if (s->streams[val - 1]->codec.coded_frame->key_frame /* && frag_offset == 0 */)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
560 val |= 0x80;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
561 put_byte(pb, val);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
562 put_byte(pb, stream->seq);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
563 put_le32(pb, frag_offset); /* fragment offset */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
564 put_byte(pb, 0x08); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
565 put_le32(pb, payload_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
566 put_le32(pb, timestamp);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
567 put_le16(pb, frag_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
568 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
569
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
570
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
571 /* Output a frame. We suppose that payload_size <= PACKET_SIZE.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
572
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
573 It is there that you understand that the ASF format is really
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
574 crap. They have misread the MPEG Systems spec !
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
575 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
576 static void put_frame(AVFormatContext *s, ASFStream *stream, int timestamp,
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
577 uint8_t *buf, int payload_size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
578 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
579 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
580 int frag_pos, frag_len, frag_len1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
581
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
582 frag_pos = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
583 while (frag_pos < payload_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
584 frag_len = payload_size - frag_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
585 frag_len1 = asf->packet_size_left - FRAME_HEADER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
586 if (frag_len1 > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
587 if (frag_len > frag_len1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
588 frag_len = frag_len1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
589 put_frame_header(s, stream, timestamp+1, payload_size, frag_pos, frag_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
590 put_buffer(&asf->pb, buf, frag_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
591 asf->packet_size_left -= (frag_len + FRAME_HEADER_SIZE);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
592 asf->packet_timestamp_end = timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
593 if (asf->packet_timestamp_start == -1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
594 asf->packet_timestamp_start = timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
595 asf->packet_nb_frames++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
596 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
597 frag_len = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
598 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
599 frag_pos += frag_len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
600 buf += frag_len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
601 /* output the frame if filled */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
602 if (asf->packet_size_left <= FRAME_HEADER_SIZE)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
603 flush_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
604 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
605 stream->seq++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
606 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
607
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
608
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
609 static int asf_write_packet(AVFormatContext *s, int stream_index,
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
610 uint8_t *buf, int size, int timestamp)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
611 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
612 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
613 ASFStream *stream;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
614 int64_t duration;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
615 AVCodecContext *codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
616
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
617 codec = &s->streams[stream_index]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
618 stream = &asf->streams[stream_index];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
619
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
620 if (codec->codec_type == CODEC_TYPE_AUDIO) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
621 duration = (codec->frame_number * codec->frame_size * int64_t_C(10000000)) /
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
622 codec->sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
623 } else {
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 84
diff changeset
624 duration = av_rescale(codec->frame_number * codec->frame_rate_base, 10000000, codec->frame_rate);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
625 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
626 if (duration > asf->duration)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
627 asf->duration = duration;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
628
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
629 put_frame(s, stream, timestamp, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
630 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
631 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
632
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
633 static int asf_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
634 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
635 ASFContext *asf = s->priv_data;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
636 int64_t file_size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
637
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
638 /* flush the current packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
639 if (asf->pb.buf_ptr > asf->pb.buffer)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
640 flush_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
641
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
642 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
643 put_chunk(s, 0x4524, 0, 0); /* end of stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
644 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
645 /* rewrite an updated header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
646 file_size = url_ftell(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
647 url_fseek(&s->pb, 0, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
648 asf_write_header1(s, file_size, file_size - asf->data_offset);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
649 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
650
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
651 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
652 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
653 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
654
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
655 /**********************************/
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
656 /* decoding */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
657
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
658 //#define DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
659
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
660 #ifdef DEBUG
69
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
661 #define PRINT_IF_GUID(g,cmp) \
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
662 if (!memcmp(g, &cmp, sizeof(GUID))) \
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
663 printf("(GUID: %s) ", #cmp)
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
664
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
665 static void print_guid(const GUID *g)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
666 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
667 int i;
69
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
668 PRINT_IF_GUID(g, asf_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
669 else PRINT_IF_GUID(g, file_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
670 else PRINT_IF_GUID(g, stream_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
671 else PRINT_IF_GUID(g, audio_stream);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
672 else PRINT_IF_GUID(g, audio_conceal_none);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
673 else PRINT_IF_GUID(g, video_stream);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
674 else PRINT_IF_GUID(g, video_conceal_none);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
675 else PRINT_IF_GUID(g, comment_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
676 else PRINT_IF_GUID(g, codec_comment_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
677 else PRINT_IF_GUID(g, codec_comment1_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
678 else PRINT_IF_GUID(g, data_header);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
679 else PRINT_IF_GUID(g, index_guid);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
680 else PRINT_IF_GUID(g, head1_guid);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
681 else PRINT_IF_GUID(g, head2_guid);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
682 else PRINT_IF_GUID(g, my_guid);
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
683 else
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
684 printf("(GUID: unknown) ");
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
685 printf("0x%08x, 0x%04x, 0x%04x, {", g->v1, g->v2, g->v3);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
686 for(i=0;i<8;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
687 printf(" 0x%02x,", g->v4[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
688 printf("}\n");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
689 }
69
0686eeb0c21b prettier debug output
mmu_man
parents: 65
diff changeset
690 #undef PRINT_IF_GUID(g,cmp)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
691 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
692
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
693 static void get_guid(ByteIOContext *s, GUID *g)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
694 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
695 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
696
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
697 g->v1 = get_le32(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
698 g->v2 = get_le16(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
699 g->v3 = get_le16(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
700 for(i=0;i<8;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
701 g->v4[i] = get_byte(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
702 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
703
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
704 #if 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
705 static void get_str16(ByteIOContext *pb, char *buf, int buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
706 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
707 int len, c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
708 char *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
709
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
710 len = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
711 q = buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
712 while (len > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
713 c = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
714 if ((q - buf) < buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
715 *q++ = c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
716 len--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
717 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
718 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
719 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
720 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
721
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
722 static void get_str16_nolen(ByteIOContext *pb, int len, char *buf, int buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
723 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
724 int c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
725 char *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
726
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
727 q = buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
728 while (len > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
729 c = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
730 if ((q - buf) < buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
731 *q++ = c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
732 len-=2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
733 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
734 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
735 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
736
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
737 static int asf_probe(AVProbeData *pd)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
738 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
739 GUID g;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
740 const unsigned char *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
741 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
742
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
743 /* check file header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
744 if (pd->buf_size <= 32)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
745 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
746 p = pd->buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
747 g.v1 = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
748 p += 4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
749 g.v2 = p[0] | (p[1] << 8);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
750 p += 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
751 g.v3 = p[0] | (p[1] << 8);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
752 p += 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
753 for(i=0;i<8;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
754 g.v4[i] = *p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
755
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
756 if (!memcmp(&g, &asf_header, sizeof(GUID)))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
757 return AVPROBE_SCORE_MAX;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
758 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
759 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
760 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
761
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
762 static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
763 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
764 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
765 GUID g;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
766 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
767 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
768 ASFStream *asf_st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
769 int size, i;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
770 int64_t gsize;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
771
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
772 av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
773
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
774 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
775 if (memcmp(&g, &asf_header, sizeof(GUID)))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
776 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
777 get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
778 get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
779 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
780 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
781 memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
782 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
783 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
784 gsize = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
785 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
786 printf("%08Lx: ", url_ftell(pb) - 24);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
787 print_guid(&g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
788 printf(" size=0x%Lx\n", gsize);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
789 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
790 if (gsize < 24)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
791 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
792 if (!memcmp(&g, &file_header, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
793 get_guid(pb, &asf->hdr.guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
794 asf->hdr.file_size = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
795 asf->hdr.create_time = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
796 asf->hdr.packets_count = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
797 asf->hdr.play_time = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
798 asf->hdr.send_time = get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
799 asf->hdr.preroll = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
800 asf->hdr.ignore = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
801 asf->hdr.flags = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
802 asf->hdr.min_pktsize = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
803 asf->hdr.max_pktsize = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
804 asf->hdr.max_bitrate = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
805 asf->packet_size = asf->hdr.max_pktsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
806 asf->nb_packets = asf->hdr.packets_count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
807 } 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
808 int type, total_size, type_specific_size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
809 unsigned int tag1;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
810 int64_t pos1, pos2;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
811
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
812 pos1 = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
813
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
814 st = av_mallocz(sizeof(AVStream));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
815 if (!st)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
816 goto fail;
5
39c4c4336486 cleanup
michaelni
parents: 0
diff changeset
817 avcodec_get_context_defaults(&st->codec);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
818 s->streams[s->nb_streams] = st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
819 asf_st = av_mallocz(sizeof(ASFStream));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
820 if (!asf_st)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
821 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
822 st->priv_data = asf_st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
823 st->time_length = (asf->hdr.send_time - asf->hdr.preroll) / 10; // us
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
824 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
825 if (!memcmp(&g, &audio_stream, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
826 type = CODEC_TYPE_AUDIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
827 } else if (!memcmp(&g, &video_stream, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
828 type = CODEC_TYPE_VIDEO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
829 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
830 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
831 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
832 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
833 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
834 type_specific_size = get_le32(pb);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
835 get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
836 st->id = get_le16(pb) & 0x7f; /* stream id */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
837 // mapping of asf ID to AV stream ID;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
838 asf->asfid2avid[st->id] = s->nb_streams++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
839
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
840 get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
841 st->codec.codec_type = type;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
842 st->codec.frame_rate = 15 * s->pts_den / s->pts_num; // 15 fps default
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
843 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
844 get_wav_header(pb, &st->codec, type_specific_size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
845 /* We have to init the frame size at some point .... */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
846 pos2 = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
847 if (gsize > (pos2 + 8 - pos1 + 24)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
848 asf_st->ds_span = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
849 asf_st->ds_packet_size = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
850 asf_st->ds_chunk_size = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
851 asf_st->ds_data_size = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
852 asf_st->ds_silence_data = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
853 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
854 //printf("Descrambling: ps:%d cs:%d ds:%d s:%d sd:%d\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
855 // asf_st->ds_packet_size, asf_st->ds_chunk_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
856 // asf_st->ds_data_size, asf_st->ds_span, asf_st->ds_silence_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
857 if (asf_st->ds_span > 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
858 if (!asf_st->ds_chunk_size
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
859 || (asf_st->ds_packet_size/asf_st->ds_chunk_size <= 1))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
860 asf_st->ds_span = 0; // disable descrambling
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
861 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
862 switch (st->codec.codec_id) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
863 case CODEC_ID_MP3LAME:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
864 st->codec.frame_size = MPA_FRAME_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
865 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
866 case CODEC_ID_PCM_S16LE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
867 case CODEC_ID_PCM_S16BE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
868 case CODEC_ID_PCM_U16LE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
869 case CODEC_ID_PCM_U16BE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
870 case CODEC_ID_PCM_S8:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
871 case CODEC_ID_PCM_U8:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
872 case CODEC_ID_PCM_ALAW:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
873 case CODEC_ID_PCM_MULAW:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
874 st->codec.frame_size = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
875 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
876 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
877 /* This is probably wrong, but it prevents a crash later */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
878 st->codec.frame_size = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
879 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
880 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
881 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
882 get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
883 get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
884 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
885 size = get_le16(pb); /* size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
886 get_le32(pb); /* size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
887 st->codec.width = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
888 st->codec.height = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
889 /* not available for asf */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
890 get_le16(pb); /* panes */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
891 get_le16(pb); /* depth */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
892 tag1 = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
893 url_fskip(pb, 20);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
894 if (size > 40) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
895 st->codec.extradata_size = size - 40;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
896 st->codec.extradata = av_mallocz(st->codec.extradata_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
897 get_buffer(pb, st->codec.extradata, st->codec.extradata_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
898 }
74
4b501fe1539c merging fourcc with codec_tag
michaelni
parents: 69
diff changeset
899 st->codec.codec_tag = tag1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
900 st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
901 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
902 pos2 = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
903 url_fskip(pb, gsize - (pos2 - pos1 + 24));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
904 } else if (!memcmp(&g, &data_header, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
905 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
906 } else if (!memcmp(&g, &comment_header, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
907 int len1, len2, len3, len4, len5;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
908
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
909 len1 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
910 len2 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
911 len3 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
912 len4 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
913 len5 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
914 get_str16_nolen(pb, len1, s->title, sizeof(s->title));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
915 get_str16_nolen(pb, len2, s->author, sizeof(s->author));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
916 get_str16_nolen(pb, len3, s->copyright, sizeof(s->copyright));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
917 get_str16_nolen(pb, len4, s->comment, sizeof(s->comment));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
918 url_fskip(pb, len5);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
919 #if 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
920 } else if (!memcmp(&g, &head1_guid, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
921 int v1, v2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
922 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
923 v1 = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
924 v2 = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
925 } else if (!memcmp(&g, &codec_comment_header, sizeof(GUID))) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
926 int len, v1, n, num;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
927 char str[256], *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
928 char tag[16];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
929
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
930 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
931 print_guid(&g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
932
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
933 n = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
934 for(i=0;i<n;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
935 num = get_le16(pb); /* stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
936 get_str16(pb, str, sizeof(str));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
937 get_str16(pb, str, sizeof(str));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
938 len = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
939 q = tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
940 while (len > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
941 v1 = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
942 if ((q - tag) < sizeof(tag) - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
943 *q++ = v1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
944 len--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
945 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
946 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
947 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
948 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
949 } else if (url_feof(pb)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
950 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
951 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
952 url_fseek(pb, gsize - 24, SEEK_CUR);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
953 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
954 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
955 get_guid(pb, &g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
956 get_le64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
957 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
958 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
959 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 asf->data_offset = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
962 asf->packet_size_left = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
963
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
964 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
965
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
966 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
967 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
968 AVStream *st = s->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
969 if (st) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
970 av_free(st->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
971 av_free(st->codec.extradata);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
972 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
973 av_free(st);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
974 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
975 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
976 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
977
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
978 #define DO_2BITS(bits, var, defval) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
979 switch (bits & 3) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
980 { \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
981 case 3: var = get_le32(pb); rsize += 4; break; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
982 case 2: var = get_le16(pb); rsize += 2; break; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
983 case 1: var = get_byte(pb); rsize++; break; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
984 default: var = defval; break; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
985 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
986
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
987 static int asf_get_packet(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
988 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
989 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
990 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
991 uint32_t packet_length, padsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
992 int rsize = 11;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
993 int c = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
994 if (c != 0x82) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
995 if (!url_feof(pb))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
996 printf("ff asf bad header %x at:%Ld\n", c, url_ftell(pb));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
997 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
998 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
999 if ((c & 0x0f) == 2) { // always true for now
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1000 if (get_le16(pb) != 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1001 if (!url_feof(pb))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1002 printf("ff asf bad non zero\n");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1003 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1004 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1005 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1006
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1007 asf->packet_flags = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1008 asf->packet_property = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1009
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1010 DO_2BITS(asf->packet_flags >> 5, packet_length, asf->packet_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1011 DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence ignored
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1012 DO_2BITS(asf->packet_flags >> 3, padsize, 0); // padding length
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1013
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1014 asf->packet_timestamp = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1015 get_le16(pb); /* duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1016 // rsize has at least 11 bytes which have to be present
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1017
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1018 if (asf->packet_flags & 0x01) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1019 asf->packet_segsizetype = get_byte(pb); rsize++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1020 asf->packet_segments = asf->packet_segsizetype & 0x3f;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1021 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1022 asf->packet_segments = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1023 asf->packet_segsizetype = 0x80;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1024 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1025 asf->packet_size_left = packet_length - padsize - rsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1026 if (packet_length < asf->hdr.min_pktsize)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1027 padsize += asf->hdr.min_pktsize - packet_length;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1028 asf->packet_padsize = padsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1029 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1030 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
1031 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1032 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1033 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1034
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1035 static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1036 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1037 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1038 ASFStream *asf_st = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1039 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1040 //static int pc = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1041 for (;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1042 int rsize = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1043 if (asf->packet_size_left < FRAME_HEADER_SIZE
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1044 || asf->packet_segments < 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1045 //asf->packet_size_left <= asf->packet_padsize) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1046 int ret = asf->packet_size_left + asf->packet_padsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1047 //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
1048 /* fail safe */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1049 url_fskip(pb, ret);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1050 ret = asf_get_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1051 //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
1052 if (ret < 0 || url_feof(pb))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1053 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1054 asf->packet_time_start = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1055 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1056 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1057 if (asf->packet_time_start == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1058 /* read frame header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1059 int num = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1060 asf->packet_segments--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1061 rsize++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1062 asf->packet_key_frame = (num & 0x80) >> 7;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1063 asf->stream_index = asf->asfid2avid[num & 0x7f];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1064 // sequence should be ignored!
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1065 DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1066 DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1067 DO_2BITS(asf->packet_property, asf->packet_replic_size, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1068
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1069 if (asf->packet_replic_size > 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1070 // it should be always at least 8 bytes - FIXME validate
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1071 asf->packet_obj_size = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1072 asf->packet_frag_timestamp = get_le32(pb); // timestamp
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1073 if (asf->packet_replic_size > 8)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1074 url_fskip(pb, asf->packet_replic_size - 8);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1075 rsize += asf->packet_replic_size; // FIXME - check validity
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1076 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1077 // multipacket - frag_offset is begining timestamp
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1078 asf->packet_time_start = asf->packet_frag_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1079 asf->packet_frag_offset = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1080 asf->packet_frag_timestamp = asf->packet_timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1081
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1082 if (asf->packet_replic_size == 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1083 asf->packet_time_delta = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1084 rsize++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1085 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1086 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1087 if (asf->packet_flags & 0x01) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1088 DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1089 #undef DO_2BITS
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1090 //printf("Fragsize %d\n", asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1091 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1092 asf->packet_frag_size = asf->packet_size_left - rsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1093 //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
1094 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1095 if (asf->packet_replic_size == 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1096 asf->packet_multi_size = asf->packet_frag_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1097 if (asf->packet_multi_size > asf->packet_size_left) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1098 asf->packet_segments = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1099 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1100 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1101 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1102 asf->packet_size_left -= rsize;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1103 //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
1104
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1105 if (asf->stream_index < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1106 asf->packet_time_start = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1107 /* unhandled packet (should not happen) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1108 url_fskip(pb, asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1109 asf->packet_size_left -= asf->packet_frag_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1110 printf("ff asf skip %d %d\n", asf->packet_frag_size, num & 0x7f);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1111 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1112 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1113 asf->asf_st = s->streams[asf->stream_index]->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1114 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1115 asf_st = asf->asf_st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1116
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1117 if ((asf->packet_frag_offset != asf_st->frag_offset
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1118 || (asf->packet_frag_offset
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1119 && asf->packet_seq != asf_st->seq)) // seq should be ignored
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1120 ) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1121 /* cannot continue current packet: free it */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1122 // FIXME better check if packet was already allocated
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1123 printf("ff asf parser skips: %d - %d o:%d - %d %d %d fl:%d\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1124 asf_st->pkt.size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1125 asf->packet_obj_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1126 asf->packet_frag_offset, asf_st->frag_offset,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1127 asf->packet_seq, asf_st->seq, asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1128 if (asf_st->pkt.size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1129 av_free_packet(&asf_st->pkt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1130 asf_st->frag_offset = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1131 if (asf->packet_frag_offset != 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1132 url_fskip(pb, asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1133 printf("ff asf parser skiping %db\n", asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1134 asf->packet_size_left -= asf->packet_frag_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1135 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1136 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1137 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1138 if (asf->packet_replic_size == 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1139 // frag_offset is here used as the begining timestamp
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1140 asf->packet_frag_timestamp = asf->packet_time_start;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1141 asf->packet_time_start += asf->packet_time_delta;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1142 asf->packet_obj_size = asf->packet_frag_size = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1143 asf->packet_size_left--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1144 asf->packet_multi_size--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1145 if (asf->packet_multi_size < asf->packet_obj_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1146 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1147 asf->packet_time_start = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1148 url_fskip(pb, asf->packet_multi_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1149 asf->packet_size_left -= asf->packet_multi_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1150 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1151 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1152 asf->packet_multi_size -= asf->packet_obj_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1153 //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
1154 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1155 if (asf_st->frag_offset == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1156 /* new packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1157 av_new_packet(&asf_st->pkt, asf->packet_obj_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1158 asf_st->seq = asf->packet_seq;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1159 asf_st->pkt.pts = asf->packet_frag_timestamp - asf->hdr.preroll;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1160 asf_st->pkt.stream_index = asf->stream_index;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1161 if (asf->packet_key_frame)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1162 asf_st->pkt.flags |= PKT_FLAG_KEY;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1163 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1164
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1165 /* read data */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1166 //printf("READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1167 // asf->packet_size, asf_st->pkt.size, asf->packet_frag_offset,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1168 // asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1169 asf->packet_size_left -= asf->packet_frag_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1170 if (asf->packet_size_left < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1171 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1172 get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1173 asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1174 asf_st->frag_offset += asf->packet_frag_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1175 /* test if whole packet is read */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1176 if (asf_st->frag_offset == asf_st->pkt.size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1177 /* return packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1178 if (asf_st->ds_span > 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1179 /* packet descrambling */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1180 char* newdata = av_malloc(asf_st->pkt.size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1181 if (newdata) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1182 int offset = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1183 while (offset < asf_st->pkt.size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1184 int off = offset / asf_st->ds_chunk_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1185 int row = off / asf_st->ds_span;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1186 int col = off % asf_st->ds_span;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1187 int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1188 //printf("off:%d row:%d col:%d idx:%d\n", off, row, col, idx);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1189 memcpy(newdata + offset,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1190 asf_st->pkt.data + idx * asf_st->ds_chunk_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1191 asf_st->ds_chunk_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1192 offset += asf_st->ds_chunk_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1193 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1194 av_free(asf_st->pkt.data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1195 asf_st->pkt.data = newdata;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1196 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1197 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1198 asf_st->frag_offset = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1199 memcpy(pkt, &asf_st->pkt, sizeof(AVPacket));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1200 //printf("packet %d %d\n", asf_st->pkt.size, asf->packet_frag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1201 asf_st->pkt.size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1202 asf_st->pkt.data = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1203 break; // packet completed
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1204 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1205 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1206 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1207 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1208
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1209 static int asf_read_close(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1210 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1211 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1212
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1213 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1214 AVStream *st = s->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1215 av_free(st->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1216 av_free(st->codec.extradata);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1217 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1218 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1219 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1220
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1221 static int asf_read_seek(AVFormatContext *s, int64_t pts)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1222 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1223 printf("SEEK TO %Ld", pts);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1224 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1225 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1226
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1227 static AVInputFormat asf_iformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1228 "asf",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1229 "asf format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1230 sizeof(ASFContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1231 asf_probe,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1232 asf_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1233 asf_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1234 asf_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1235 asf_read_seek,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1236 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1237
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1238 static AVOutputFormat asf_oformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1239 "asf",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1240 "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
1241 "video/x-ms-asf",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1242 "asf,wmv",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1243 sizeof(ASFContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1244 #ifdef CONFIG_MP3LAME
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1245 CODEC_ID_MP3LAME,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1246 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1247 CODEC_ID_MP2,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1248 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1249 CODEC_ID_MSMPEG4V3,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1250 asf_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1251 asf_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1252 asf_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1253 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1254
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1255 static AVOutputFormat asf_stream_oformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1256 "asf_stream",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1257 "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
1258 "video/x-ms-asf",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1259 "asf,wmv",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1260 sizeof(ASFContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1261 #ifdef CONFIG_MP3LAME
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1262 CODEC_ID_MP3LAME,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1263 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1264 CODEC_ID_MP2,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1265 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1266 CODEC_ID_MSMPEG4V3,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1267 asf_write_stream_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1268 asf_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1269 asf_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1270 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1271
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1272 int asf_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1273 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1274 av_register_input_format(&asf_iformat);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1275 av_register_output_format(&asf_oformat);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1276 av_register_output_format(&asf_stream_oformat);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1277 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1278 }