Mercurial > libavformat.hg
annotate ffm.c @ 3311:c603ff471631 libavformat
10l, fix compilation
author | bcoudurier |
---|---|
date | Wed, 21 May 2008 22:53:52 +0000 |
parents | 66d5e19f7b77 |
children | 20ea7e918398 |
rev | line source |
---|---|
0 | 1 /* |
1415
3b00fb8ef8e4
replace coder/decoder file description in libavformat by muxer/demuxer
aurel
parents:
1358
diff
changeset
|
2 * FFM (ffserver live feed) muxer and demuxer |
0 | 3 * Copyright (c) 2001 Fabrice Bellard. |
4 * | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
0 | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
0 | 11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
0 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
887
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 20 */ |
21 #include "avformat.h" | |
22 #include <unistd.h> | |
23 | |
24 /* The FFM file is made of blocks of fixed size */ | |
25 #define FFM_HEADER_SIZE 14 | |
26 #define PACKET_ID 0x666d | |
27 | |
28 /* each packet contains frames (which can span several packets */ | |
29 #define FRAME_HEADER_SIZE 8 | |
30 #define FLAG_KEY_FRAME 0x01 | |
31 | |
32 typedef struct FFMStream { | |
65 | 33 int64_t pts; |
0 | 34 } FFMStream; |
35 | |
36 enum { | |
37 READ_HEADER, | |
38 READ_DATA, | |
39 }; | |
40 | |
41 typedef struct FFMContext { | |
42 /* only reading mode */ | |
43 offset_t write_index, file_size; | |
44 int read_state; | |
65 | 45 uint8_t header[FRAME_HEADER_SIZE]; |
0 | 46 |
47 /* read and write */ | |
48 int first_packet; /* true if first packet, needed to set the discontinuity tag */ | |
901
c1a07d63a66d
pts fix by (Bryan Mayland / bmayland O leoninedev o com)
michael
parents:
896
diff
changeset
|
49 int first_frame_in_packet; /* true if first frame in packet, needed to know if PTS information is valid */ |
0 | 50 int packet_size; |
51 int frame_offset; | |
65 | 52 int64_t pts; |
53 uint8_t *packet_ptr, *packet_end; | |
54 uint8_t packet[FFM_PACKET_SIZE]; | |
0 | 55 } FFMContext; |
56 | |
318
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
57 static int64_t get_pts(AVFormatContext *s, offset_t pos); |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
58 |
0 | 59 /* disable pts hack for testing */ |
60 int ffm_nopts = 0; | |
61 | |
858
66cc656ea404
Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents:
823
diff
changeset
|
62 #ifdef CONFIG_MUXERS |
0 | 63 static void flush_packet(AVFormatContext *s) |
64 { | |
65 FFMContext *ffm = s->priv_data; | |
66 int fill_size, h; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2222
diff
changeset
|
67 ByteIOContext *pb = s->pb; |
0 | 68 |
69 fill_size = ffm->packet_end - ffm->packet_ptr; | |
70 memset(ffm->packet_ptr, 0, fill_size); | |
71 | |
885 | 72 if (url_ftell(pb) % ffm->packet_size) |
318
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
73 av_abort(); |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
74 |
0 | 75 /* put header */ |
76 put_be16(pb, PACKET_ID); | |
77 put_be16(pb, fill_size); | |
78 put_be64(pb, ffm->pts); | |
79 h = ffm->frame_offset; | |
80 if (ffm->first_packet) | |
81 h |= 0x8000; | |
82 put_be16(pb, h); | |
83 put_buffer(pb, ffm->packet, ffm->packet_end - ffm->packet); | |
751
dcb459ca11eb
Flush the ffm packet to the wire (or file) whenever we flush the ffm packet.
philipjsg
parents:
744
diff
changeset
|
84 put_flush_packet(pb); |
0 | 85 |
86 /* prepare next packet */ | |
87 ffm->frame_offset = 0; /* no key frame */ | |
88 ffm->pts = 0; /* no pts */ | |
89 ffm->packet_ptr = ffm->packet; | |
90 ffm->first_packet = 0; | |
91 } | |
92 | |
93 /* 'first' is true if first data of a frame */ | |
94 static void ffm_write_data(AVFormatContext *s, | |
241 | 95 const uint8_t *buf, int size, |
65 | 96 int64_t pts, int first) |
0 | 97 { |
98 FFMContext *ffm = s->priv_data; | |
99 int len; | |
100 | |
101 if (first && ffm->frame_offset == 0) | |
102 ffm->frame_offset = ffm->packet_ptr - ffm->packet + FFM_HEADER_SIZE; | |
103 if (first && ffm->pts == 0) | |
104 ffm->pts = pts; | |
105 | |
106 /* write as many packets as needed */ | |
107 while (size > 0) { | |
108 len = ffm->packet_end - ffm->packet_ptr; | |
109 if (len > size) | |
110 len = size; | |
111 memcpy(ffm->packet_ptr, buf, len); | |
112 | |
113 ffm->packet_ptr += len; | |
114 buf += len; | |
115 size -= len; | |
116 if (ffm->packet_ptr >= ffm->packet_end) { | |
117 /* special case : no pts in packet : we leave the current one */ | |
118 if (ffm->pts == 0) | |
119 ffm->pts = pts; | |
120 | |
121 flush_packet(s); | |
122 } | |
123 } | |
124 } | |
125 | |
126 static int ffm_write_header(AVFormatContext *s) | |
127 { | |
128 FFMContext *ffm = s->priv_data; | |
129 AVStream *st; | |
130 FFMStream *fst; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2222
diff
changeset
|
131 ByteIOContext *pb = s->pb; |
0 | 132 AVCodecContext *codec; |
133 int bit_rate, i; | |
134 | |
135 ffm->packet_size = FFM_PACKET_SIZE; | |
136 | |
137 /* header */ | |
862
aa0abab5e320
fix feed read_header, avoid using put_tag in write_header, to be consistent with read_header, also some minor cosmetics
alex
parents:
858
diff
changeset
|
138 put_le32(pb, MKTAG('F', 'F', 'M', '1')); |
0 | 139 put_be32(pb, ffm->packet_size); |
140 /* XXX: store write position in other file ? */ | |
141 put_be64(pb, ffm->packet_size); /* current write position */ | |
142 | |
143 put_be32(pb, s->nb_streams); | |
144 bit_rate = 0; | |
145 for(i=0;i<s->nb_streams;i++) { | |
146 st = s->streams[i]; | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
147 bit_rate += st->codec->bit_rate; |
0 | 148 } |
149 put_be32(pb, bit_rate); | |
150 | |
151 /* list of streams */ | |
152 for(i=0;i<s->nb_streams;i++) { | |
153 st = s->streams[i]; | |
154 fst = av_mallocz(sizeof(FFMStream)); | |
155 if (!fst) | |
156 goto fail; | |
502
813b0119a98e
ffserver fixes by (Koos Vriezen <koos.vriezen at xs4all dot nl>)
michael
parents:
468
diff
changeset
|
157 av_set_pts_info(st, 64, 1, 1000000); |
0 | 158 st->priv_data = fst; |
159 | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
160 codec = st->codec; |
0 | 161 /* generic info */ |
162 put_be32(pb, codec->codec_id); | |
163 put_byte(pb, codec->codec_type); | |
164 put_be32(pb, codec->bit_rate); | |
887 | 165 put_be32(pb, st->quality); |
0 | 166 put_be32(pb, codec->flags); |
744
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
167 put_be32(pb, codec->flags2); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
168 put_be32(pb, codec->debug); |
0 | 169 /* specific info */ |
170 switch(codec->codec_type) { | |
171 case CODEC_TYPE_VIDEO: | |
743 | 172 put_be32(pb, codec->time_base.num); |
173 put_be32(pb, codec->time_base.den); | |
0 | 174 put_be16(pb, codec->width); |
175 put_be16(pb, codec->height); | |
176 put_be16(pb, codec->gop_size); | |
744
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
177 put_be32(pb, codec->pix_fmt); |
0 | 178 put_byte(pb, codec->qmin); |
179 put_byte(pb, codec->qmax); | |
180 put_byte(pb, codec->max_qdiff); | |
181 put_be16(pb, (int) (codec->qcompress * 10000.0)); | |
182 put_be16(pb, (int) (codec->qblur * 10000.0)); | |
183 put_be32(pb, codec->bit_rate_tolerance); | |
184 put_strz(pb, codec->rc_eq); | |
185 put_be32(pb, codec->rc_max_rate); | |
186 put_be32(pb, codec->rc_min_rate); | |
187 put_be32(pb, codec->rc_buffer_size); | |
823 | 188 put_be64(pb, av_dbl2int(codec->i_quant_factor)); |
189 put_be64(pb, av_dbl2int(codec->b_quant_factor)); | |
190 put_be64(pb, av_dbl2int(codec->i_quant_offset)); | |
191 put_be64(pb, av_dbl2int(codec->b_quant_offset)); | |
0 | 192 put_be32(pb, codec->dct_algo); |
744
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
193 put_be32(pb, codec->strict_std_compliance); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
194 put_be32(pb, codec->max_b_frames); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
195 put_be32(pb, codec->luma_elim_threshold); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
196 put_be32(pb, codec->chroma_elim_threshold); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
197 put_be32(pb, codec->mpeg_quant); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
198 put_be32(pb, codec->intra_dc_precision); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
199 put_be32(pb, codec->me_method); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
200 put_be32(pb, codec->mb_decision); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
201 put_be32(pb, codec->nsse_weight); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
202 put_be32(pb, codec->frame_skip_cmp); |
823 | 203 put_be64(pb, av_dbl2int(codec->rc_buffer_aggressivity)); |
1809
491581a2b9a7
codec_tag settable via VideoTag, and transmit codec_tag in ffm
alex
parents:
1787
diff
changeset
|
204 put_be32(pb, codec->codec_tag); |
0 | 205 break; |
206 case CODEC_TYPE_AUDIO: | |
207 put_be32(pb, codec->sample_rate); | |
208 put_le16(pb, codec->channels); | |
209 put_le16(pb, codec->frame_size); | |
210 break; | |
211 default: | |
537 | 212 return -1; |
0 | 213 } |
214 /* hack to have real time */ | |
215 if (ffm_nopts) | |
216 fst->pts = 0; | |
217 else | |
218 fst->pts = av_gettime(); | |
219 } | |
220 | |
221 /* flush until end of block reached */ | |
222 while ((url_ftell(pb) % ffm->packet_size) != 0) | |
223 put_byte(pb, 0); | |
224 | |
225 put_flush_packet(pb); | |
226 | |
227 /* init packet mux */ | |
228 ffm->packet_ptr = ffm->packet; | |
229 ffm->packet_end = ffm->packet + ffm->packet_size - FFM_HEADER_SIZE; | |
537 | 230 assert(ffm->packet_end >= ffm->packet); |
0 | 231 ffm->frame_offset = 0; |
232 ffm->pts = 0; | |
233 ffm->first_packet = 1; | |
234 | |
235 return 0; | |
236 fail: | |
237 for(i=0;i<s->nb_streams;i++) { | |
238 st = s->streams[i]; | |
239 av_freep(&st->priv_data); | |
240 } | |
241 return -1; | |
242 } | |
243 | |
468 | 244 static int ffm_write_packet(AVFormatContext *s, AVPacket *pkt) |
0 | 245 { |
468 | 246 AVStream *st = s->streams[pkt->stream_index]; |
0 | 247 FFMStream *fst = st->priv_data; |
65 | 248 int64_t pts; |
249 uint8_t header[FRAME_HEADER_SIZE]; | |
468 | 250 int size= pkt->size; |
0 | 251 |
252 pts = fst->pts; | |
253 /* packet size & key_frame */ | |
468 | 254 header[0] = pkt->stream_index; |
0 | 255 header[1] = 0; |
468 | 256 if (pkt->flags & PKT_FLAG_KEY) |
0 | 257 header[1] |= FLAG_KEY_FRAME; |
3308 | 258 AV_WB24(header+2, size); |
3310 | 259 AV_WB24(header+5, pkt->duration); |
0 | 260 ffm_write_data(s, header, FRAME_HEADER_SIZE, pts, 1); |
468 | 261 ffm_write_data(s, pkt->data, size, pts, 0); |
0 | 262 |
3311 | 263 fst->pts += pkt->duration; |
0 | 264 return 0; |
265 } | |
266 | |
267 static int ffm_write_trailer(AVFormatContext *s) | |
268 { | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2222
diff
changeset
|
269 ByteIOContext *pb = s->pb; |
0 | 270 FFMContext *ffm = s->priv_data; |
271 | |
272 /* flush packets */ | |
273 if (ffm->packet_ptr > ffm->packet) | |
274 flush_packet(s); | |
275 | |
276 put_flush_packet(pb); | |
277 | |
278 if (!url_is_streamed(pb)) { | |
65 | 279 int64_t size; |
0 | 280 /* update the write offset */ |
281 size = url_ftell(pb); | |
282 url_fseek(pb, 8, SEEK_SET); | |
283 put_be64(pb, size); | |
284 put_flush_packet(pb); | |
285 } | |
286 | |
287 return 0; | |
288 } | |
858
66cc656ea404
Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents:
823
diff
changeset
|
289 #endif //CONFIG_MUXERS |
0 | 290 |
291 /* ffm demux */ | |
292 | |
293 static int ffm_is_avail_data(AVFormatContext *s, int size) | |
294 { | |
295 FFMContext *ffm = s->priv_data; | |
296 offset_t pos, avail_size; | |
297 int len; | |
298 | |
299 len = ffm->packet_end - ffm->packet_ptr; | |
300 if (!ffm_nopts) { | |
301 /* XXX: I don't understand this test, so I disabled it for testing */ | |
302 if (size <= len) | |
303 return 1; | |
304 } | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2222
diff
changeset
|
305 pos = url_ftell(s->pb); |
0 | 306 if (pos == ffm->write_index) { |
307 /* exactly at the end of stream */ | |
308 return 0; | |
309 } else if (pos < ffm->write_index) { | |
310 avail_size = ffm->write_index - pos; | |
311 } else { | |
312 avail_size = (ffm->file_size - pos) + (ffm->write_index - FFM_PACKET_SIZE); | |
313 } | |
314 avail_size = (avail_size / ffm->packet_size) * (ffm->packet_size - FFM_HEADER_SIZE) + len; | |
315 if (size <= avail_size) | |
316 return 1; | |
317 else | |
318 return 0; | |
319 } | |
320 | |
321 /* first is true if we read the frame header */ | |
322 static int ffm_read_data(AVFormatContext *s, | |
65 | 323 uint8_t *buf, int size, int first) |
0 | 324 { |
325 FFMContext *ffm = s->priv_data; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2222
diff
changeset
|
326 ByteIOContext *pb = s->pb; |
0 | 327 int len, fill_size, size1, frame_offset; |
328 | |
329 size1 = size; | |
330 while (size > 0) { | |
331 redo: | |
332 len = ffm->packet_end - ffm->packet_ptr; | |
333 if (len > size) | |
334 len = size; | |
335 if (len == 0) { | |
336 if (url_ftell(pb) == ffm->file_size) | |
337 url_fseek(pb, ffm->packet_size, SEEK_SET); | |
338 retry_read: | |
339 get_be16(pb); /* PACKET_ID */ | |
340 fill_size = get_be16(pb); | |
341 ffm->pts = get_be64(pb); | |
901
c1a07d63a66d
pts fix by (Bryan Mayland / bmayland O leoninedev o com)
michael
parents:
896
diff
changeset
|
342 ffm->first_frame_in_packet = 1; |
0 | 343 frame_offset = get_be16(pb); |
344 get_buffer(pb, ffm->packet, ffm->packet_size - FFM_HEADER_SIZE); | |
345 ffm->packet_end = ffm->packet + (ffm->packet_size - FFM_HEADER_SIZE - fill_size); | |
318
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
346 if (ffm->packet_end < ffm->packet) |
537 | 347 return -1; |
0 | 348 /* if first packet or resynchronization packet, we must |
349 handle it specifically */ | |
350 if (ffm->first_packet || (frame_offset & 0x8000)) { | |
351 if (!frame_offset) { | |
352 /* This packet has no frame headers in it */ | |
353 if (url_ftell(pb) >= ffm->packet_size * 3) { | |
354 url_fseek(pb, -ffm->packet_size * 2, SEEK_CUR); | |
355 goto retry_read; | |
356 } | |
357 /* This is bad, we cannot find a valid frame header */ | |
358 return 0; | |
359 } | |
360 ffm->first_packet = 0; | |
361 if ((frame_offset & 0x7ffff) < FFM_HEADER_SIZE) | |
537 | 362 return -1; |
0 | 363 ffm->packet_ptr = ffm->packet + (frame_offset & 0x7fff) - FFM_HEADER_SIZE; |
364 if (!first) | |
365 break; | |
366 } else { | |
367 ffm->packet_ptr = ffm->packet; | |
368 } | |
369 goto redo; | |
370 } | |
371 memcpy(buf, ffm->packet_ptr, len); | |
372 buf += len; | |
373 ffm->packet_ptr += len; | |
374 size -= len; | |
375 first = 0; | |
376 } | |
377 return size1 - size; | |
378 } | |
379 | |
380 | |
318
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
381 static void adjust_write_index(AVFormatContext *s) |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
382 { |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
383 FFMContext *ffm = s->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2222
diff
changeset
|
384 ByteIOContext *pb = s->pb; |
318
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
385 int64_t pts; |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
386 //offset_t orig_write_index = ffm->write_index; |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
387 offset_t pos_min, pos_max; |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
388 int64_t pts_start; |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
389 offset_t ptr = url_ftell(pb); |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
390 |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
391 |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
392 pos_min = 0; |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
393 pos_max = ffm->file_size - 2 * FFM_PACKET_SIZE; |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
394 |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
395 pts_start = get_pts(s, pos_min); |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
396 |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
397 pts = get_pts(s, pos_max); |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
398 |
885 | 399 if (pts - 100000 > pts_start) |
390
3a40642dc4df
adjust_write_index() fix by ("Curi Fabio Eduardo (SFL)" <curif at TELEFONICA dot COM dot AR>)
michael
parents:
318
diff
changeset
|
400 goto end; |
318
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
401 |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
402 ffm->write_index = FFM_PACKET_SIZE; |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
403 |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
404 pts_start = get_pts(s, pos_min); |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
405 |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
406 pts = get_pts(s, pos_max); |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
407 |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
408 if (pts - 100000 <= pts_start) { |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
409 while (1) { |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
410 offset_t newpos; |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
411 int64_t newpts; |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
412 |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
413 newpos = ((pos_max + pos_min) / (2 * FFM_PACKET_SIZE)) * FFM_PACKET_SIZE; |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
414 |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
415 if (newpos == pos_min) |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
416 break; |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
417 |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
418 newpts = get_pts(s, newpos); |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
419 |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
420 if (newpts - 100000 <= pts) { |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
421 pos_max = newpos; |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
422 pts = newpts; |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
423 } else { |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
424 pos_min = newpos; |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
425 } |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
426 } |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
427 ffm->write_index += pos_max; |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
428 } |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
429 |
1443
404048ea11bc
Replace most of the %lld and %llx by their (cleaner) PRI*64 counterparts.
diego
parents:
1415
diff
changeset
|
430 //printf("Adjusted write index from %"PRId64" to %"PRId64": pts=%0.6f\n", orig_write_index, ffm->write_index, pts / 1000000.); |
318
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
431 //printf("pts range %0.6f - %0.6f\n", get_pts(s, 0) / 1000000. , get_pts(s, ffm->file_size - 2 * FFM_PACKET_SIZE) / 1000000. ); |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
432 |
390
3a40642dc4df
adjust_write_index() fix by ("Curi Fabio Eduardo (SFL)" <curif at TELEFONICA dot COM dot AR>)
michael
parents:
318
diff
changeset
|
433 end: |
318
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
434 url_fseek(pb, ptr, SEEK_SET); |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
435 } |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
436 |
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
437 |
0 | 438 static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap) |
439 { | |
440 FFMContext *ffm = s->priv_data; | |
441 AVStream *st; | |
442 FFMStream *fst; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2222
diff
changeset
|
443 ByteIOContext *pb = s->pb; |
0 | 444 AVCodecContext *codec; |
187 | 445 int i, nb_streams; |
65 | 446 uint32_t tag; |
0 | 447 |
448 /* header */ | |
449 tag = get_le32(pb); | |
450 if (tag != MKTAG('F', 'F', 'M', '1')) | |
451 goto fail; | |
452 ffm->packet_size = get_be32(pb); | |
453 if (ffm->packet_size != FFM_PACKET_SIZE) | |
454 goto fail; | |
455 ffm->write_index = get_be64(pb); | |
456 /* get also filesize */ | |
457 if (!url_is_streamed(pb)) { | |
764
cdb845a57ae4
drop most url_fileno() calls (allows to use ByteIOContext directly in caller apps instead of URLProtocol)
aurel
parents:
751
diff
changeset
|
458 ffm->file_size = url_fsize(pb); |
318
54e915169d48
Add more resilience in reading ffm files. In particular, don't assume
philipjsg
parents:
277
diff
changeset
|
459 adjust_write_index(s); |
0 | 460 } else { |
1556 | 461 ffm->file_size = (UINT64_C(1) << 63) - 1; |
0 | 462 } |
463 | |
187 | 464 nb_streams = get_be32(pb); |
0 | 465 get_be32(pb); /* total bitrate */ |
466 /* read each stream */ | |
187 | 467 for(i=0;i<nb_streams;i++) { |
0 | 468 char rc_eq_buf[128]; |
469 | |
187 | 470 st = av_new_stream(s, 0); |
0 | 471 if (!st) |
472 goto fail; | |
473 fst = av_mallocz(sizeof(FFMStream)); | |
474 if (!fst) | |
475 goto fail; | |
862
aa0abab5e320
fix feed read_header, avoid using put_tag in write_header, to be consistent with read_header, also some minor cosmetics
alex
parents:
858
diff
changeset
|
476 s->streams[i] = st; |
885 | 477 |
468 | 478 av_set_pts_info(st, 64, 1, 1000000); |
885 | 479 |
0 | 480 st->priv_data = fst; |
481 | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
482 codec = st->codec; |
0 | 483 /* generic info */ |
862
aa0abab5e320
fix feed read_header, avoid using put_tag in write_header, to be consistent with read_header, also some minor cosmetics
alex
parents:
858
diff
changeset
|
484 codec->codec_id = get_be32(pb); |
aa0abab5e320
fix feed read_header, avoid using put_tag in write_header, to be consistent with read_header, also some minor cosmetics
alex
parents:
858
diff
changeset
|
485 codec->codec_type = get_byte(pb); /* codec_type */ |
0 | 486 codec->bit_rate = get_be32(pb); |
862
aa0abab5e320
fix feed read_header, avoid using put_tag in write_header, to be consistent with read_header, also some minor cosmetics
alex
parents:
858
diff
changeset
|
487 st->quality = get_be32(pb); |
0 | 488 codec->flags = get_be32(pb); |
744
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
489 codec->flags2 = get_be32(pb); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
490 codec->debug = get_be32(pb); |
0 | 491 /* specific info */ |
492 switch(codec->codec_type) { | |
493 case CODEC_TYPE_VIDEO: | |
743 | 494 codec->time_base.num = get_be32(pb); |
495 codec->time_base.den = get_be32(pb); | |
0 | 496 codec->width = get_be16(pb); |
497 codec->height = get_be16(pb); | |
498 codec->gop_size = get_be16(pb); | |
744
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
499 codec->pix_fmt = get_be32(pb); |
0 | 500 codec->qmin = get_byte(pb); |
501 codec->qmax = get_byte(pb); | |
502 codec->max_qdiff = get_byte(pb); | |
503 codec->qcompress = get_be16(pb) / 10000.0; | |
504 codec->qblur = get_be16(pb) / 10000.0; | |
505 codec->bit_rate_tolerance = get_be32(pb); | |
34 | 506 codec->rc_eq = av_strdup(get_strz(pb, rc_eq_buf, sizeof(rc_eq_buf))); |
0 | 507 codec->rc_max_rate = get_be32(pb); |
508 codec->rc_min_rate = get_be32(pb); | |
509 codec->rc_buffer_size = get_be32(pb); | |
823 | 510 codec->i_quant_factor = av_int2dbl(get_be64(pb)); |
511 codec->b_quant_factor = av_int2dbl(get_be64(pb)); | |
512 codec->i_quant_offset = av_int2dbl(get_be64(pb)); | |
513 codec->b_quant_offset = av_int2dbl(get_be64(pb)); | |
0 | 514 codec->dct_algo = get_be32(pb); |
744
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
515 codec->strict_std_compliance = get_be32(pb); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
516 codec->max_b_frames = get_be32(pb); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
517 codec->luma_elim_threshold = get_be32(pb); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
518 codec->chroma_elim_threshold = get_be32(pb); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
519 codec->mpeg_quant = get_be32(pb); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
520 codec->intra_dc_precision = get_be32(pb); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
521 codec->me_method = get_be32(pb); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
522 codec->mb_decision = get_be32(pb); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
523 codec->nsse_weight = get_be32(pb); |
da5b3b9e898e
Add in many fields that have been added to the Codec structure. This means
philipjsg
parents:
743
diff
changeset
|
524 codec->frame_skip_cmp = get_be32(pb); |
823 | 525 codec->rc_buffer_aggressivity = av_int2dbl(get_be64(pb)); |
1809
491581a2b9a7
codec_tag settable via VideoTag, and transmit codec_tag in ffm
alex
parents:
1787
diff
changeset
|
526 codec->codec_tag = get_be32(pb); |
0 | 527 break; |
528 case CODEC_TYPE_AUDIO: | |
529 codec->sample_rate = get_be32(pb); | |
530 codec->channels = get_le16(pb); | |
531 codec->frame_size = get_le16(pb); | |
532 break; | |
533 default: | |
534 goto fail; | |
535 } | |
536 | |
537 } | |
538 | |
539 /* get until end of block reached */ | |
540 while ((url_ftell(pb) % ffm->packet_size) != 0) | |
541 get_byte(pb); | |
542 | |
543 /* init packet demux */ | |
544 ffm->packet_ptr = ffm->packet; | |
545 ffm->packet_end = ffm->packet; | |
546 ffm->frame_offset = 0; | |
547 ffm->pts = 0; | |
548 ffm->read_state = READ_HEADER; | |
549 ffm->first_packet = 1; | |
550 return 0; | |
551 fail: | |
552 for(i=0;i<s->nb_streams;i++) { | |
553 st = s->streams[i]; | |
554 if (st) { | |
555 av_freep(&st->priv_data); | |
556 av_free(st); | |
557 } | |
558 } | |
559 return -1; | |
560 } | |
561 | |
562 /* return < 0 if eof */ | |
563 static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt) | |
564 { | |
565 int size; | |
566 FFMContext *ffm = s->priv_data; | |
567 int duration; | |
568 | |
569 switch(ffm->read_state) { | |
570 case READ_HEADER: | |
571 if (!ffm_is_avail_data(s, FRAME_HEADER_SIZE)) { | |
1787
eb16c64144ee
This fixes error handling for BeOS, removing the need for some ifdefs.
mmu_man
parents:
1556
diff
changeset
|
572 return AVERROR(EAGAIN); |
0 | 573 } |
574 #if 0 | |
1443
404048ea11bc
Replace most of the %lld and %llx by their (cleaner) PRI*64 counterparts.
diego
parents:
1415
diff
changeset
|
575 printf("pos=%08"PRIx64" spos=%"PRIx64", write_index=%"PRIx64" size=%"PRIx64"\n", |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2222
diff
changeset
|
576 url_ftell(s->pb), s->pb.pos, ffm->write_index, ffm->file_size); |
0 | 577 #endif |
885 | 578 if (ffm_read_data(s, ffm->header, FRAME_HEADER_SIZE, 1) != |
0 | 579 FRAME_HEADER_SIZE) |
1787
eb16c64144ee
This fixes error handling for BeOS, removing the need for some ifdefs.
mmu_man
parents:
1556
diff
changeset
|
580 return AVERROR(EAGAIN); |
0 | 581 #if 0 |
582 { | |
583 int i; | |
584 for(i=0;i<FRAME_HEADER_SIZE;i++) | |
585 printf("%02x ", ffm->header[i]); | |
586 printf("\n"); | |
587 } | |
588 #endif | |
589 ffm->read_state = READ_DATA; | |
590 /* fall thru */ | |
591 case READ_DATA: | |
2222 | 592 size = AV_RB24(ffm->header + 2); |
0 | 593 if (!ffm_is_avail_data(s, size)) { |
1787
eb16c64144ee
This fixes error handling for BeOS, removing the need for some ifdefs.
mmu_man
parents:
1556
diff
changeset
|
594 return AVERROR(EAGAIN); |
0 | 595 } |
596 | |
2222 | 597 duration = AV_RB24(ffm->header + 5); |
0 | 598 |
599 av_new_packet(pkt, size); | |
600 pkt->stream_index = ffm->header[0]; | |
3307
e4ff879325c0
check pkt stream index before returning packet, prevent segfault
bcoudurier
parents:
2915
diff
changeset
|
601 if ((unsigned)pkt->stream_index >= s->nb_streams) { |
e4ff879325c0
check pkt stream index before returning packet, prevent segfault
bcoudurier
parents:
2915
diff
changeset
|
602 av_log(s, AV_LOG_ERROR, "invalid stream index %d\n", pkt->stream_index); |
e4ff879325c0
check pkt stream index before returning packet, prevent segfault
bcoudurier
parents:
2915
diff
changeset
|
603 av_free_packet(pkt); |
e4ff879325c0
check pkt stream index before returning packet, prevent segfault
bcoudurier
parents:
2915
diff
changeset
|
604 ffm->read_state = READ_HEADER; |
e4ff879325c0
check pkt stream index before returning packet, prevent segfault
bcoudurier
parents:
2915
diff
changeset
|
605 return AVERROR(EAGAIN); |
e4ff879325c0
check pkt stream index before returning packet, prevent segfault
bcoudurier
parents:
2915
diff
changeset
|
606 } |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2222
diff
changeset
|
607 pkt->pos = url_ftell(s->pb); |
0 | 608 if (ffm->header[1] & FLAG_KEY_FRAME) |
609 pkt->flags |= PKT_FLAG_KEY; | |
610 | |
611 ffm->read_state = READ_HEADER; | |
612 if (ffm_read_data(s, pkt->data, size, 0) != size) { | |
613 /* bad case: desynchronized packet. we cancel all the packet loading */ | |
614 av_free_packet(pkt); | |
1787
eb16c64144ee
This fixes error handling for BeOS, removing the need for some ifdefs.
mmu_man
parents:
1556
diff
changeset
|
615 return AVERROR(EAGAIN); |
0 | 616 } |
901
c1a07d63a66d
pts fix by (Bryan Mayland / bmayland O leoninedev o com)
michael
parents:
896
diff
changeset
|
617 if (ffm->first_frame_in_packet) |
c1a07d63a66d
pts fix by (Bryan Mayland / bmayland O leoninedev o com)
michael
parents:
896
diff
changeset
|
618 { |
c1a07d63a66d
pts fix by (Bryan Mayland / bmayland O leoninedev o com)
michael
parents:
896
diff
changeset
|
619 pkt->pts = ffm->pts; |
c1a07d63a66d
pts fix by (Bryan Mayland / bmayland O leoninedev o com)
michael
parents:
896
diff
changeset
|
620 ffm->first_frame_in_packet = 0; |
c1a07d63a66d
pts fix by (Bryan Mayland / bmayland O leoninedev o com)
michael
parents:
896
diff
changeset
|
621 } |
0 | 622 pkt->duration = duration; |
623 break; | |
624 } | |
625 return 0; | |
626 } | |
627 | |
628 //#define DEBUG_SEEK | |
629 | |
630 /* pos is between 0 and file_size - FFM_PACKET_SIZE. It is translated | |
631 by the write position inside this function */ | |
632 static void ffm_seek1(AVFormatContext *s, offset_t pos1) | |
633 { | |
634 FFMContext *ffm = s->priv_data; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2222
diff
changeset
|
635 ByteIOContext *pb = s->pb; |
0 | 636 offset_t pos; |
637 | |
638 pos = pos1 + ffm->write_index; | |
639 if (pos >= ffm->file_size) | |
640 pos -= (ffm->file_size - FFM_PACKET_SIZE); | |
641 #ifdef DEBUG_SEEK | |
1443
404048ea11bc
Replace most of the %lld and %llx by their (cleaner) PRI*64 counterparts.
diego
parents:
1415
diff
changeset
|
642 printf("seek to %"PRIx64" -> %"PRIx64"\n", pos1, pos); |
0 | 643 #endif |
644 url_fseek(pb, pos, SEEK_SET); | |
645 } | |
646 | |
65 | 647 static int64_t get_pts(AVFormatContext *s, offset_t pos) |
0 | 648 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2222
diff
changeset
|
649 ByteIOContext *pb = s->pb; |
65 | 650 int64_t pts; |
0 | 651 |
652 ffm_seek1(s, pos); | |
653 url_fskip(pb, 4); | |
654 pts = get_be64(pb); | |
655 #ifdef DEBUG_SEEK | |
656 printf("pts=%0.6f\n", pts / 1000000.0); | |
657 #endif | |
658 return pts; | |
659 } | |
660 | |
661 /* seek to a given time in the file. The file read pointer is | |
2915 | 662 positioned at or before pts. XXX: the following code is quite |
0 | 663 approximative */ |
558 | 664 static int ffm_seek(AVFormatContext *s, int stream_index, int64_t wanted_pts, int flags) |
0 | 665 { |
666 FFMContext *ffm = s->priv_data; | |
667 offset_t pos_min, pos_max, pos; | |
65 | 668 int64_t pts_min, pts_max, pts; |
0 | 669 double pos1; |
670 | |
671 #ifdef DEBUG_SEEK | |
672 printf("wanted_pts=%0.6f\n", wanted_pts / 1000000.0); | |
673 #endif | |
674 /* find the position using linear interpolation (better than | |
675 dichotomy in typical cases) */ | |
676 pos_min = 0; | |
677 pos_max = ffm->file_size - 2 * FFM_PACKET_SIZE; | |
678 while (pos_min <= pos_max) { | |
679 pts_min = get_pts(s, pos_min); | |
680 pts_max = get_pts(s, pos_max); | |
681 /* linear interpolation */ | |
682 pos1 = (double)(pos_max - pos_min) * (double)(wanted_pts - pts_min) / | |
683 (double)(pts_max - pts_min); | |
65 | 684 pos = (((int64_t)pos1) / FFM_PACKET_SIZE) * FFM_PACKET_SIZE; |
0 | 685 if (pos <= pos_min) |
686 pos = pos_min; | |
687 else if (pos >= pos_max) | |
688 pos = pos_max; | |
689 pts = get_pts(s, pos); | |
690 /* check if we are lucky */ | |
691 if (pts == wanted_pts) { | |
692 goto found; | |
693 } else if (pts > wanted_pts) { | |
694 pos_max = pos - FFM_PACKET_SIZE; | |
695 } else { | |
696 pos_min = pos + FFM_PACKET_SIZE; | |
697 } | |
698 } | |
558 | 699 pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max; |
0 | 700 if (pos > 0) |
701 pos -= FFM_PACKET_SIZE; | |
702 found: | |
703 ffm_seek1(s, pos); | |
704 return 0; | |
705 } | |
706 | |
905
dbc0145bbf11
Add --disable-protocols option to configure to disable I/O protocol from
diego
parents:
901
diff
changeset
|
707 #ifdef CONFIG_FFSERVER |
0 | 708 offset_t ffm_read_write_index(int fd) |
709 { | |
65 | 710 uint8_t buf[8]; |
0 | 711 |
712 lseek(fd, 8, SEEK_SET); | |
713 read(fd, buf, 8); | |
2222 | 714 return AV_RB64(buf); |
0 | 715 } |
716 | |
717 void ffm_write_write_index(int fd, offset_t pos) | |
718 { | |
65 | 719 uint8_t buf[8]; |
0 | 720 int i; |
721 | |
722 for(i=0;i<8;i++) | |
723 buf[i] = (pos >> (56 - i * 8)) & 0xff; | |
724 lseek(fd, 8, SEEK_SET); | |
725 write(fd, buf, 8); | |
726 } | |
727 | |
728 void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size) | |
729 { | |
730 FFMContext *ffm = s->priv_data; | |
731 ffm->write_index = pos; | |
732 ffm->file_size = file_size; | |
733 } | |
905
dbc0145bbf11
Add --disable-protocols option to configure to disable I/O protocol from
diego
parents:
901
diff
changeset
|
734 #endif // CONFIG_FFSERVER |
0 | 735 |
736 static int ffm_read_close(AVFormatContext *s) | |
737 { | |
738 AVStream *st; | |
739 int i; | |
740 | |
741 for(i=0;i<s->nb_streams;i++) { | |
742 st = s->streams[i]; | |
743 av_freep(&st->priv_data); | |
744 } | |
745 return 0; | |
746 } | |
747 | |
748 static int ffm_probe(AVProbeData *p) | |
749 { | |
2001
1a3c9056982a
allocate 32 extra bytes at the end of the probe buffer and remove most probe buf_size checks
michael
parents:
1809
diff
changeset
|
750 if ( |
885 | 751 p->buf[0] == 'F' && p->buf[1] == 'F' && p->buf[2] == 'M' && |
0 | 752 p->buf[3] == '1') |
753 return AVPROBE_SCORE_MAX + 1; | |
754 return 0; | |
755 } | |
756 | |
1169 | 757 #ifdef CONFIG_FFM_DEMUXER |
758 AVInputFormat ffm_demuxer = { | |
0 | 759 "ffm", |
760 "ffm format", | |
761 sizeof(FFMContext), | |
762 ffm_probe, | |
763 ffm_read_header, | |
764 ffm_read_packet, | |
765 ffm_read_close, | |
766 ffm_seek, | |
767 }; | |
1169 | 768 #endif |
769 #ifdef CONFIG_FFM_MUXER | |
770 AVOutputFormat ffm_muxer = { | |
0 | 771 "ffm", |
772 "ffm format", | |
773 "", | |
774 "ffm", | |
775 sizeof(FFMContext), | |
776 /* not really used */ | |
777 CODEC_ID_MP2, | |
778 CODEC_ID_MPEG1VIDEO, | |
779 ffm_write_header, | |
780 ffm_write_packet, | |
781 ffm_write_trailer, | |
782 }; | |
1169 | 783 #endif //CONFIG_FFM_MUXER |