ape.c File Reference

#include <stdio.h>
#include "avformat.h"

Go to the source code of this file.

Data Structures

struct  APEFrame
struct  APEContext

Defines

#define ENABLE_DEBUG   0
#define APE_MIN_VERSION   3950
#define APE_MAX_VERSION   3990
#define MAC_FORMAT_FLAG_8_BIT   1
#define MAC_FORMAT_FLAG_CRC   2
#define MAC_FORMAT_FLAG_HAS_PEAK_LEVEL   4
#define MAC_FORMAT_FLAG_24_BIT   8
#define MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS   16
#define MAC_FORMAT_FLAG_CREATE_WAV_HEADER   32
#define MAC_SUBFRAME_SIZE   4608
#define APE_EXTRADATA_SIZE   6
#define APE_TAG_VERSION   2000
#define APE_TAG_FOOTER_BYTES   32
#define APE_TAG_FLAG_CONTAINS_HEADER   (1 << 31)
#define APE_TAG_FLAG_IS_HEADER   (1 << 29)
#define TAG(name, field)   {name, offsetof(AVFormatContext, field), sizeof(((AVFormatContext *)0)->field)}

Functions

static void ape_tag_read_field (AVFormatContext *s)
static void ape_parse_tag (AVFormatContext *s)
static int ape_probe (AVProbeData *p)
static void ape_dumpinfo (APEContext *ape_ctx)
static int ape_read_header (AVFormatContext *s, AVFormatParameters *ap)
static int ape_read_packet (AVFormatContext *s, AVPacket *pkt)
static int ape_read_close (AVFormatContext *s)
static int ape_read_seek (AVFormatContext *s, int stream_index, int64_t timestamp, int flags)

Variables

struct {
   const char *   name
   int   offset
   int   size
tags []
AVInputFormat ape_demuxer


Define Documentation

#define APE_EXTRADATA_SIZE   6

Definition at line 42 of file ape.c.

#define APE_MAX_VERSION   3990

Definition at line 31 of file ape.c.

Referenced by ape_read_header().

#define APE_MIN_VERSION   3950

Definition at line 30 of file ape.c.

Referenced by ape_read_header().

#define APE_TAG_FLAG_CONTAINS_HEADER   (1 << 31)

Definition at line 47 of file ape.c.

Referenced by ape_parse_tag().

#define APE_TAG_FLAG_IS_HEADER   (1 << 29)

Definition at line 48 of file ape.c.

Referenced by ape_parse_tag().

#define APE_TAG_FOOTER_BYTES   32

Definition at line 46 of file ape.c.

Referenced by ape_parse_tag().

#define APE_TAG_VERSION   2000

Definition at line 45 of file ape.c.

Referenced by ape_parse_tag().

#define ENABLE_DEBUG   0

Definition at line 27 of file ape.c.

#define MAC_FORMAT_FLAG_24_BIT   8

Definition at line 36 of file ape.c.

Referenced by ape_read_header().

#define MAC_FORMAT_FLAG_8_BIT   1

Definition at line 33 of file ape.c.

Referenced by ape_read_header().

#define MAC_FORMAT_FLAG_CRC   2

Definition at line 34 of file ape.c.

#define MAC_FORMAT_FLAG_CREATE_WAV_HEADER   32

Definition at line 38 of file ape.c.

Referenced by ape_read_header().

#define MAC_FORMAT_FLAG_HAS_PEAK_LEVEL   4

Definition at line 35 of file ape.c.

Referenced by ape_read_header().

#define MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS   16

Definition at line 37 of file ape.c.

Referenced by ape_read_header().

#define MAC_SUBFRAME_SIZE   4608

Definition at line 40 of file ape.c.

#define TAG ( name,
field   )     {name, offsetof(AVFormatContext, field), sizeof(((AVFormatContext *)0)->field)}

Definition at line 50 of file ape.c.


Function Documentation

static void ape_dumpinfo ( APEContext ape_ctx  )  [static]

Definition at line 215 of file ape.c.

References APEContext::audiodatalength, APEContext::audiodatalength_high, av_log(), AV_LOG_DEBUG, APEContext::blocksperframe, APEContext::bps, APEContext::channels, APEContext::compressiontype, APEContext::descriptorlength, APEContext::fileversion, APEContext::finalframeblocks, APEContext::firstframe, APEContext::formatflags, APEContext::frames, APEContext::headerlength, APEContext::junklength, APEContext::magic, APEContext::md5, APEFrame::nblocks, NULL, APEFrame::pos, APEContext::samplerate, APEContext::seektable, APEContext::seektablelength, APEFrame::size, APEContext::totalframes, APEContext::totalsamples, APEContext::wavheaderlength, and APEContext::wavtaillength.

00216 {
00217 #if ENABLE_DEBUG
00218     int i;
00219 
00220     av_log(NULL, AV_LOG_DEBUG, "Descriptor Block:\n\n");
00221     av_log(NULL, AV_LOG_DEBUG, "magic                = \"%c%c%c%c\"\n", ape_ctx->magic[0], ape_ctx->magic[1], ape_ctx->magic[2], ape_ctx->magic[3]);
00222     av_log(NULL, AV_LOG_DEBUG, "fileversion          = %d\n", ape_ctx->fileversion);
00223     av_log(NULL, AV_LOG_DEBUG, "descriptorlength     = %d\n", ape_ctx->descriptorlength);
00224     av_log(NULL, AV_LOG_DEBUG, "headerlength         = %d\n", ape_ctx->headerlength);
00225     av_log(NULL, AV_LOG_DEBUG, "seektablelength      = %d\n", ape_ctx->seektablelength);
00226     av_log(NULL, AV_LOG_DEBUG, "wavheaderlength      = %d\n", ape_ctx->wavheaderlength);
00227     av_log(NULL, AV_LOG_DEBUG, "audiodatalength      = %d\n", ape_ctx->audiodatalength);
00228     av_log(NULL, AV_LOG_DEBUG, "audiodatalength_high = %d\n", ape_ctx->audiodatalength_high);
00229     av_log(NULL, AV_LOG_DEBUG, "wavtaillength        = %d\n", ape_ctx->wavtaillength);
00230     av_log(NULL, AV_LOG_DEBUG, "md5                  = ");
00231     for (i = 0; i < 16; i++)
00232          av_log(NULL, AV_LOG_DEBUG, "%02x", ape_ctx->md5[i]);
00233     av_log(NULL, AV_LOG_DEBUG, "\n");
00234 
00235     av_log(NULL, AV_LOG_DEBUG, "\nHeader Block:\n\n");
00236 
00237     av_log(NULL, AV_LOG_DEBUG, "compressiontype      = %d\n", ape_ctx->compressiontype);
00238     av_log(NULL, AV_LOG_DEBUG, "formatflags          = %d\n", ape_ctx->formatflags);
00239     av_log(NULL, AV_LOG_DEBUG, "blocksperframe       = %d\n", ape_ctx->blocksperframe);
00240     av_log(NULL, AV_LOG_DEBUG, "finalframeblocks     = %d\n", ape_ctx->finalframeblocks);
00241     av_log(NULL, AV_LOG_DEBUG, "totalframes          = %d\n", ape_ctx->totalframes);
00242     av_log(NULL, AV_LOG_DEBUG, "bps                  = %d\n", ape_ctx->bps);
00243     av_log(NULL, AV_LOG_DEBUG, "channels             = %d\n", ape_ctx->channels);
00244     av_log(NULL, AV_LOG_DEBUG, "samplerate           = %d\n", ape_ctx->samplerate);
00245 
00246     av_log(NULL, AV_LOG_DEBUG, "\nSeektable\n\n");
00247     if ((ape_ctx->seektablelength / sizeof(uint32_t)) != ape_ctx->totalframes) {
00248         av_log(NULL, AV_LOG_DEBUG, "No seektable\n");
00249     } else {
00250         for (i = 0; i < ape_ctx->seektablelength / sizeof(uint32_t); i++) {
00251             if (i < ape_ctx->totalframes - 1) {
00252                 av_log(NULL, AV_LOG_DEBUG, "%8d   %d (%d bytes)\n", i, ape_ctx->seektable[i], ape_ctx->seektable[i + 1] - ape_ctx->seektable[i]);
00253             } else {
00254                 av_log(NULL, AV_LOG_DEBUG, "%8d   %d\n", i, ape_ctx->seektable[i]);
00255             }
00256         }
00257     }
00258 
00259     av_log(NULL, AV_LOG_DEBUG, "\nFrames\n\n");
00260     for (i = 0; i < ape_ctx->totalframes; i++)
00261         av_log(NULL, AV_LOG_DEBUG, "%8d   %8lld %8d (%d samples)\n", i, ape_ctx->frames[i].pos, ape_ctx->frames[i].size, ape_ctx->frames[i].nblocks);
00262 
00263     av_log(NULL, AV_LOG_DEBUG, "\nCalculated information:\n\n");
00264     av_log(NULL, AV_LOG_DEBUG, "junklength           = %d\n", ape_ctx->junklength);
00265     av_log(NULL, AV_LOG_DEBUG, "firstframe           = %d\n", ape_ctx->firstframe);
00266     av_log(NULL, AV_LOG_DEBUG, "totalsamples         = %d\n", ape_ctx->totalsamples);
00267 #endif
00268 }

static void ape_parse_tag ( AVFormatContext s  )  [static]

Definition at line 144 of file ape.c.

References AVFormatContext::album, APE_TAG_FLAG_CONTAINS_HEADER, APE_TAG_FLAG_IS_HEADER, APE_TAG_FOOTER_BYTES, ape_tag_read_field(), APE_TAG_VERSION, AVFormatContext::author, av_log(), AV_LOG_DEBUG, AV_LOG_ERROR, AVFormatContext::comment, AVFormatContext::copyright, AVFormatContext::genre, get_buffer(), get_le32(), NULL, AVFormatContext::pb, AVFormatContext::title, AVFormatContext::track, url_fseek(), url_fsize(), and AVFormatContext::year.

00145 {
00146     ByteIOContext *pb = s->pb;
00147     int file_size = url_fsize(pb);
00148     uint32_t val, fields, tag_bytes;
00149     uint8_t buf[8];
00150     int i;
00151 
00152     if (file_size < APE_TAG_FOOTER_BYTES)
00153         return;
00154 
00155     url_fseek(pb, file_size - APE_TAG_FOOTER_BYTES, SEEK_SET);
00156 
00157     get_buffer(pb, buf, 8);    /* APETAGEX */
00158     if (strncmp(buf, "APETAGEX", 8)) {
00159         return;
00160     }
00161 
00162     val = get_le32(pb);        /* APE tag version */
00163     if (val > APE_TAG_VERSION) {
00164         av_log(NULL, AV_LOG_ERROR, "Unsupported tag version. (>=%d)\n", APE_TAG_VERSION);
00165         return;
00166     }
00167 
00168     tag_bytes = get_le32(pb);  /* tag size */
00169     if (tag_bytes - APE_TAG_FOOTER_BYTES > (1024 * 1024 * 16)) {
00170         av_log(NULL, AV_LOG_ERROR, "Tag size is way too big\n");
00171         return;
00172     }
00173 
00174     fields = get_le32(pb);     /* number of fields */
00175     if (fields > 65536) {
00176         av_log(NULL, AV_LOG_ERROR, "Too many tag fields (%d)\n", fields);
00177         return;
00178     }
00179 
00180     val = get_le32(pb);        /* flags */
00181     if (val & APE_TAG_FLAG_IS_HEADER) {
00182         av_log(NULL, AV_LOG_ERROR, "APE Tag is a header\n");
00183         return;
00184     }
00185 
00186     if (val & APE_TAG_FLAG_CONTAINS_HEADER)
00187         tag_bytes += 2*APE_TAG_FOOTER_BYTES;
00188 
00189     url_fseek(pb, file_size - tag_bytes, SEEK_SET);
00190 
00191     for (i=0; i<fields; i++)
00192         ape_tag_read_field(s);
00193 
00194 #if ENABLE_DEBUG
00195     av_log(NULL, AV_LOG_DEBUG, "\nAPE Tags:\n\n");
00196     av_log(NULL, AV_LOG_DEBUG, "title     = %s\n", s->title);
00197     av_log(NULL, AV_LOG_DEBUG, "author    = %s\n", s->author);
00198     av_log(NULL, AV_LOG_DEBUG, "copyright = %s\n", s->copyright);
00199     av_log(NULL, AV_LOG_DEBUG, "comment   = %s\n", s->comment);
00200     av_log(NULL, AV_LOG_DEBUG, "album     = %s\n", s->album);
00201     av_log(NULL, AV_LOG_DEBUG, "year      = %d\n", s->year);
00202     av_log(NULL, AV_LOG_DEBUG, "track     = %d\n", s->track);
00203     av_log(NULL, AV_LOG_DEBUG, "genre     = %s\n", s->genre);
00204 #endif
00205 }

static int ape_probe ( AVProbeData p  )  [static]

Definition at line 207 of file ape.c.

References AVPROBE_SCORE_MAX, and AVProbeData::buf.

00208 {
00209     if (p->buf[0] == 'M' && p->buf[1] == 'A' && p->buf[2] == 'C' && p->buf[3] == ' ')
00210         return AVPROBE_SCORE_MAX;
00211 
00212     return 0;
00213 }

static int ape_read_close ( AVFormatContext s  )  [static]

Definition at line 490 of file ape.c.

References av_freep(), APEContext::frames, AVFormatContext::priv_data, and APEContext::seektable.

00491 {
00492     APEContext *ape = s->priv_data;
00493 
00494     av_freep(&ape->frames);
00495     av_freep(&ape->seektable);
00496     return 0;
00497 }

static int ape_read_header ( AVFormatContext s,
AVFormatParameters ap 
) [static]

Definition at line 270 of file ape.c.

References APE_MAX_VERSION, APE_MIN_VERSION, APEContext::audiodatalength, APEContext::audiodatalength_high, av_log(), AV_LOG_ERROR, av_malloc(), AVERROR_NOMEM, APEContext::blocksperframe, APEContext::bps, APEContext::channels, APEContext::compressiontype, APEContext::currentframe, APEContext::descriptorlength, APEContext::fileversion, APEContext::finalframeblocks, APEContext::firstframe, APEContext::formatflags, APEContext::frames, get_buffer(), get_le16(), get_le32(), APEContext::headerlength, APEContext::junklength, MAC_FORMAT_FLAG_24_BIT, MAC_FORMAT_FLAG_8_BIT, MAC_FORMAT_FLAG_CREATE_WAV_HEADER, MAC_FORMAT_FLAG_HAS_PEAK_LEVEL, MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS, APEContext::md5, MKTAG, APEFrame::nblocks, APEContext::padding1, AVFormatContext::pb, APEFrame::pos, AVFormatContext::priv_data, APEContext::samplerate, APEContext::seektable, APEContext::seektablelength, APEFrame::size, APEFrame::skip, APEContext::totalframes, APEContext::totalsamples, url_fseek(), url_fskip(), APEContext::wavheaderlength, and APEContext::wavtaillength.

00271 {
00272     ByteIOContext *pb = s->pb;
00273     APEContext *ape = s->priv_data;
00274     AVStream *st;
00275     uint32_t tag;
00276     int i;
00277     int total_blocks;
00278     int64_t pts;
00279 
00280     /* TODO: Skip any leading junk such as id3v2 tags */
00281     ape->junklength = 0;
00282 
00283     tag = get_le32(pb);
00284     if (tag != MKTAG('M', 'A', 'C', ' '))
00285         return -1;
00286 
00287     ape->fileversion = get_le16(pb);
00288 
00289     if (ape->fileversion < APE_MIN_VERSION || ape->fileversion > APE_MAX_VERSION) {
00290         av_log(s, AV_LOG_ERROR, "Unsupported file version - %d.%02d\n", ape->fileversion / 1000, (ape->fileversion % 1000) / 10);
00291         return -1;
00292     }
00293 
00294     if (ape->fileversion >= 3980) {
00295         ape->padding1             = get_le16(pb);
00296         ape->descriptorlength     = get_le32(pb);
00297         ape->headerlength         = get_le32(pb);
00298         ape->seektablelength      = get_le32(pb);
00299         ape->wavheaderlength      = get_le32(pb);
00300         ape->audiodatalength      = get_le32(pb);
00301         ape->audiodatalength_high = get_le32(pb);
00302         ape->wavtaillength        = get_le32(pb);
00303         get_buffer(pb, ape->md5, 16);
00304 
00305         /* Skip any unknown bytes at the end of the descriptor.
00306            This is for future compatibility */
00307         if (ape->descriptorlength > 52)
00308             url_fseek(pb, ape->descriptorlength - 52, SEEK_CUR);
00309 
00310         /* Read header data */
00311         ape->compressiontype      = get_le16(pb);
00312         ape->formatflags          = get_le16(pb);
00313         ape->blocksperframe       = get_le32(pb);
00314         ape->finalframeblocks     = get_le32(pb);
00315         ape->totalframes          = get_le32(pb);
00316         ape->bps                  = get_le16(pb);
00317         ape->channels             = get_le16(pb);
00318         ape->samplerate           = get_le32(pb);
00319     } else {
00320         ape->descriptorlength = 0;
00321         ape->headerlength = 32;
00322 
00323         ape->compressiontype      = get_le16(pb);
00324         ape->formatflags          = get_le16(pb);
00325         ape->channels             = get_le16(pb);
00326         ape->samplerate           = get_le32(pb);
00327         ape->wavheaderlength      = get_le32(pb);
00328         ape->wavtaillength        = get_le32(pb);
00329         ape->totalframes          = get_le32(pb);
00330         ape->finalframeblocks     = get_le32(pb);
00331 
00332         if (ape->formatflags & MAC_FORMAT_FLAG_HAS_PEAK_LEVEL) {
00333             url_fseek(pb, 4, SEEK_CUR); /* Skip the peak level */
00334             ape->headerlength += 4;
00335         }
00336 
00337         if (ape->formatflags & MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS) {
00338             ape->seektablelength = get_le32(pb);
00339             ape->headerlength += 4;
00340             ape->seektablelength *= sizeof(int32_t);
00341         } else
00342             ape->seektablelength = ape->totalframes * sizeof(int32_t);
00343 
00344         if (ape->formatflags & MAC_FORMAT_FLAG_8_BIT)
00345             ape->bps = 8;
00346         else if (ape->formatflags & MAC_FORMAT_FLAG_24_BIT)
00347             ape->bps = 24;
00348         else
00349             ape->bps = 16;
00350 
00351         if (ape->fileversion >= 3950)
00352             ape->blocksperframe = 73728 * 4;
00353         else if (ape->fileversion >= 3900 || (ape->fileversion >= 3800  && ape->compressiontype >= 4000))
00354             ape->blocksperframe = 73728;
00355         else
00356             ape->blocksperframe = 9216;
00357 
00358         /* Skip any stored wav header */
00359         if (!(ape->formatflags & MAC_FORMAT_FLAG_CREATE_WAV_HEADER))
00360             url_fskip(pb, ape->wavheaderlength);
00361     }
00362 
00363     if(ape->totalframes > UINT_MAX / sizeof(APEFrame)){
00364         av_log(s, AV_LOG_ERROR, "Too many frames: %d\n", ape->totalframes);
00365         return -1;
00366     }
00367     ape->frames       = av_malloc(ape->totalframes * sizeof(APEFrame));
00368     if(!ape->frames)
00369         return AVERROR_NOMEM;
00370     ape->firstframe   = ape->junklength + ape->descriptorlength + ape->headerlength + ape->seektablelength + ape->wavheaderlength;
00371     ape->currentframe = 0;
00372 
00373 
00374     ape->totalsamples = ape->finalframeblocks;
00375     if (ape->totalframes > 1)
00376         ape->totalsamples += ape->blocksperframe * (ape->totalframes - 1);
00377 
00378     if (ape->seektablelength > 0) {
00379         ape->seektable = av_malloc(ape->seektablelength);
00380         for (i = 0; i < ape->seektablelength / sizeof(uint32_t); i++)
00381             ape->seektable[i] = get_le32(pb);
00382     }
00383 
00384     ape->frames[0].pos     = ape->firstframe;
00385     ape->frames[0].nblocks = ape->blocksperframe;
00386     ape->frames[0].skip    = 0;
00387     for (i = 1; i < ape->totalframes; i++) {
00388         ape->frames[i].pos      = ape->seektable[i]; //ape->frames[i-1].pos + ape->blocksperframe;
00389         ape->frames[i].nblocks  = ape->blocksperframe;
00390         ape->frames[i - 1].size = ape->frames[i].pos - ape->frames[i - 1].pos;
00391         ape->frames[i].skip     = (ape->frames[i].pos - ape->frames[0].pos) & 3;
00392     }
00393     ape->frames[ape->totalframes - 1].size    = ape->finalframeblocks * 4;
00394     ape->frames[ape->totalframes - 1].nblocks = ape->finalframeblocks;
00395 
00396     for (i = 0; i < ape->totalframes; i++) {
00397         if(ape->frames[i].skip){
00398             ape->frames[i].pos  -= ape->frames[i].skip;
00399             ape->frames[i].size += ape->frames[i].skip;
00400         }
00401         ape->frames[i].size = (ape->frames[i].size + 3) & ~3;
00402     }
00403 
00404 
00405     ape_dumpinfo(ape);
00406 
00407     /* try to read APE tags */
00408     if (!url_is_streamed(pb)) {
00409         ape_parse_tag(s);
00410         url_fseek(pb, 0, SEEK_SET);
00411     }
00412 
00413     av_log(s, AV_LOG_DEBUG, "Decoding file - v%d.%02d, compression level %d\n", ape->fileversion / 1000, (ape->fileversion % 1000) / 10, ape->compressiontype);
00414 
00415     /* now we are ready: build format streams */
00416     st = av_new_stream(s, 0);
00417     if (!st)
00418         return -1;
00419 
00420     total_blocks = (ape->totalframes == 0) ? 0 : ((ape->totalframes - 1) * ape->blocksperframe) + ape->finalframeblocks;
00421 
00422     st->codec->codec_type      = CODEC_TYPE_AUDIO;
00423     st->codec->codec_id        = CODEC_ID_APE;
00424     st->codec->codec_tag       = MKTAG('A', 'P', 'E', ' ');
00425     st->codec->channels        = ape->channels;
00426     st->codec->sample_rate     = ape->samplerate;
00427     st->codec->bits_per_sample = ape->bps;
00428     st->codec->frame_size      = MAC_SUBFRAME_SIZE;
00429 
00430     st->nb_frames = ape->totalframes;
00431     s->start_time = 0;
00432     s->duration   = (int64_t) total_blocks * AV_TIME_BASE / ape->samplerate;
00433     av_set_pts_info(st, 64, MAC_SUBFRAME_SIZE, ape->samplerate);
00434 
00435     st->codec->extradata = av_malloc(APE_EXTRADATA_SIZE);
00436     st->codec->extradata_size = APE_EXTRADATA_SIZE;
00437     AV_WL16(st->codec->extradata + 0, ape->fileversion);
00438     AV_WL16(st->codec->extradata + 2, ape->compressiontype);
00439     AV_WL16(st->codec->extradata + 4, ape->formatflags);
00440 
00441     pts = 0;
00442     for (i = 0; i < ape->totalframes; i++) {
00443         ape->frames[i].pts = pts;
00444         av_add_index_entry(st, ape->frames[i].pos, ape->frames[i].pts, 0, 0, AVINDEX_KEYFRAME);
00445         pts += ape->blocksperframe / MAC_SUBFRAME_SIZE;
00446     }
00447 
00448     return 0;
00449 }

static int ape_read_packet ( AVFormatContext s,
AVPacket pkt 
) [static]

Definition at line 451 of file ape.c.

References av_new_packet(), AV_WL32, AVERROR_IO, AVERROR_NOMEM, APEContext::blocksperframe, APEContext::currentframe, AVPacket::data, extra_size, APEContext::finalframeblocks, APEContext::frames, get_buffer(), AVFormatContext::pb, APEFrame::pos, AVFormatContext::priv_data, APEFrame::pts, AVPacket::pts, AVPacket::size, APEFrame::size, APEFrame::skip, AVPacket::stream_index, APEContext::totalframes, url_feof(), and url_fseek().

00452 {
00453     int ret;
00454     int nblocks;
00455     APEContext *ape = s->priv_data;
00456     uint32_t extra_size = 8;
00457 
00458     if (url_feof(s->pb))
00459         return AVERROR_IO;
00460     if (ape->currentframe > ape->totalframes)
00461         return AVERROR_IO;
00462 
00463     url_fseek (s->pb, ape->frames[ape->currentframe].pos, SEEK_SET);
00464 
00465     /* Calculate how many blocks there are in this frame */
00466     if (ape->currentframe == (ape->totalframes - 1))
00467         nblocks = ape->finalframeblocks;
00468     else
00469         nblocks = ape->blocksperframe;
00470 
00471     if (av_new_packet(pkt,  ape->frames[ape->currentframe].size + extra_size) < 0)
00472         return AVERROR_NOMEM;
00473 
00474     AV_WL32(pkt->data    , nblocks);
00475     AV_WL32(pkt->data + 4, ape->frames[ape->currentframe].skip);
00476     ret = get_buffer(s->pb, pkt->data + extra_size, ape->frames[ape->currentframe].size);
00477 
00478     pkt->pts = ape->frames[ape->currentframe].pts;
00479     pkt->stream_index = 0;
00480 
00481     /* note: we need to modify the packet size here to handle the last
00482        packet */
00483     pkt->size = ret + extra_size;
00484 
00485     ape->currentframe++;
00486 
00487     return 0;
00488 }

static int ape_read_seek ( AVFormatContext s,
int  stream_index,
int64_t  timestamp,
int  flags 
) [static]

Definition at line 499 of file ape.c.

References av_index_search_timestamp(), APEContext::currentframe, AVFormatContext::priv_data, and AVFormatContext::streams.

00500 {
00501     AVStream *st = s->streams[stream_index];
00502     APEContext *ape = s->priv_data;
00503     int index = av_index_search_timestamp(st, timestamp, flags);
00504 
00505     if (index < 0)
00506         return -1;
00507 
00508     ape->currentframe = index;
00509     return 0;
00510 }

static void ape_tag_read_field ( AVFormatContext s  )  [static]

Definition at line 111 of file ape.c.

References ByteIOContext::buf_ptr, FFMIN, get_buffer(), get_le32(), name, offset, AVFormatContext::pb, size, tags, and url_fskip().

Referenced by ape_parse_tag().

00112 {
00113     ByteIOContext *pb = s->pb;
00114     uint8_t buf[1024];
00115     uint32_t size;
00116     int i;
00117 
00118     memset(buf, 0, 1024);
00119     size = get_le32(pb);  /* field size */
00120     url_fskip(pb, 4);     /* skip field flags */
00121 
00122     for (i=0; pb->buf_ptr[i]!='0' && pb->buf_ptr[i]>=0x20 && pb->buf_ptr[i]<=0x7E; i++);
00123 
00124     get_buffer(pb, buf, FFMIN(i, 1024));
00125     url_fskip(pb, 1);
00126 
00127     for (i=0; tags[i].name; i++)
00128         if (!strcmp (buf, tags[i].name)) {
00129             if (tags[i].size == sizeof(int)) {
00130                 char tmp[16];
00131                 get_buffer(pb, tmp, FFMIN(sizeof(tmp), size));
00132                 *(int *)(((char *)s)+tags[i].offset) = atoi(tmp);
00133             } else {
00134                 get_buffer(pb, ((char *)s) + tags[i].offset,
00135                            FFMIN(tags[i].size, size));
00136             }
00137             break;
00138         }
00139 
00140     if (!tags[i].name)
00141         url_fskip(pb, size);
00142 }


Variable Documentation

AVInputFormat ape_demuxer

Initial value:

 {
    "ape",
    NULL_IF_CONFIG_SMALL("Monkey's Audio"),
    sizeof(APEContext),
    ape_probe,
    ape_read_header,
    ape_read_packet,
    ape_read_close,
    ape_read_seek,
    .extensions = "ape,apl,mac"
}

Definition at line 512 of file ape.c.

const char* name

Definition at line 53 of file ape.c.

int offset

Definition at line 54 of file ape.c.

Referenced by adx_decode_header(), adx_encode_header(), aiff_read_header(), alloc_and_copy(), altivec_packIntArrayToCharArray(), ape_tag_read_field(), apply_window_and_mdct(), asf_read_packet(), av_estimate_timings_from_pts(), bfi_decode_frame(), bitplane_decoding(), chroma_4mv_motion(), chroma_4mv_motion_lowres(), cin_decode_lzss(), compute_pkt_fields(), decode_blockcode(), decode_bytes_and_gain(), decode_frame(), denoise_dct_mmx(), denoise_dct_sse2(), dnxhd_encode_picture(), dnxhd_init_vlc(), dnxhd_setup_threads_slices(), dv_frame_offset(), dv_read_seek(), encode_block(), encode_frame(), encode_init(), ff_draw_horiz_band(), ff_mpa_synth_filter(), ff_mspel_motion(), ff_rv34_decode_frame(), filter(), fixup_vorbis_headers(), flv_read_header(), get_intra_count(), gmc1_motion(), h263_mv4_search(), h264_luma_dc_dequant_idct_c(), h_block_filter(), hScale(), init_ref(), libextractor_applefile_extract(), libextractor_zip_extract(), matroska_add_stream(), motion_search(), mov_probe(), mov_read_trun(), mp_read_changes_map(), oggvorbis_encode_init(), ptx_decode_frame(), qdm2_fft_decode_tones(), read_braindead_odml_indx(), read_uncompressed_sgi(), rpl_read_header(), rv10_decode_frame(), sdp_parse_fmtp(), seq_decode_op3(), slice_buffer_load_line(), slice_buffer_release(), svq3_luma_dc_dequant_idct_c(), v_block_filter(), vorbis_floor1_decode(), vp56_get_vectors_predictors(), x11grab_read_header(), xan_unpack(), and yuv2yuvX_altivec_real().

int size

Definition at line 55 of file ape.c.

Referenced by aac_sync(), adx_encode_header(), aiff_read_header(), alloc_picture(), amr_read_packet(), ape_tag_read_field(), asf_read_header(), au_read_header(), audio_decode_example(), audio_write_packet(), av_fifo_size(), av_parser_change(), avcodec_default_get_buffer(), avpicture_alloc(), avpicture_layout(), avs_read_audio_packet(), avs_read_packet(), Configure(), createFingerprintFromQString(), daud_packet(), dca_subsubframe(), decode_frame(), decode_frame_header(), decode_sei(), dump_extradata(), dv1394_read_packet(), dv_extract_audio(), dv_extract_video_info(), dv_frame_offset(), dv_get_packet(), dv_inject_audio(), dv_produce_packet(), dv_read_packet(), dvvideo_init(), dxa_read_header(), dxa_read_packet(), ebml_read_ascii(), ebml_read_float(), ebml_read_sint(), ebml_read_uint(), encode_block(), encode_init(), encode_picture_ls(), escape_FF(), extract_mpeg4_header(), extractNGrams(), ff_er_frame_end(), ff_fill_pointer(), ff_isom_write_avcc(), ff_rm_read_mdpr_codecdata(), ff_rv34_decode_frame(), ffm_read_packet(), ffm_write_trailer(), find_tag(), flashsv_decode_frame(), flic_read_packet(), flush_packet(), flv_read_packet(), flv_write_packet(), fourxm_read_header(), fourxm_read_packet(), get_codec_data(), get_packetheader(), get_tag(), gxf_new_audio_packet(), gxf_write_mpeg_auxiliary(), h263_mv4_search(), http_send_data(), img_read_packet(), ingenient_read_packet(), interlaced_search(), jpeg_put_comments(), jpeg_table_header(), klv_decode_ber_length(), matroska_add_stream(), matroska_parse_blockgroup(), matroska_parse_cluster(), matroska_probe(), mkv_block_size(), mkv_blockgroup_size(), mov_read_dref(), mov_read_extradata(), mov_read_stsd(), mov_write_meta_tag(), mov_write_packet(), mov_write_string_tag(), mov_write_trkn_tag(), mp3_read_packet(), mpc8_parse_seektable(), mpc8_read_header(), mpc8_read_packet(), mpc_read_packet(), mpeg_mux_write_packet(), mpegps_read_pes_header(), mpegts_probe(), mpegts_write_packet(), msnwc_tcp_read_packet(), msrle_decode_pal4(), msrle_decode_pal8(), mxf_decrypt_triplet(), mxf_read_local_tags(), nuv_packet(), ogg_get_length(), ogg_new_buf(), ogg_read_page(), ogg_write_packet(), pre_process_video_frame(), Process(), Process0(), Process1(), process_ea_header(), processSO(), put_system_header(), qdm2_decode_init(), raw_read_packet(), raw_read_partial_packet(), read_arbitary(), rtp_write_packet(), rv10_decode_frame(), rv10_write_header(), sdp_read_header(), siff_read_packet(), smacker_read_packet(), sol_read_header(), svq3_decode_frame(), sws_scale(), thp_read_packet(), tm2_read_header(), tta_read_header(), tta_read_packet(),