annotate asf-enc.c @ 372:2e12cd1b68ed libavformat

split asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
author michael
date Fri, 05 Mar 2004 21:34:30 +0000
parents asf.c@845f9de2c883
children e47d9c8e2054
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
372
2e12cd1b68ed split asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 370
diff changeset
2 * Adaptive stream format encoder
0
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"
372
2e12cd1b68ed split asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 370
diff changeset
21 #include "asf.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22
348
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
23 #undef NDEBUG
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
24 #include <assert.h>
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
25
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
26 #ifdef CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 static void put_guid(ByteIOContext *s, const GUID *g)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 put_le32(s, g->v1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 put_le16(s, g->v2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 put_le16(s, g->v3);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 for(i=0;i<8;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 put_byte(s, g->v4[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 static void put_str16(ByteIOContext *s, const char *tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 int c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 put_le16(s,strlen(tag) + 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 for(;;) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
44 c = (uint8_t)*tag++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 put_le16(s, c);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 if (c == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 static void put_str16_nolen(ByteIOContext *s, const char *tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 int c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 for(;;) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
56 c = (uint8_t)*tag++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 put_le16(s, c);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 if (c == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
63 static int64_t put_header(ByteIOContext *pb, const GUID *g)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
65 int64_t pos;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 put_guid(pb, g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 put_le64(pb, 24);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 return pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 /* update header size */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
74 static void end_header(ByteIOContext *pb, int64_t pos)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
76 int64_t pos1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 pos1 = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 url_fseek(pb, pos + 16, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 put_le64(pb, pos1 - pos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 url_fseek(pb, pos1, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 /* write an asf chunk (only used in streaming case) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 int length;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 length = payload_length + 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 put_le16(pb, type);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 put_le16(pb, length);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 put_le32(pb, asf->seqno);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 put_le16(pb, flags); /* unknown bytes */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 put_le16(pb, length);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 asf->seqno++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 /* convert from unix to windows time */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
101 static int64_t unix_to_file_time(int ti)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
103 int64_t t;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
105 t = ti * int64_t_C(10000000);
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
106 t += int64_t_C(116444736000000000);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 return t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 /* write the header (used two times if non streamed) */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
111 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
112 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 int has_title;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 AVCodecContext *enc;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
118 int64_t header_offset, cur_pos, hpos;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 int bit_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 has_title = (s->title[0] || s->author[0] || s->copyright[0] || s->comment[0]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 bit_rate = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 for(n=0;n<s->nb_streams;n++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 enc = &s->streams[n]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 bit_rate += enc->bit_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 put_guid(pb, &asf_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 put_le64(pb, -1); /* header length, will be patched after */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 put_le32(pb, 3 + has_title + s->nb_streams); /* number of chunks in header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 put_byte(pb, 1); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 put_byte(pb, 2); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 /* file header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 header_offset = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 hpos = put_header(pb, &file_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 put_guid(pb, &my_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 put_le64(pb, file_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 file_time = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 put_le64(pb, unix_to_file_time(file_time));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 put_le64(pb, asf->nb_packets); /* number of packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 put_le64(pb, asf->duration); /* end time stamp (in 100ns units) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 put_le64(pb, asf->duration); /* duration (in 100ns units) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150 put_le32(pb, 0); /* start time stamp */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151 put_le32(pb, 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152 put_le32(pb, asf->is_streamed ? 1 : 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 put_le32(pb, asf->packet_size); /* packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 put_le32(pb, asf->packet_size); /* packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155 put_le32(pb, bit_rate); /* Nominal data rate in bps */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 /* unknown headers */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 hpos = put_header(pb, &head1_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 put_guid(pb, &head2_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 put_le32(pb, 6);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 /* title and other infos */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166 if (has_title) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 hpos = put_header(pb, &comment_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 put_le16(pb, 2 * (strlen(s->title) + 1));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 put_le16(pb, 2 * (strlen(s->author) + 1));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 put_le16(pb, 2 * (strlen(s->copyright) + 1));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 put_le16(pb, 2 * (strlen(s->comment) + 1));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 put_str16_nolen(pb, s->title);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 put_str16_nolen(pb, s->author);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 put_str16_nolen(pb, s->copyright);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 put_str16_nolen(pb, s->comment);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180 /* stream headers */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181 for(n=0;n<s->nb_streams;n++) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
182 int64_t es_pos;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 // ASFStream *stream = &asf->streams[n];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 enc = &s->streams[n]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 asf->streams[n].num = n + 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 asf->streams[n].seq = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 switch(enc->codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 wav_extra_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 extra_size = 18 + wav_extra_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 extra_size2 = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 wav_extra_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 extra_size = 0x33;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199 extra_size2 = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 hpos = put_header(pb, &stream_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 if (enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 put_guid(pb, &audio_stream);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 put_guid(pb, &audio_conceal_none);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 put_guid(pb, &video_stream);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 put_guid(pb, &video_conceal_none);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 put_le64(pb, 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 es_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 put_le32(pb, extra_size); /* wav header len */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 put_le32(pb, extra_size2); /* additional data len */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 put_le16(pb, n + 1); /* stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 put_le32(pb, 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 if (enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 /* WAVEFORMATEX header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 int wavsize = put_wav_header(pb, enc);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 if (wavsize < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 if (wavsize != extra_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 cur_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 url_fseek(pb, es_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 put_le32(pb, wavsize); /* wav header len */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 url_fseek(pb, cur_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 put_le32(pb, enc->width);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 put_le32(pb, enc->height);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 put_byte(pb, 2); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 put_le16(pb, 40); /* size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 /* BITMAPINFOHEADER header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 put_bmp_header(pb, enc, codec_bmp_tags, 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 end_header(pb, hpos);
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 /* media comments */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 hpos = put_header(pb, &codec_comment_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 put_guid(pb, &codec_comment1_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 put_le32(pb, s->nb_streams);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 for(n=0;n<s->nb_streams;n++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 AVCodec *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 enc = &s->streams[n]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 p = avcodec_find_encoder(enc->codec_id);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 put_le16(pb, asf->streams[n].num);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 put_str16(pb, p ? p->name : enc->codec_name);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 put_le16(pb, 0); /* no parameters */
196
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
256
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
257
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 /* id */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 if (enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 put_le16(pb, 2);
196
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
261 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
262 enc->codec_tag = codec_get_tag(codec_wav_tags, enc->codec_id);
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
263 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
264 return -1;
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
265 put_le16(pb, enc->codec_tag);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267 put_le16(pb, 4);
196
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
268 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
269 enc->codec_tag = codec_get_tag(codec_bmp_tags, enc->codec_id);
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
270 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
271 return -1;
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
272 put_le32(pb, enc->codec_tag);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 /* patch the header size fields */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279 cur_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 header_size = cur_pos - header_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282 header_size += 8 + 30 + 50;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 url_fseek(pb, header_offset - 10 - 30, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285 put_le16(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 url_fseek(pb, header_offset - 2 - 30, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287 put_le16(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289 header_size -= 8 + 30 + 50;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291 header_size += 24 + 6;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292 url_fseek(pb, header_offset - 14, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293 put_le64(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 url_fseek(pb, cur_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
296 /* movie chunk, followed by packets of packet_size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
297 asf->data_offset = cur_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
298 put_guid(pb, &data_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
299 put_le64(pb, data_chunk_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300 put_guid(pb, &my_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301 put_le64(pb, asf->nb_packets); /* nb packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
302 put_byte(pb, 1); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303 put_byte(pb, 1); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
304 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
305 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307 static int asf_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
308 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
311 av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
312
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
313 asf->packet_size = PACKET_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
314 asf->nb_packets = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316 if (asf_write_header1(s, 0, 50) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
317 //av_free(asf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
319 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
320
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
321 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
322
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
323 asf->packet_nb_frames = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
324 asf->packet_timestamp_start = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
325 asf->packet_timestamp_end = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326 asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328 NULL, NULL, NULL, NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
329
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333 static int asf_write_stream_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
336
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337 asf->is_streamed = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339 return asf_write_header(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
340 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
341
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342 /* write a fixed size packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343 static int put_packet(AVFormatContext *s,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
344 unsigned int timestamp, unsigned int duration,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
345 int nb_frames, int padsize)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
346 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349 int flags;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 put_chunk(s, 0x4424, asf->packet_size, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
353 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
354
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
355 put_byte(pb, 0x82);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
358 flags = 0x01; /* nb segments present */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359 if (padsize > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360 if (padsize < 256)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361 flags |= 0x08;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
362 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363 flags |= 0x10;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
365 put_byte(pb, flags); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
366 put_byte(pb, 0x5d);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
367 if (flags & 0x10)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
368 put_le16(pb, padsize - 2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
369 if (flags & 0x08)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
370 put_byte(pb, padsize - 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
371 put_le32(pb, timestamp);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
372 put_le16(pb, duration);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
373 put_byte(pb, nb_frames | 0x80);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
374
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375 return PACKET_HEADER_SIZE + ((flags & 0x18) >> 3);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
377
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
378 static void flush_packet(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
379 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
380 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
381 int hdr_size, ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
382
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
383 hdr_size = put_packet(s, asf->packet_timestamp_start,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
384 asf->packet_timestamp_end - asf->packet_timestamp_start,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
385 asf->packet_nb_frames, asf->packet_size_left);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
386
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
387 /* Clear out the padding bytes */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
388 ptr = asf->packet_size - hdr_size - asf->packet_size_left;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
389 memset(asf->packet_buf + ptr, 0, asf->packet_size_left);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
390
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
391 put_buffer(&s->pb, asf->packet_buf, asf->packet_size - hdr_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
393 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 asf->nb_packets++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395 asf->packet_nb_frames = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396 asf->packet_timestamp_start = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
397 asf->packet_timestamp_end = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
398 asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399 init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
400 NULL, NULL, NULL, NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
401 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
402
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403 static void put_frame_header(AVFormatContext *s, ASFStream *stream, int timestamp,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404 int payload_size, int frag_offset, int frag_len)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
406 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
407 ByteIOContext *pb = &asf->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
408 int val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
409
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410 val = stream->num;
7
47e502ac6349 AVVideoFrame -> AVFrame
michaelni
parents: 5
diff changeset
411 if (s->streams[val - 1]->codec.coded_frame->key_frame /* && frag_offset == 0 */)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412 val |= 0x80;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 put_byte(pb, val);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 put_byte(pb, stream->seq);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415 put_le32(pb, frag_offset); /* fragment offset */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 put_byte(pb, 0x08); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 put_le32(pb, payload_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 put_le32(pb, timestamp);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419 put_le16(pb, frag_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420 }
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 /* Output a frame. We suppose that payload_size <= PACKET_SIZE.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
425 It is there that you understand that the ASF format is really
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
426 crap. They have misread the MPEG Systems spec !
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
428 static void put_frame(AVFormatContext *s, ASFStream *stream, int timestamp,
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 232
diff changeset
429 const uint8_t *buf, int payload_size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
430 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
431 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432 int frag_pos, frag_len, frag_len1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
433
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
434 frag_pos = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435 while (frag_pos < payload_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 frag_len = payload_size - frag_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 frag_len1 = asf->packet_size_left - FRAME_HEADER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 if (frag_len1 > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439 if (frag_len > frag_len1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 frag_len = frag_len1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441 put_frame_header(s, stream, timestamp+1, payload_size, frag_pos, frag_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 put_buffer(&asf->pb, buf, frag_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 asf->packet_size_left -= (frag_len + FRAME_HEADER_SIZE);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 asf->packet_timestamp_end = timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445 if (asf->packet_timestamp_start == -1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446 asf->packet_timestamp_start = timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447 asf->packet_nb_frames++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449 frag_len = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451 frag_pos += frag_len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452 buf += frag_len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453 /* output the frame if filled */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
454 if (asf->packet_size_left <= FRAME_HEADER_SIZE)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455 flush_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
456 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
457 stream->seq++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
458 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
460
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461 static int asf_write_packet(AVFormatContext *s, int stream_index,
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 232
diff changeset
462 const uint8_t *buf, int size, int64_t timestamp)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
464 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
465 ASFStream *stream;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
466 int64_t duration;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467 AVCodecContext *codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469 codec = &s->streams[stream_index]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470 stream = &asf->streams[stream_index];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
471
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472 if (codec->codec_type == CODEC_TYPE_AUDIO) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
473 duration = (codec->frame_number * codec->frame_size * int64_t_C(10000000)) /
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
474 codec->sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
475 } else {
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 84
diff changeset
476 duration = av_rescale(codec->frame_number * codec->frame_rate_base, 10000000, codec->frame_rate);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
477 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
478 if (duration > asf->duration)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
479 asf->duration = duration;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
480
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
481 put_frame(s, stream, timestamp, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
482 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
483 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
484
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
485 static int asf_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
486 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
487 ASFContext *asf = s->priv_data;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
488 int64_t file_size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
489
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
490 /* flush the current packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
491 if (asf->pb.buf_ptr > asf->pb.buffer)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
492 flush_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
493
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
494 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
495 put_chunk(s, 0x4524, 0, 0); /* end of stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
496 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
497 /* rewrite an updated header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
498 file_size = url_ftell(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
499 url_fseek(&s->pb, 0, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
500 asf_write_header1(s, file_size, file_size - asf->data_offset);
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_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
504 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
505 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
506
372
2e12cd1b68ed split asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 370
diff changeset
507 AVOutputFormat asf_oformat = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
508 "asf",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
509 "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
510 "video/x-ms-asf",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
511 "asf,wmv",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
512 sizeof(ASFContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
513 #ifdef CONFIG_MP3LAME
232
eb90c0a5a1ba CODEC_ID_MP3LAME is obsolete
bellard
parents: 196
diff changeset
514 CODEC_ID_MP3,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
515 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
516 CODEC_ID_MP2,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
517 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
518 CODEC_ID_MSMPEG4V3,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
519 asf_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
520 asf_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
521 asf_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
522 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
523
372
2e12cd1b68ed split asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 370
diff changeset
524 AVOutputFormat asf_stream_oformat = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
525 "asf_stream",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
526 "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
527 "video/x-ms-asf",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
528 "asf,wmv",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
529 sizeof(ASFContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
530 #ifdef CONFIG_MP3LAME
232
eb90c0a5a1ba CODEC_ID_MP3LAME is obsolete
bellard
parents: 196
diff changeset
531 CODEC_ID_MP3,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
532 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
533 CODEC_ID_MP2,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
534 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
535 CODEC_ID_MSMPEG4V3,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
536 asf_write_stream_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
537 asf_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
538 asf_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
539 };
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
540 #endif //CONFIG_ENCODERS