annotate ape.c @ 6145:33fe8833a439 libavformat

RTSP: Don't store the connection handles in local variables This removes some useless copying of handles, and simplifies error handling. Patch by Josh Allmann, joshua dot allmann at gmail
author mstorsjo
date Sat, 19 Jun 2010 21:36:13 +0000
parents 08cd1179a20d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
1 /*
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
2 * Monkey's Audio APE demuxer
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
3 * Copyright (c) 2007 Benjamin Zores <ben@geexbox.org>
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
4 * based upon libdemac from Dave Chapman.
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
5 *
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
6 * This file is part of FFmpeg.
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
7 *
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
12 *
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
16 * Lesser General Public License for more details.
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
17 *
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
21 */
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
22
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
23 #include <stdio.h>
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
24
4201
7d2f3f1b68d8 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 3908
diff changeset
25 #include "libavutil/intreadwrite.h"
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
26 #include "avformat.h"
5134
6c0318c8a127 Move APE tag parsing into separate module.
kostya
parents: 5133
diff changeset
27 #include "apetag.h"
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
28
2556
cb131102b256 disable loads of debug messages to reduce object size
aurel
parents: 2554
diff changeset
29 #define ENABLE_DEBUG 0
cb131102b256 disable loads of debug messages to reduce object size
aurel
parents: 2554
diff changeset
30
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
31 /* The earliest and latest file formats supported by this library */
2568
59f7ce8ad381 Looks like this APE decoder support versions starting from 3.95
kostya
parents: 2556
diff changeset
32 #define APE_MIN_VERSION 3950
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
33 #define APE_MAX_VERSION 3990
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
34
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
35 #define MAC_FORMAT_FLAG_8_BIT 1 // is 8-bit [OBSOLETE]
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
36 #define MAC_FORMAT_FLAG_CRC 2 // uses the new CRC32 error detection [OBSOLETE]
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
37 #define MAC_FORMAT_FLAG_HAS_PEAK_LEVEL 4 // uint32 nPeakLevel after the header [OBSOLETE]
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
38 #define MAC_FORMAT_FLAG_24_BIT 8 // is 24-bit [OBSOLETE]
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
39 #define MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS 16 // has the number of seek elements after the peak level
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
40 #define MAC_FORMAT_FLAG_CREATE_WAV_HEADER 32 // create the wave header on decompression (not stored)
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
41
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
42 #define MAC_SUBFRAME_SIZE 4608
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
43
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
44 #define APE_EXTRADATA_SIZE 6
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
45
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
46 typedef struct {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
47 int64_t pos;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
48 int nblocks;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
49 int size;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
50 int skip;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
51 int64_t pts;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
52 } APEFrame;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
53
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
54 typedef struct {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
55 /* Derived fields */
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
56 uint32_t junklength;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
57 uint32_t firstframe;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
58 uint32_t totalsamples;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
59 int currentframe;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
60 APEFrame *frames;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
61
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
62 /* Info from Descriptor Block */
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
63 char magic[4];
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
64 int16_t fileversion;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
65 int16_t padding1;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
66 uint32_t descriptorlength;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
67 uint32_t headerlength;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
68 uint32_t seektablelength;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
69 uint32_t wavheaderlength;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
70 uint32_t audiodatalength;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
71 uint32_t audiodatalength_high;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
72 uint32_t wavtaillength;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
73 uint8_t md5[16];
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
74
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
75 /* Info from Header Block */
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
76 uint16_t compressiontype;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
77 uint16_t formatflags;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
78 uint32_t blocksperframe;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
79 uint32_t finalframeblocks;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
80 uint32_t totalframes;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
81 uint16_t bps;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
82 uint16_t channels;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
83 uint32_t samplerate;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
84
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
85 /* Seektable */
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
86 uint32_t *seektable;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
87 } APEContext;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
88
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
89 static int ape_probe(AVProbeData * p)
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
90 {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
91 if (p->buf[0] == 'M' && p->buf[1] == 'A' && p->buf[2] == 'C' && p->buf[3] == ' ')
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
92 return AVPROBE_SCORE_MAX;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
93
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
94 return 0;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
95 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
96
4506
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
97 static void ape_dumpinfo(AVFormatContext * s, APEContext * ape_ctx)
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
98 {
2556
cb131102b256 disable loads of debug messages to reduce object size
aurel
parents: 2554
diff changeset
99 #if ENABLE_DEBUG
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
100 int i;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
101
4506
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
102 av_log(s, AV_LOG_DEBUG, "Descriptor Block:\n\n");
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
103 av_log(s, 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]);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
104 av_log(s, AV_LOG_DEBUG, "fileversion = %d\n", ape_ctx->fileversion);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
105 av_log(s, AV_LOG_DEBUG, "descriptorlength = %d\n", ape_ctx->descriptorlength);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
106 av_log(s, AV_LOG_DEBUG, "headerlength = %d\n", ape_ctx->headerlength);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
107 av_log(s, AV_LOG_DEBUG, "seektablelength = %d\n", ape_ctx->seektablelength);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
108 av_log(s, AV_LOG_DEBUG, "wavheaderlength = %d\n", ape_ctx->wavheaderlength);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
109 av_log(s, AV_LOG_DEBUG, "audiodatalength = %d\n", ape_ctx->audiodatalength);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
110 av_log(s, AV_LOG_DEBUG, "audiodatalength_high = %d\n", ape_ctx->audiodatalength_high);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
111 av_log(s, AV_LOG_DEBUG, "wavtaillength = %d\n", ape_ctx->wavtaillength);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
112 av_log(s, AV_LOG_DEBUG, "md5 = ");
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
113 for (i = 0; i < 16; i++)
4506
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
114 av_log(s, AV_LOG_DEBUG, "%02x", ape_ctx->md5[i]);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
115 av_log(s, AV_LOG_DEBUG, "\n");
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
116
4506
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
117 av_log(s, AV_LOG_DEBUG, "\nHeader Block:\n\n");
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
118
4506
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
119 av_log(s, AV_LOG_DEBUG, "compressiontype = %d\n", ape_ctx->compressiontype);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
120 av_log(s, AV_LOG_DEBUG, "formatflags = %d\n", ape_ctx->formatflags);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
121 av_log(s, AV_LOG_DEBUG, "blocksperframe = %d\n", ape_ctx->blocksperframe);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
122 av_log(s, AV_LOG_DEBUG, "finalframeblocks = %d\n", ape_ctx->finalframeblocks);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
123 av_log(s, AV_LOG_DEBUG, "totalframes = %d\n", ape_ctx->totalframes);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
124 av_log(s, AV_LOG_DEBUG, "bps = %d\n", ape_ctx->bps);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
125 av_log(s, AV_LOG_DEBUG, "channels = %d\n", ape_ctx->channels);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
126 av_log(s, AV_LOG_DEBUG, "samplerate = %d\n", ape_ctx->samplerate);
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
127
4506
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
128 av_log(s, AV_LOG_DEBUG, "\nSeektable\n\n");
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
129 if ((ape_ctx->seektablelength / sizeof(uint32_t)) != ape_ctx->totalframes) {
4506
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
130 av_log(s, AV_LOG_DEBUG, "No seektable\n");
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
131 } else {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
132 for (i = 0; i < ape_ctx->seektablelength / sizeof(uint32_t); i++) {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
133 if (i < ape_ctx->totalframes - 1) {
4506
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
134 av_log(s, AV_LOG_DEBUG, "%8d %d (%d bytes)\n", i, ape_ctx->seektable[i], ape_ctx->seektable[i + 1] - ape_ctx->seektable[i]);
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
135 } else {
4506
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
136 av_log(s, AV_LOG_DEBUG, "%8d %d\n", i, ape_ctx->seektable[i]);
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
137 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
138 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
139 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
140
4506
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
141 av_log(s, AV_LOG_DEBUG, "\nFrames\n\n");
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
142 for (i = 0; i < ape_ctx->totalframes; i++)
4506
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
143 av_log(s, 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);
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
144
4506
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
145 av_log(s, AV_LOG_DEBUG, "\nCalculated information:\n\n");
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
146 av_log(s, AV_LOG_DEBUG, "junklength = %d\n", ape_ctx->junklength);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
147 av_log(s, AV_LOG_DEBUG, "firstframe = %d\n", ape_ctx->firstframe);
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
148 av_log(s, AV_LOG_DEBUG, "totalsamples = %d\n", ape_ctx->totalsamples);
2556
cb131102b256 disable loads of debug messages to reduce object size
aurel
parents: 2554
diff changeset
149 #endif
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
150 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
151
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
152 static int ape_read_header(AVFormatContext * s, AVFormatParameters * ap)
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
153 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2568
diff changeset
154 ByteIOContext *pb = s->pb;
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
155 APEContext *ape = s->priv_data;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
156 AVStream *st;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
157 uint32_t tag;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
158 int i;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
159 int total_blocks;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
160 int64_t pts;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
161
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
162 /* TODO: Skip any leading junk such as id3v2 tags */
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
163 ape->junklength = 0;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
164
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
165 tag = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
166 if (tag != MKTAG('M', 'A', 'C', ' '))
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
167 return -1;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
168
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
169 ape->fileversion = get_le16(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
170
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
171 if (ape->fileversion < APE_MIN_VERSION || ape->fileversion > APE_MAX_VERSION) {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
172 av_log(s, AV_LOG_ERROR, "Unsupported file version - %d.%02d\n", ape->fileversion / 1000, (ape->fileversion % 1000) / 10);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
173 return -1;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
174 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
175
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
176 if (ape->fileversion >= 3980) {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
177 ape->padding1 = get_le16(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
178 ape->descriptorlength = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
179 ape->headerlength = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
180 ape->seektablelength = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
181 ape->wavheaderlength = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
182 ape->audiodatalength = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
183 ape->audiodatalength_high = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
184 ape->wavtaillength = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
185 get_buffer(pb, ape->md5, 16);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
186
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
187 /* Skip any unknown bytes at the end of the descriptor.
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
188 This is for future compatibility */
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
189 if (ape->descriptorlength > 52)
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
190 url_fseek(pb, ape->descriptorlength - 52, SEEK_CUR);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
191
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
192 /* Read header data */
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
193 ape->compressiontype = get_le16(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
194 ape->formatflags = get_le16(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
195 ape->blocksperframe = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
196 ape->finalframeblocks = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
197 ape->totalframes = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
198 ape->bps = get_le16(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
199 ape->channels = get_le16(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
200 ape->samplerate = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
201 } else {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
202 ape->descriptorlength = 0;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
203 ape->headerlength = 32;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
204
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
205 ape->compressiontype = get_le16(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
206 ape->formatflags = get_le16(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
207 ape->channels = get_le16(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
208 ape->samplerate = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
209 ape->wavheaderlength = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
210 ape->wavtaillength = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
211 ape->totalframes = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
212 ape->finalframeblocks = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
213
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
214 if (ape->formatflags & MAC_FORMAT_FLAG_HAS_PEAK_LEVEL) {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
215 url_fseek(pb, 4, SEEK_CUR); /* Skip the peak level */
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
216 ape->headerlength += 4;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
217 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
218
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
219 if (ape->formatflags & MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS) {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
220 ape->seektablelength = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
221 ape->headerlength += 4;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
222 ape->seektablelength *= sizeof(int32_t);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
223 } else
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
224 ape->seektablelength = ape->totalframes * sizeof(int32_t);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
225
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
226 if (ape->formatflags & MAC_FORMAT_FLAG_8_BIT)
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
227 ape->bps = 8;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
228 else if (ape->formatflags & MAC_FORMAT_FLAG_24_BIT)
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
229 ape->bps = 24;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
230 else
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
231 ape->bps = 16;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
232
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
233 if (ape->fileversion >= 3950)
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
234 ape->blocksperframe = 73728 * 4;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
235 else if (ape->fileversion >= 3900 || (ape->fileversion >= 3800 && ape->compressiontype >= 4000))
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
236 ape->blocksperframe = 73728;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
237 else
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
238 ape->blocksperframe = 9216;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
239
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
240 /* Skip any stored wav header */
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
241 if (!(ape->formatflags & MAC_FORMAT_FLAG_CREATE_WAV_HEADER))
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
242 url_fskip(pb, ape->wavheaderlength);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
243 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
244
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
245 if(ape->totalframes > UINT_MAX / sizeof(APEFrame)){
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
246 av_log(s, AV_LOG_ERROR, "Too many frames: %d\n", ape->totalframes);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
247 return -1;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
248 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
249 ape->frames = av_malloc(ape->totalframes * sizeof(APEFrame));
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
250 if(!ape->frames)
5930
08cd1179a20d Replace all remaining occurrences of AVERROR_NOMEM with
stefano
parents: 5910
diff changeset
251 return AVERROR(ENOMEM);
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
252 ape->firstframe = ape->junklength + ape->descriptorlength + ape->headerlength + ape->seektablelength + ape->wavheaderlength;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
253 ape->currentframe = 0;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
254
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
255
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
256 ape->totalsamples = ape->finalframeblocks;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
257 if (ape->totalframes > 1)
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
258 ape->totalsamples += ape->blocksperframe * (ape->totalframes - 1);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
259
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
260 if (ape->seektablelength > 0) {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
261 ape->seektable = av_malloc(ape->seektablelength);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
262 for (i = 0; i < ape->seektablelength / sizeof(uint32_t); i++)
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
263 ape->seektable[i] = get_le32(pb);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
264 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
265
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
266 ape->frames[0].pos = ape->firstframe;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
267 ape->frames[0].nblocks = ape->blocksperframe;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
268 ape->frames[0].skip = 0;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
269 for (i = 1; i < ape->totalframes; i++) {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
270 ape->frames[i].pos = ape->seektable[i]; //ape->frames[i-1].pos + ape->blocksperframe;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
271 ape->frames[i].nblocks = ape->blocksperframe;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
272 ape->frames[i - 1].size = ape->frames[i].pos - ape->frames[i - 1].pos;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
273 ape->frames[i].skip = (ape->frames[i].pos - ape->frames[0].pos) & 3;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
274 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
275 ape->frames[ape->totalframes - 1].size = ape->finalframeblocks * 4;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
276 ape->frames[ape->totalframes - 1].nblocks = ape->finalframeblocks;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
277
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
278 for (i = 0; i < ape->totalframes; i++) {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
279 if(ape->frames[i].skip){
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
280 ape->frames[i].pos -= ape->frames[i].skip;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
281 ape->frames[i].size += ape->frames[i].skip;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
282 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
283 ape->frames[i].size = (ape->frames[i].size + 3) & ~3;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
284 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
285
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
286
4506
dfb8f047b552 Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents: 4201
diff changeset
287 ape_dumpinfo(s, ape);
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
288
2554
2d6bfd63d606 monkey audio demuxer now can parse ape tags
ben
parents: 2548
diff changeset
289 /* try to read APE tags */
2d6bfd63d606 monkey audio demuxer now can parse ape tags
ben
parents: 2548
diff changeset
290 if (!url_is_streamed(pb)) {
5134
6c0318c8a127 Move APE tag parsing into separate module.
kostya
parents: 5133
diff changeset
291 ff_ape_parse_tag(s);
2554
2d6bfd63d606 monkey audio demuxer now can parse ape tags
ben
parents: 2548
diff changeset
292 url_fseek(pb, 0, SEEK_SET);
2d6bfd63d606 monkey audio demuxer now can parse ape tags
ben
parents: 2548
diff changeset
293 }
2d6bfd63d606 monkey audio demuxer now can parse ape tags
ben
parents: 2548
diff changeset
294
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
295 av_log(s, AV_LOG_DEBUG, "Decoding file - v%d.%02d, compression level %d\n", ape->fileversion / 1000, (ape->fileversion % 1000) / 10, ape->compressiontype);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
296
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
297 /* now we are ready: build format streams */
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
298 st = av_new_stream(s, 0);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
299 if (!st)
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
300 return -1;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
301
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
302 total_blocks = (ape->totalframes == 0) ? 0 : ((ape->totalframes - 1) * ape->blocksperframe) + ape->finalframeblocks;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
303
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5834
diff changeset
304 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
305 st->codec->codec_id = CODEC_ID_APE;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
306 st->codec->codec_tag = MKTAG('A', 'P', 'E', ' ');
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
307 st->codec->channels = ape->channels;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
308 st->codec->sample_rate = ape->samplerate;
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3424
diff changeset
309 st->codec->bits_per_coded_sample = ape->bps;
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
310 st->codec->frame_size = MAC_SUBFRAME_SIZE;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
311
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
312 st->nb_frames = ape->totalframes;
5566
28094e9bd013 Set start_time and duration in AVStream instead of AVFormatContext for
conrad
parents: 5134
diff changeset
313 st->start_time = 0;
28094e9bd013 Set start_time and duration in AVStream instead of AVFormatContext for
conrad
parents: 5134
diff changeset
314 st->duration = total_blocks / MAC_SUBFRAME_SIZE;
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
315 av_set_pts_info(st, 64, MAC_SUBFRAME_SIZE, ape->samplerate);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
316
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
317 st->codec->extradata = av_malloc(APE_EXTRADATA_SIZE);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
318 st->codec->extradata_size = APE_EXTRADATA_SIZE;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
319 AV_WL16(st->codec->extradata + 0, ape->fileversion);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
320 AV_WL16(st->codec->extradata + 2, ape->compressiontype);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
321 AV_WL16(st->codec->extradata + 4, ape->formatflags);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
322
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
323 pts = 0;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
324 for (i = 0; i < ape->totalframes; i++) {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
325 ape->frames[i].pts = pts;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
326 av_add_index_entry(st, ape->frames[i].pos, ape->frames[i].pts, 0, 0, AVINDEX_KEYFRAME);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
327 pts += ape->blocksperframe / MAC_SUBFRAME_SIZE;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
328 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
329
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
330 return 0;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
331 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
332
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
333 static int ape_read_packet(AVFormatContext * s, AVPacket * pkt)
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
334 {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
335 int ret;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
336 int nblocks;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
337 APEContext *ape = s->priv_data;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
338 uint32_t extra_size = 8;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
339
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2568
diff changeset
340 if (url_feof(s->pb))
5834
134741dc8327 Replace all the occurrences of AVERROR_EIO with AVERROR(EIO), and mark
stefano
parents: 5566
diff changeset
341 return AVERROR(EIO);
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
342 if (ape->currentframe > ape->totalframes)
5834
134741dc8327 Replace all the occurrences of AVERROR_EIO with AVERROR(EIO), and mark
stefano
parents: 5566
diff changeset
343 return AVERROR(EIO);
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
344
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2568
diff changeset
345 url_fseek (s->pb, ape->frames[ape->currentframe].pos, SEEK_SET);
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
346
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
347 /* Calculate how many blocks there are in this frame */
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
348 if (ape->currentframe == (ape->totalframes - 1))
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
349 nblocks = ape->finalframeblocks;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
350 else
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
351 nblocks = ape->blocksperframe;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
352
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
353 if (av_new_packet(pkt, ape->frames[ape->currentframe].size + extra_size) < 0)
5930
08cd1179a20d Replace all remaining occurrences of AVERROR_NOMEM with
stefano
parents: 5910
diff changeset
354 return AVERROR(ENOMEM);
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
355
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
356 AV_WL32(pkt->data , nblocks);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
357 AV_WL32(pkt->data + 4, ape->frames[ape->currentframe].skip);
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2568
diff changeset
358 ret = get_buffer(s->pb, pkt->data + extra_size, ape->frames[ape->currentframe].size);
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
359
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
360 pkt->pts = ape->frames[ape->currentframe].pts;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
361 pkt->stream_index = 0;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
362
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
363 /* note: we need to modify the packet size here to handle the last
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
364 packet */
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
365 pkt->size = ret + extra_size;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
366
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
367 ape->currentframe++;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
368
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
369 return 0;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
370 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
371
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
372 static int ape_read_close(AVFormatContext * s)
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
373 {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
374 APEContext *ape = s->priv_data;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
375
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
376 av_freep(&ape->frames);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
377 av_freep(&ape->seektable);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
378 return 0;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
379 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
380
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
381 static int ape_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
382 {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
383 AVStream *st = s->streams[stream_index];
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
384 APEContext *ape = s->priv_data;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
385 int index = av_index_search_timestamp(st, timestamp, flags);
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
386
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
387 if (index < 0)
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
388 return -1;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
389
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
390 ape->currentframe = index;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
391 return 0;
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
392 }
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
393
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
394 AVInputFormat ape_demuxer = {
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
395 "ape",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3266
diff changeset
396 NULL_IF_CONFIG_SMALL("Monkey's Audio"),
2548
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
397 sizeof(APEContext),
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
398 ape_probe,
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
399 ape_read_header,
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
400 ape_read_packet,
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
401 ape_read_close,
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
402 ape_read_seek,
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
403 .extensions = "ape,apl,mac"
276257e703af Monkey Audio decoder
kostya
parents:
diff changeset
404 };