Lines Matching defs:ape
165 APEContext *ape = s->priv_data;
173 ape->junklength = avio_tell(pb);
179 ape->fileversion = avio_rl16(pb);
181 if (ape->fileversion < APE_MIN_VERSION || ape->fileversion > APE_MAX_VERSION) {
183 ape->fileversion / 1000, (ape->fileversion % 1000) / 10);
187 if (ape->fileversion >= 3980) {
188 ape->padding1 = avio_rl16(pb);
189 ape->descriptorlength = avio_rl32(pb);
190 ape->headerlength = avio_rl32(pb);
191 ape->seektablelength = avio_rl32(pb);
192 ape->wavheaderlength = avio_rl32(pb);
193 ape->audiodatalength = avio_rl32(pb);
194 ape->audiodatalength_high = avio_rl32(pb);
195 ape->wavtaillength = avio_rl32(pb);
196 avio_read(pb, ape->md5, 16);
200 if (ape->descriptorlength > 52)
201 avio_skip(pb, ape->descriptorlength - 52);
204 ape->compressiontype = avio_rl16(pb);
205 ape->formatflags = avio_rl16(pb);
206 ape->blocksperframe = avio_rl32(pb);
207 ape->finalframeblocks = avio_rl32(pb);
208 ape->totalframes = avio_rl32(pb);
209 ape->bps = avio_rl16(pb);
210 ape->channels = avio_rl16(pb);
211 ape->samplerate = avio_rl32(pb);
213 ape->descriptorlength = 0;
214 ape->headerlength = 32;
216 ape->compressiontype = avio_rl16(pb);
217 ape->formatflags = avio_rl16(pb);
218 ape->channels = avio_rl16(pb);
219 ape->samplerate = avio_rl32(pb);
220 ape->wavheaderlength = avio_rl32(pb);
221 ape->wavtaillength = avio_rl32(pb);
222 ape->totalframes = avio_rl32(pb);
223 ape->finalframeblocks = avio_rl32(pb);
225 if (ape->formatflags & MAC_FORMAT_FLAG_HAS_PEAK_LEVEL) {
227 ape->headerlength += 4;
230 if (ape->formatflags & MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS) {
231 ape->seektablelength = avio_rl32(pb);
232 ape->headerlength += 4;
233 ape->seektablelength *= sizeof(int32_t);
235 ape->seektablelength = ape->totalframes * sizeof(int32_t);
237 if (ape->formatflags & MAC_FORMAT_FLAG_8_BIT)
238 ape->bps = 8;
239 else if (ape->formatflags & MAC_FORMAT_FLAG_24_BIT)
240 ape->bps = 24;
242 ape->bps = 16;
244 if (ape->fileversion >= 3950)
245 ape->blocksperframe = 73728 * 4;
246 else if (ape->fileversion >= 3900 || (ape->fileversion >= 3800 && ape->compressiontype >= 4000))
247 ape->blocksperframe = 73728;
249 ape->blocksperframe = 9216;
252 if (!(ape->formatflags & MAC_FORMAT_FLAG_CREATE_WAV_HEADER))
253 avio_skip(pb, ape->wavheaderlength);
256 if(!ape->totalframes){
260 if(ape->totalframes > UINT_MAX / sizeof(APEFrame)){
262 ape->totalframes);
265 if (ape->seektablelength / sizeof(*ape->seektable) < ape->totalframes) {
268 ape->seektablelength / sizeof(*ape->seektable), ape->totalframes);
271 ape->frames = av_malloc(ape->totalframes * sizeof(APEFrame));
272 if(!ape->frames)
274 ape->firstframe = ape->junklength + ape->descriptorlength + ape->headerlength + ape->seektablelength + ape->wavheaderlength;
275 if (ape->fileversion < 3810)
276 ape->firstframe += ape->totalframes;
277 ape->currentframe = 0;
280 ape->totalsamples = ape->finalframeblocks;
281 if (ape->totalframes > 1)
282 ape->totalsamples += ape->blocksperframe * (ape->totalframes - 1);
284 if (ape->seektablelength > 0) {
285 ape->seektable = av_mallocz(ape->seektablelength);
286 if (!ape->seektable)
288 for (i = 0; i < ape->seektablelength / sizeof(uint32_t) && !pb->eof_reached; i++)
289 ape->seektable[i] = avio_rl32(pb);
290 if (ape->fileversion < 3810) {
291 ape->bittable = av_mallocz(ape->totalframes);
292 if (!ape->bittable)
294 for (i = 0; i < ape->totalframes && !pb->eof_reached; i++)
295 ape->bittable[i] = avio_r8(pb);
301 ape->frames[0].pos = ape->firstframe;
302 ape->frames[0].nblocks = ape->blocksperframe;
303 ape->frames[0].skip = 0;
304 for (i = 1; i < ape->totalframes; i++) {
305 ape->frames[i].pos = ape->seektable[i] + ape->junklength;
306 ape->frames[i].nblocks = ape->blocksperframe;
307 ape->frames[i - 1].size = ape->frames[i].pos - ape->frames[i - 1].pos;
308 ape->frames[i].skip = (ape->frames[i].pos - ape->frames[0].pos) & 3;
310 ape->frames[ape->totalframes - 1].nblocks = ape->finalframeblocks;
314 final_size = file_size - ape->frames[ape->totalframes - 1].pos -
315 ape->wavtaillength;
319 final_size = ape->finalframeblocks * 8;
320 ape->frames[ape->totalframes - 1].size = final_size;
322 for (i = 0; i < ape->totalframes; i++) {
323 if(ape->frames[i].skip){
324 ape->frames[i].pos -= ape->frames[i].skip;
325 ape->frames[i].size += ape->frames[i].skip;
327 ape->frames[i].size = (ape->frames[i].size + 3) & ~3;
329 if (ape->fileversion < 3810) {
330 for (i = 0; i < ape->totalframes; i++) {
331 if (i < ape->totalframes - 1 && ape->bittable[i + 1])
332 ape->frames[i].size += 4;
333 ape->frames[i].skip <<= 3;
334 ape->frames[i].skip += ape->bittable[i];
338 ape_dumpinfo(s, ape);
341 ape->fileversion / 1000, (ape->fileversion % 1000) / 10,
342 ape->compressiontype);
349 total_blocks = (ape->totalframes == 0) ? 0 : ((ape->totalframes - 1) * ape->blocksperframe) + ape->finalframeblocks;
354 st->codec->channels = ape->channels;
355 st->codec->sample_rate = ape->samplerate;
356 st->codec->bits_per_coded_sample = ape->bps;
358 st->nb_frames = ape->totalframes;
361 avpriv_set_pts_info(st, 64, 1, ape->samplerate);
365 AV_WL16(st->codec->extradata + 0, ape->fileversion);
366 AV_WL16(st->codec->extradata + 2, ape->compressiontype);
367 AV_WL16(st->codec->extradata + 4, ape->formatflags);
370 for (i = 0; i < ape->totalframes; i++) {
371 ape->frames[i].pts = pts;
372 av_add_index_entry(st, ape->frames[i].pos, ape->frames[i].pts, 0, 0, AVINDEX_KEYFRAME);
373 pts += ape->blocksperframe;
389 APEContext *ape = s->priv_data;
394 if (ape->currentframe >= ape->totalframes)
397 if (avio_seek(s->pb, ape->frames[ape->currentframe].pos, SEEK_SET) < 0)
401 if (ape->currentframe == (ape->totalframes - 1))
402 nblocks = ape->finalframeblocks;
404 nblocks = ape->blocksperframe;
406 if (ape->frames[ape->currentframe].size <= 0 ||
407 ape->frames[ape->currentframe].size > INT_MAX - extra_size) {
409 ape->frames[ape->currentframe].size);
410 ape->currentframe++;
414 if (av_new_packet(pkt, ape->frames[ape->currentframe].size + extra_size) < 0)
418 AV_WL32(pkt->data + 4, ape->frames[ape->currentframe].skip);
419 ret = avio_read(s->pb, pkt->data + extra_size, ape->frames[ape->currentframe].size);
425 pkt->pts = ape->frames[ape->currentframe].pts;
432 ape->currentframe++;
439 APEContext *ape = s->priv_data;
441 av_freep(&ape->frames);
442 av_freep(&ape->seektable);
443 av_freep(&ape->bittable);
450 APEContext *ape = s->priv_data;
458 ape->currentframe = index;
463 .name = "ape",
471 .extensions = "ape,apl,mac",