annotate ffm.c @ 2:06b1347b3c8e libavformat

fixed multidir compile
author bellard
date Fri, 29 Nov 2002 14:56:03 +0000
parents 05318cf2e886
children 39c4c4336486
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * FFM (ffserver live feed) encoder and decoder
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 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 <unistd.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 /* The FFM file is made of blocks of fixed size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 #define FFM_HEADER_SIZE 14
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 #define PACKET_ID 0x666d
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 /* each packet contains frames (which can span several packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 #define FRAME_HEADER_SIZE 8
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 #define FLAG_KEY_FRAME 0x01
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 typedef struct FFMStream {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 INT64 pts;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 } FFMStream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 enum {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 READ_HEADER,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 READ_DATA,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 typedef struct FFMContext {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 /* only reading mode */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 offset_t write_index, file_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 int read_state;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 UINT8 header[FRAME_HEADER_SIZE];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 /* read and write */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 int first_packet; /* true if first packet, needed to set the discontinuity tag */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 int packet_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 int frame_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 INT64 pts;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 UINT8 *packet_ptr, *packet_end;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 UINT8 packet[FFM_PACKET_SIZE];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 } FFMContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 /* disable pts hack for testing */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 int ffm_nopts = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 static void flush_packet(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 FFMContext *ffm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 int fill_size, h;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 fill_size = ffm->packet_end - ffm->packet_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 memset(ffm->packet_ptr, 0, fill_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 /* put header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 put_be16(pb, PACKET_ID);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 put_be16(pb, fill_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 put_be64(pb, ffm->pts);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 h = ffm->frame_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 if (ffm->first_packet)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 h |= 0x8000;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 put_be16(pb, h);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 put_buffer(pb, ffm->packet, ffm->packet_end - ffm->packet);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 /* prepare next packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 ffm->frame_offset = 0; /* no key frame */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 ffm->pts = 0; /* no pts */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 ffm->packet_ptr = ffm->packet;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 ffm->first_packet = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 /* 'first' is true if first data of a frame */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 static void ffm_write_data(AVFormatContext *s,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 UINT8 *buf, int size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 INT64 pts, int first)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 FFMContext *ffm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 int len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 if (first && ffm->frame_offset == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 ffm->frame_offset = ffm->packet_ptr - ffm->packet + FFM_HEADER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 if (first && ffm->pts == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 ffm->pts = pts;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 /* write as many packets as needed */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 while (size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 len = ffm->packet_end - ffm->packet_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 if (len > size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 len = size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 memcpy(ffm->packet_ptr, buf, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 ffm->packet_ptr += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 buf += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 size -= len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 if (ffm->packet_ptr >= ffm->packet_end) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 /* special case : no pts in packet : we leave the current one */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 if (ffm->pts == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 ffm->pts = pts;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 flush_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 static int ffm_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 FFMContext *ffm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 FFMStream *fst;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 AVCodecContext *codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 int bit_rate, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 ffm->packet_size = FFM_PACKET_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 /* header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 put_tag(pb, "FFM1");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 put_be32(pb, ffm->packet_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 /* XXX: store write position in other file ? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 put_be64(pb, ffm->packet_size); /* current write position */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 put_be32(pb, s->nb_streams);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 bit_rate = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 st = s->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 bit_rate += st->codec.bit_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 put_be32(pb, bit_rate);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 /* list of streams */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 st = s->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 fst = av_mallocz(sizeof(FFMStream));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 if (!fst)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 st->priv_data = fst;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 codec = &st->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150 /* generic info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151 put_be32(pb, codec->codec_id);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152 put_byte(pb, codec->codec_type);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 put_be32(pb, codec->bit_rate);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 put_be32(pb, codec->quality);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155 put_be32(pb, codec->flags);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 /* specific info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157 switch(codec->codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 put_be32(pb, (codec->frame_rate * 1000) / FRAME_RATE_BASE);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 put_be16(pb, codec->width);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 put_be16(pb, codec->height);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 put_be16(pb, codec->gop_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 put_byte(pb, codec->qmin);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 put_byte(pb, codec->qmax);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 put_byte(pb, codec->max_qdiff);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166 put_be16(pb, (int) (codec->qcompress * 10000.0));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 put_be16(pb, (int) (codec->qblur * 10000.0));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 put_be32(pb, codec->bit_rate_tolerance);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 put_strz(pb, codec->rc_eq);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 put_be32(pb, codec->rc_max_rate);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 put_be32(pb, codec->rc_min_rate);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 put_be32(pb, codec->rc_buffer_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 put_be64_double(pb, codec->i_quant_factor);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 put_be64_double(pb, codec->b_quant_factor);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 put_be64_double(pb, codec->i_quant_offset);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 put_be64_double(pb, codec->b_quant_offset);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 put_be32(pb, codec->dct_algo);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180 put_be32(pb, codec->sample_rate);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181 put_le16(pb, codec->channels);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 put_le16(pb, codec->frame_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 av_abort();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 /* hack to have real time */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 if (ffm_nopts)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 fst->pts = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 fst->pts = av_gettime();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 /* flush until end of block reached */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 while ((url_ftell(pb) % ffm->packet_size) != 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 put_byte(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 /* init packet mux */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 ffm->packet_ptr = ffm->packet;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 ffm->packet_end = ffm->packet + ffm->packet_size - FFM_HEADER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 ffm->frame_offset = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 ffm->pts = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 ffm->first_packet = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 st = s->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 av_freep(&st->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 static int ffm_write_packet(AVFormatContext *s, int stream_index,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 UINT8 *buf, int size, int force_pts)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 AVStream *st = s->streams[stream_index];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 FFMStream *fst = st->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 INT64 pts;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 UINT8 header[FRAME_HEADER_SIZE];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 int duration;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 if (st->codec.codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 duration = ((float)st->codec.frame_size / st->codec.sample_rate * 1000000.0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 duration = (1000000.0 * FRAME_RATE_BASE / (float)st->codec.frame_rate);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 pts = fst->pts;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 /* packet size & key_frame */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 header[0] = stream_index;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 header[1] = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 if (st->codec.key_frame)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 header[1] |= FLAG_KEY_FRAME;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 header[2] = (size >> 16) & 0xff;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 header[3] = (size >> 8) & 0xff;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 header[4] = size & 0xff;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 header[5] = (duration >> 16) & 0xff;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 header[6] = (duration >> 8) & 0xff;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 header[7] = duration & 0xff;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 ffm_write_data(s, header, FRAME_HEADER_SIZE, pts, 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 ffm_write_data(s, buf, size, pts, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 fst->pts += duration;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 static int ffm_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 FFMContext *ffm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 /* flush packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257 if (ffm->packet_ptr > ffm->packet)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 flush_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 if (!url_is_streamed(pb)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 INT64 size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 /* update the write offset */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 size = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 url_fseek(pb, 8, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267 put_be64(pb, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
268 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
270
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271 for(i=0;i<s->nb_streams;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272 av_freep(&s->streams[i]->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276 /* ffm demux */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 static int ffm_is_avail_data(AVFormatContext *s, int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 FFMContext *ffm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281 offset_t pos, avail_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282 int len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 len = ffm->packet_end - ffm->packet_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285 if (!ffm_nopts) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 /* XXX: I don't understand this test, so I disabled it for testing */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287 if (size <= len)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288 return 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 pos = url_ftell(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291 if (pos == ffm->write_index) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292 /* exactly at the end of stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 } else if (pos < ffm->write_index) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295 avail_size = ffm->write_index - pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
296 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
297 avail_size = (ffm->file_size - pos) + (ffm->write_index - FFM_PACKET_SIZE);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
298 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
299 avail_size = (avail_size / ffm->packet_size) * (ffm->packet_size - FFM_HEADER_SIZE) + len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300 if (size <= avail_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301 return 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
302 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
304 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
305
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306 /* first is true if we read the frame header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307 static int ffm_read_data(AVFormatContext *s,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
308 UINT8 *buf, int size, int first)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310 FFMContext *ffm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
311 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
312 int len, fill_size, size1, frame_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
313
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
314 size1 = size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315 while (size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316 redo:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
317 len = ffm->packet_end - ffm->packet_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318 if (len > size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
319 len = size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
320 if (len == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
321 if (url_ftell(pb) == ffm->file_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
322 url_fseek(pb, ffm->packet_size, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
323 retry_read:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
324 get_be16(pb); /* PACKET_ID */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
325 fill_size = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326 ffm->pts = get_be64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 frame_offset = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328 get_buffer(pb, ffm->packet, ffm->packet_size - FFM_HEADER_SIZE);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
329 ffm->packet_end = ffm->packet + (ffm->packet_size - FFM_HEADER_SIZE - fill_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330 /* if first packet or resynchronization packet, we must
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331 handle it specifically */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332 if (ffm->first_packet || (frame_offset & 0x8000)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333 if (!frame_offset) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334 /* This packet has no frame headers in it */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335 if (url_ftell(pb) >= ffm->packet_size * 3) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
336 url_fseek(pb, -ffm->packet_size * 2, SEEK_CUR);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337 goto retry_read;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339 /* This is bad, we cannot find a valid frame header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
340 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
341 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342 ffm->first_packet = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343 if ((frame_offset & 0x7ffff) < FFM_HEADER_SIZE)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
344 av_abort();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
345 ffm->packet_ptr = ffm->packet + (frame_offset & 0x7fff) - FFM_HEADER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
346 if (!first)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349 ffm->packet_ptr = ffm->packet;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351 goto redo;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
353 memcpy(buf, ffm->packet_ptr, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
354 buf += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
355 ffm->packet_ptr += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356 size -= len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357 first = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
358 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359 return size1 - size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
362
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363 static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
365 FFMContext *ffm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
366 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
367 FFMStream *fst;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
368 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
369 AVCodecContext *codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
370 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
371 UINT32 tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
372
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
373 /* header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
374 tag = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375 if (tag != MKTAG('F', 'F', 'M', '1'))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
377 ffm->packet_size = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
378 if (ffm->packet_size != FFM_PACKET_SIZE)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
379 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
380 ffm->write_index = get_be64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
381 /* get also filesize */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
382 if (!url_is_streamed(pb)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
383 ffm->file_size = url_filesize(url_fileno(pb));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
384 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
385 ffm->file_size = (UINT64_C(1) << 63) - 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
386 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
387
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
388 s->nb_streams = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
389 get_be32(pb); /* total bitrate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
390 /* read each stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
391 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392 char rc_eq_buf[128];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
393
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 st = av_mallocz(sizeof(AVStream));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395 if (!st)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
397 s->streams[i] = st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
398 fst = av_mallocz(sizeof(FFMStream));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399 if (!fst)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
400 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
401 st->priv_data = fst;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
402
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403 codec = &st->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404 /* generic info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405 st->codec.codec_id = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
406 st->codec.codec_type = get_byte(pb); /* codec_type */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
407 codec->bit_rate = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
408 codec->quality = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
409 codec->flags = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410 /* specific info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
411 switch(codec->codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 codec->frame_rate = ((INT64)get_be32(pb) * FRAME_RATE_BASE) / 1000;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 codec->width = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415 codec->height = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 codec->gop_size = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 codec->qmin = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 codec->qmax = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419 codec->max_qdiff = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420 codec->qcompress = get_be16(pb) / 10000.0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
421 codec->qblur = get_be16(pb) / 10000.0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
422 codec->bit_rate_tolerance = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 codec->rc_eq = strdup(get_strz(pb, rc_eq_buf, sizeof(rc_eq_buf)));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424 codec->rc_max_rate = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
425 codec->rc_min_rate = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
426 codec->rc_buffer_size = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427 codec->i_quant_factor = get_be64_double(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
428 codec->b_quant_factor = get_be64_double(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429 codec->i_quant_offset = get_be64_double(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
430 codec->b_quant_offset = get_be64_double(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
431 codec->dct_algo = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
433 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
434 codec->sample_rate = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435 codec->channels = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 codec->frame_size = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 /* get until end of block reached */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445 while ((url_ftell(pb) % ffm->packet_size) != 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 /* init packet demux */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449 ffm->packet_ptr = ffm->packet;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450 ffm->packet_end = ffm->packet;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451 ffm->frame_offset = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452 ffm->pts = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453 ffm->read_state = READ_HEADER;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
454 ffm->first_packet = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
456 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
457 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
458 st = s->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459 if (st) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
460 av_freep(&st->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461 av_free(st);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
462 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
464 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
465 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
466
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467 /* return < 0 if eof */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468 static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470 int size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
471 FFMContext *ffm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472 int duration;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
473
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
474 switch(ffm->read_state) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
475 case READ_HEADER:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
476 if (!ffm_is_avail_data(s, FRAME_HEADER_SIZE)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
477 return -EAGAIN;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
478 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
479 #if 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
480 printf("pos=%08Lx spos=%Lx, write_index=%Lx size=%Lx\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
481 url_ftell(&s->pb), s->pb.pos, ffm->write_index, ffm->file_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
482 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
483 if (ffm_read_data(s, ffm->header, FRAME_HEADER_SIZE, 1) !=
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
484 FRAME_HEADER_SIZE)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
485 return -EAGAIN;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
486 #if 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
487 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
488 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
489 for(i=0;i<FRAME_HEADER_SIZE;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
490 printf("%02x ", ffm->header[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
491 printf("\n");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
492 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
493 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
494 ffm->read_state = READ_DATA;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
495 /* fall thru */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
496 case READ_DATA:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
497 size = (ffm->header[2] << 16) | (ffm->header[3] << 8) | ffm->header[4];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
498 if (!ffm_is_avail_data(s, size)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
499 return -EAGAIN;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
500 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
501
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
502 duration = (ffm->header[5] << 16) | (ffm->header[6] << 8) | ffm->header[7];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
503
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
504 av_new_packet(pkt, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
505 pkt->stream_index = ffm->header[0];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
506 if (ffm->header[1] & FLAG_KEY_FRAME)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
507 pkt->flags |= PKT_FLAG_KEY;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
508
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
509 ffm->read_state = READ_HEADER;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
510 if (ffm_read_data(s, pkt->data, size, 0) != size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
511 /* bad case: desynchronized packet. we cancel all the packet loading */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
512 av_free_packet(pkt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
513 return -EAGAIN;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
514 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
515 pkt->pts = ffm->pts;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
516 pkt->duration = duration;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
517 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
518 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
519 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
520 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
521
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
522 //#define DEBUG_SEEK
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
523
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
524 /* pos is between 0 and file_size - FFM_PACKET_SIZE. It is translated
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
525 by the write position inside this function */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
526 static void ffm_seek1(AVFormatContext *s, offset_t pos1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
527 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
528 FFMContext *ffm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
529 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
530 offset_t pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
531
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
532 pos = pos1 + ffm->write_index;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
533 if (pos >= ffm->file_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
534 pos -= (ffm->file_size - FFM_PACKET_SIZE);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
535 #ifdef DEBUG_SEEK
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
536 printf("seek to %Lx -> %Lx\n", pos1, pos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
537 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
538 url_fseek(pb, pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
539 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
540
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
541 static INT64 get_pts(AVFormatContext *s, offset_t pos)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
542 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
543 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
544 INT64 pts;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
545
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
546 ffm_seek1(s, pos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
547 url_fskip(pb, 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
548 pts = get_be64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
549 #ifdef DEBUG_SEEK
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
550 printf("pts=%0.6f\n", pts / 1000000.0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
551 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
552 return pts;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
553 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
554
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
555 /* seek to a given time in the file. The file read pointer is
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
556 positionned at or before pts. XXX: the following code is quite
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
557 approximative */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
558 static int ffm_seek(AVFormatContext *s, INT64 wanted_pts)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
559 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
560 FFMContext *ffm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
561 offset_t pos_min, pos_max, pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
562 INT64 pts_min, pts_max, pts;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
563 double pos1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
564
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
565 #ifdef DEBUG_SEEK
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
566 printf("wanted_pts=%0.6f\n", wanted_pts / 1000000.0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
567 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
568 /* find the position using linear interpolation (better than
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
569 dichotomy in typical cases) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
570 pos_min = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
571 pos_max = ffm->file_size - 2 * FFM_PACKET_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
572 while (pos_min <= pos_max) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
573 pts_min = get_pts(s, pos_min);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
574 pts_max = get_pts(s, pos_max);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
575 /* linear interpolation */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
576 pos1 = (double)(pos_max - pos_min) * (double)(wanted_pts - pts_min) /
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
577 (double)(pts_max - pts_min);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
578 pos = (((INT64)pos1) / FFM_PACKET_SIZE) * FFM_PACKET_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
579 if (pos <= pos_min)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
580 pos = pos_min;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
581 else if (pos >= pos_max)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
582 pos = pos_max;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
583 pts = get_pts(s, pos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
584 /* check if we are lucky */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
585 if (pts == wanted_pts) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
586 goto found;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
587 } else if (pts > wanted_pts) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
588 pos_max = pos - FFM_PACKET_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
589 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
590 pos_min = pos + FFM_PACKET_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
591 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
592 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
593 pos = pos_min;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
594 if (pos > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
595 pos -= FFM_PACKET_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
596 found:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
597 ffm_seek1(s, pos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
598 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
599 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
600
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
601 offset_t ffm_read_write_index(int fd)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
602 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
603 UINT8 buf[8];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
604 offset_t pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
605 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
606
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
607 lseek(fd, 8, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
608 read(fd, buf, 8);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
609 pos = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
610 for(i=0;i<8;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
611 pos |= buf[i] << (56 - i * 8);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
612 return pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
613 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
614
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
615 void ffm_write_write_index(int fd, offset_t pos)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
616 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
617 UINT8 buf[8];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
618 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
619
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
620 for(i=0;i<8;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
621 buf[i] = (pos >> (56 - i * 8)) & 0xff;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
622 lseek(fd, 8, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
623 write(fd, buf, 8);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
624 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
625
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
626 void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
627 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
628 FFMContext *ffm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
629 ffm->write_index = pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
630 ffm->file_size = file_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
631 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
632
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
633 static int ffm_read_close(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
634 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
635 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
636 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
637
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
638 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
639 st = s->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
640 av_freep(&st->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
641 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
642 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
643 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
644
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
645 static int ffm_probe(AVProbeData *p)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
646 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
647 if (p->buf_size >= 4 &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
648 p->buf[0] == 'F' && p->buf[1] == 'F' && p->buf[2] == 'M' &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
649 p->buf[3] == '1')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
650 return AVPROBE_SCORE_MAX + 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
651 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
652 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
653
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
654 static AVInputFormat ffm_iformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
655 "ffm",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
656 "ffm format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
657 sizeof(FFMContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
658 ffm_probe,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
659 ffm_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
660 ffm_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
661 ffm_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
662 ffm_seek,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
663 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
664
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
665 static AVOutputFormat ffm_oformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
666 "ffm",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
667 "ffm format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
668 "",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
669 "ffm",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
670 sizeof(FFMContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
671 /* not really used */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
672 CODEC_ID_MP2,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
673 CODEC_ID_MPEG1VIDEO,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
674 ffm_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
675 ffm_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
676 ffm_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
677 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
678
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
679 int ffm_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
680 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
681 av_register_input_format(&ffm_iformat);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
682 av_register_output_format(&ffm_oformat);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
683 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
684 }