Mercurial > audlegacy-plugins
annotate src/demac/ape.c @ 2260:b71d8bee8882
OSS: use SNDCTL_DSP_SYNC, as not all OSS versions have SNDCTL_DSP_RESET.
Reported by Michal on the forums.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Fri, 21 Dec 2007 12:17:25 -0600 |
parents | 8b3c2fe608c9 |
children | ed6c81bd9016 |
rev | line source |
---|---|
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
1 /* |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
2 * Monkey's Audio APE demuxer, standalone version |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
3 * Copyright (c) 2007 Benjamin Zores <ben@geexbox.org> |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
4 * based upon libdemac from Dave Chapman. |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
5 * Copyright (c) 2007 Eugene Zagidullin <e.asphyx@gmail.com> |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
6 * Cleanup libav* depending code, Audacious stuff. |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
7 * |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
8 * This file is part of FFmpeg. |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
9 * |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
10 * FFmpeg is free software; you can redistribute it and/or |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
11 * modify it under the terms of the GNU Lesser General Public |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
12 * License as published by the Free Software Foundation; either |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
13 * version 2.1 of the License, or (at your option) any later version. |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
14 * |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
15 * FFmpeg is distributed in the hope that it will be useful, |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
18 * Lesser General Public License for more details. |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
19 * |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
20 * You should have received a copy of the GNU Lesser General Public |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
21 * License along with FFmpeg; if not, write to the Free Software |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
23 */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
24 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
25 #include <stdio.h> |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
26 #include <stdlib.h> |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
27 #include <errno.h> |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
28 #include <string.h> |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
29 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
30 #include <audacious/vfs.h> |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
31 #include <audacious/plugin.h> |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
32 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
33 #include "ape.h" |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
34 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
35 #define ENABLE_DEBUG 0 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
36 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
37 /* The earliest and latest file formats supported by this library */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
38 #define APE_MIN_VERSION 3950 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
39 #define APE_MAX_VERSION 3990 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
40 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
41 #define MAC_FORMAT_FLAG_8_BIT 1 // is 8-bit [OBSOLETE] |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
42 #define MAC_FORMAT_FLAG_CRC 2 // uses the new CRC32 error detection [OBSOLETE] |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
43 #define MAC_FORMAT_FLAG_HAS_PEAK_LEVEL 4 // uint32 nPeakLevel after the header [OBSOLETE] |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
44 #define MAC_FORMAT_FLAG_24_BIT 8 // is 24-bit [OBSOLETE] |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
45 #define MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS 16 // has the number of seek elements after the peak level |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
46 #define MAC_FORMAT_FLAG_CREATE_WAV_HEADER 32 // create the wave header on decompression (not stored) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
47 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
48 #define MAC_SUBFRAME_SIZE 4608 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
49 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
50 #define APE_EXTRADATA_SIZE 6 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
51 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
52 /* APE tags */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
53 #define APE_TAG_VERSION 2000 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
54 #define APE_TAG_FOOTER_BYTES 32 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
55 #define APE_TAG_FLAG_CONTAINS_HEADER (1 << 31) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
56 #define APE_TAG_FLAG_IS_HEADER (1 << 29) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
57 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
58 #define TAG(name, field) {name, offsetof(AVFormatContext, field), sizeof(((AVFormatContext *)0)->field)} |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
59 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
60 |
2193
80d7ab8f2ec5
removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2182
diff
changeset
|
61 uint16_t get_le16(VFSFile *vfd) |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
62 { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
63 unsigned char tmp[2]; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
64 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
65 if(aud_vfs_fread(tmp, 1, 2, vfd) != 2) return -1; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
66 return tmp[0] | (tmp[1] << 8); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
67 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
68 |
2193
80d7ab8f2ec5
removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2182
diff
changeset
|
69 uint32_t get_le32(VFSFile *vfd) |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
70 { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
71 unsigned char tmp[4]; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
72 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
73 if(aud_vfs_fread(tmp, 1, 4, vfd) != 4) return -1; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
74 return tmp[0] | (tmp[1] << 8) | (tmp[2] << 16) | (tmp[3] << 24); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
75 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
76 |
2199
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2193
diff
changeset
|
77 int put_le32(uint32_t val, VFSFile *vfd) |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2193
diff
changeset
|
78 { |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2193
diff
changeset
|
79 unsigned char tmp[4]; |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2193
diff
changeset
|
80 |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2193
diff
changeset
|
81 tmp[0] = (val & 0x000000ff); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2193
diff
changeset
|
82 tmp[1] = (val & 0x0000ff00) >> 8; |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2193
diff
changeset
|
83 tmp[2] = (val & 0x00ff0000) >> 16; |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2193
diff
changeset
|
84 tmp[3] = (val & 0xff000000) >> 24; |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2193
diff
changeset
|
85 |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2193
diff
changeset
|
86 return aud_vfs_fwrite(tmp, 1, 4, vfd); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2193
diff
changeset
|
87 } |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2193
diff
changeset
|
88 |
2193
80d7ab8f2ec5
removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2182
diff
changeset
|
89 uint64_t get_le64(VFSFile *vfd) |
80d7ab8f2ec5
removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2182
diff
changeset
|
90 { |
80d7ab8f2ec5
removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2182
diff
changeset
|
91 unsigned char tmp[8]; |
80d7ab8f2ec5
removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2182
diff
changeset
|
92 |
80d7ab8f2ec5
removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2182
diff
changeset
|
93 if(aud_vfs_fread(tmp, 1, 8, vfd) != 8) return -1; |
80d7ab8f2ec5
removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2182
diff
changeset
|
94 return (uint64_t)tmp[0] | ((uint64_t)tmp[1] << 8) | ((uint64_t)tmp[2] << 16) | ((uint64_t)tmp[3] << 24) | |
80d7ab8f2ec5
removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2182
diff
changeset
|
95 ((uint64_t)tmp[4] << 32) | ((uint64_t)tmp[5] << 40) | ((uint64_t)tmp[6] << 48) | ((uint64_t)tmp[7] << 56); |
80d7ab8f2ec5
removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2182
diff
changeset
|
96 } |
80d7ab8f2ec5
removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2182
diff
changeset
|
97 |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
98 #ifdef DEBUG |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
99 static void ape_dumpinfo(APEContext * ape_ctx) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
100 { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
101 int i; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
102 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
103 av_log(NULL, AV_LOG_DEBUG, "Descriptor Block:\n\n"); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
104 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]); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
105 av_log(NULL, AV_LOG_DEBUG, "fileversion = %d\n", ape_ctx->fileversion); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
106 av_log(NULL, AV_LOG_DEBUG, "descriptorlength = %d\n", ape_ctx->descriptorlength); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
107 av_log(NULL, AV_LOG_DEBUG, "headerlength = %d\n", ape_ctx->headerlength); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
108 av_log(NULL, AV_LOG_DEBUG, "seektablelength = %d\n", ape_ctx->seektablelength); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
109 av_log(NULL, AV_LOG_DEBUG, "wavheaderlength = %d\n", ape_ctx->wavheaderlength); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
110 av_log(NULL, AV_LOG_DEBUG, "audiodatalength = %d\n", ape_ctx->audiodatalength); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
111 av_log(NULL, AV_LOG_DEBUG, "audiodatalength_high = %d\n", ape_ctx->audiodatalength_high); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
112 av_log(NULL, AV_LOG_DEBUG, "wavtaillength = %d\n", ape_ctx->wavtaillength); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
113 av_log(NULL, AV_LOG_DEBUG, "md5 = "); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
114 for (i = 0; i < 16; i++) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
115 av_log(NULL, AV_LOG_DEBUG, "%02x", ape_ctx->md5[i]); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
116 av_log(NULL, AV_LOG_DEBUG, "\n"); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
117 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
118 av_log(NULL, AV_LOG_DEBUG, "\nHeader Block:\n\n"); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
119 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
120 av_log(NULL, AV_LOG_DEBUG, "compressiontype = %d\n", ape_ctx->compressiontype); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
121 av_log(NULL, AV_LOG_DEBUG, "formatflags = %d\n", ape_ctx->formatflags); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
122 av_log(NULL, AV_LOG_DEBUG, "blocksperframe = %d\n", ape_ctx->blocksperframe); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
123 av_log(NULL, AV_LOG_DEBUG, "finalframeblocks = %d\n", ape_ctx->finalframeblocks); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
124 av_log(NULL, AV_LOG_DEBUG, "totalframes = %d\n", ape_ctx->totalframes); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
125 av_log(NULL, AV_LOG_DEBUG, "bps = %d\n", ape_ctx->bps); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
126 av_log(NULL, AV_LOG_DEBUG, "channels = %d\n", ape_ctx->channels); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
127 av_log(NULL, AV_LOG_DEBUG, "samplerate = %d\n", ape_ctx->samplerate); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
128 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
129 av_log(NULL, AV_LOG_DEBUG, "\nSeektable\n\n"); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
130 if ((ape_ctx->seektablelength / sizeof(uint32_t)) != ape_ctx->totalframes) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
131 av_log(NULL, AV_LOG_DEBUG, "No seektable\n"); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
132 } else { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
133 for (i = 0; i < ape_ctx->seektablelength / sizeof(uint32_t); i++) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
134 if (i < ape_ctx->totalframes - 1) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
135 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]); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
136 } else { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
137 av_log(NULL, AV_LOG_DEBUG, "%8d %d\n", i, ape_ctx->seektable[i]); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
138 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
139 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
140 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
141 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
142 av_log(NULL, AV_LOG_DEBUG, "\nFrames\n\n"); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
143 for (i = 0; i < ape_ctx->totalframes; i++) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
144 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); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
145 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
146 av_log(NULL, AV_LOG_DEBUG, "\nCalculated information:\n\n"); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
147 av_log(NULL, AV_LOG_DEBUG, "junklength = %d\n", ape_ctx->junklength); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
148 av_log(NULL, AV_LOG_DEBUG, "firstframe = %d\n", ape_ctx->firstframe); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
149 av_log(NULL, AV_LOG_DEBUG, "totalsamples = %d\n", ape_ctx->totalsamples); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
150 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
151 #else |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
152 #define ape_dumpinfo(a) ; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
153 #endif |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
154 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
155 int ape_read_header(APEContext *ape, VFSFile *pb, int probe_only) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
156 { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
157 /*ByteIOContext *pb = &s->pb; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
158 APEContext *ape = s->priv_data; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
159 AVStream *st;*/ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
160 uint32_t tag; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
161 int i; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
162 //int total_blocks; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
163 //int64_t pts; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
164 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
165 /* TODO: Skip any leading junk such as id3v2 tags */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
166 ape->junklength = 0; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
167 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
168 tag = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
169 if (tag != MKTAG('M', 'A', 'C', ' ')) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
170 return -1; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
171 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
172 ape->fileversion = get_le16(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
173 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
174 if (ape->fileversion < APE_MIN_VERSION || ape->fileversion > APE_MAX_VERSION) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
175 #ifdef DEBUG |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
176 fprintf(stderr, "ape.c: ape_read_header(): Unsupported file version - %d.%02d\n", |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
177 ape->fileversion / 1000, (ape->fileversion % 1000) / 10); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
178 #endif |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
179 return -1; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
180 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
181 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
182 if (ape->fileversion >= 3980) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
183 ape->padding1 = get_le16(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
184 ape->descriptorlength = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
185 ape->headerlength = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
186 ape->seektablelength = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
187 ape->wavheaderlength = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
188 ape->audiodatalength = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
189 ape->audiodatalength_high = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
190 ape->wavtaillength = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
191 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
192 aud_vfs_fread(ape->md5, 1, 16, pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
193 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
194 /* Skip any unknown bytes at the end of the descriptor. |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
195 This is for future compatibility */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
196 if (ape->descriptorlength > 52) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
197 aud_vfs_fseek(pb, ape->descriptorlength - 52, SEEK_CUR); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
198 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
199 /* Read header data */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
200 ape->compressiontype = get_le16(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
201 ape->formatflags = get_le16(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
202 ape->blocksperframe = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
203 ape->finalframeblocks = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
204 ape->totalframes = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
205 ape->bps = get_le16(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
206 ape->channels = get_le16(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
207 ape->samplerate = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
208 } else { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
209 ape->descriptorlength = 0; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
210 ape->headerlength = 32; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
211 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
212 ape->compressiontype = get_le16(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
213 ape->formatflags = get_le16(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
214 ape->channels = get_le16(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
215 ape->samplerate = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
216 ape->wavheaderlength = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
217 ape->wavtaillength = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
218 ape->totalframes = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
219 ape->finalframeblocks = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
220 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
221 if (ape->formatflags & MAC_FORMAT_FLAG_HAS_PEAK_LEVEL) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
222 aud_vfs_fseek(pb, 4, SEEK_CUR); /* Skip the peak level */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
223 ape->headerlength += 4; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
224 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
225 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
226 if (ape->formatflags & MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
227 ape->seektablelength = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
228 ape->headerlength += 4; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
229 ape->seektablelength *= sizeof(int32_t); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
230 } else |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
231 ape->seektablelength = ape->totalframes * sizeof(int32_t); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
232 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
233 if (ape->formatflags & MAC_FORMAT_FLAG_8_BIT) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
234 ape->bps = 8; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
235 else if (ape->formatflags & MAC_FORMAT_FLAG_24_BIT) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
236 ape->bps = 24; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
237 else |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
238 ape->bps = 16; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
239 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
240 if (ape->fileversion >= 3950) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
241 ape->blocksperframe = 73728 * 4; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
242 else if (ape->fileversion >= 3900 || (ape->fileversion >= 3800 && ape->compressiontype >= 4000)) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
243 ape->blocksperframe = 73728; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
244 else |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
245 ape->blocksperframe = 9216; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
246 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
247 /* Skip any stored wav header */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
248 if (!(ape->formatflags & MAC_FORMAT_FLAG_CREATE_WAV_HEADER)) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
249 aud_vfs_fseek(pb, ape->wavheaderlength, SEEK_CUR); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
250 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
251 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
252 if(ape->totalframes > UINT_MAX / sizeof(APEFrame)){ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
253 #ifdef DEBUG |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
254 fprintf(stdout, "Too many frames: %d\n", ape->totalframes); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
255 #endif |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
256 return -1; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
257 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
258 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
259 if(!probe_only) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
260 ape->frames = malloc(ape->totalframes * sizeof(APEFrame)); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
261 if(!ape->frames) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
262 return AVERROR_NOMEM; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
263 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
264 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
265 ape->firstframe = ape->junklength + ape->descriptorlength + ape->headerlength + ape->seektablelength + ape->wavheaderlength; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
266 ape->currentframe = 0; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
267 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
268 ape->totalsamples = ape->finalframeblocks; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
269 if (ape->totalframes > 1) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
270 ape->totalsamples += ape->blocksperframe * (ape->totalframes - 1); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
271 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
272 if (!probe_only) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
273 if (ape->seektablelength > 0) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
274 ape->seektable = malloc(ape->seektablelength); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
275 for (i = 0; i < ape->seektablelength / sizeof(uint32_t); i++) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
276 ape->seektable[i] = get_le32(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
277 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
278 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
279 ape->frames[0].pos = ape->firstframe; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
280 ape->frames[0].nblocks = ape->blocksperframe; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
281 ape->frames[0].skip = 0; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
282 for (i = 1; i < ape->totalframes; i++) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
283 ape->frames[i].pos = ape->seektable[i]; //ape->frames[i-1].pos + ape->blocksperframe; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
284 ape->frames[i].nblocks = ape->blocksperframe; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
285 ape->frames[i - 1].size = ape->frames[i].pos - ape->frames[i - 1].pos; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
286 ape->frames[i].skip = (ape->frames[i].pos - ape->frames[0].pos) & 3; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
287 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
288 ape->frames[ape->totalframes - 1].size = ape->finalframeblocks * 4; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
289 ape->frames[ape->totalframes - 1].nblocks = ape->finalframeblocks; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
290 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
291 ape->max_packet_size = 0; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
292 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
293 for (i = 0; i < ape->totalframes; i++) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
294 if(ape->frames[i].skip){ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
295 ape->frames[i].pos -= ape->frames[i].skip; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
296 ape->frames[i].size += ape->frames[i].skip; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
297 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
298 ape->frames[i].size = (ape->frames[i].size + 3) & ~3; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
299 // Eugene: |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
300 ape->max_packet_size = MAX(ape->max_packet_size, ape->frames[i].size + 8); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
301 // why +8? look in ape_read_packet() |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
302 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
303 ape_dumpinfo(ape); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
304 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
305 } // !probe_only |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
306 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
307 //ape->total_blocks = (ape->totalframes == 0) ? 0 : ((ape->totalframes - 1) * ape->blocksperframe) + ape->finalframeblocks; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
308 ape->frame_size = MAC_SUBFRAME_SIZE; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
309 //ape->duration = (uint64_t) total_blocks * AV_TIME_BASE / ape->samplerate; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
310 ape->duration = (uint64_t) ape->totalsamples * AV_TIME_BASE / ape->samplerate; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
311 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
312 #ifdef DEBUG |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
313 fprintf(stderr, "Decoding file - v%4.2f, compression level %d, duration %llu msec, %d frames, %d blocks per frame, %s\n", |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
314 ape->fileversion / 1000.0, ape->compressiontype, (unsigned long long)ape->duration, |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
315 ape->totalframes, ape->blocksperframe, ape->channels == 2 ? "stereo" : "mono"); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
316 #endif |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
317 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
318 //av_set_pts_info(st, 64, MAC_SUBFRAME_SIZE, ape->samplerate); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
319 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
320 /*pts = 0; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
321 for (i = 0; i < ape->totalframes; i++) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
322 ape->frames[i].pts = pts; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
323 av_add_index_entry(st, ape->frames[i].pos, ape->frames[i].pts, 0, 0, AVINDEX_KEYFRAME); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
324 pts += ape->blocksperframe / MAC_SUBFRAME_SIZE; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
325 }*/ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
326 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
327 return 0; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
328 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
329 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
330 /* buffer must be allocated before in conformity to ape->max_packet_size. Eugene. */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
331 int ape_read_packet(APEContext *ape, VFSFile *pb, uint8_t *pkt, int *pkt_size) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
332 { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
333 int ret; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
334 int nblocks; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
335 uint32_t extra_size = 8; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
336 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
337 if (aud_vfs_feof(pb)) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
338 return AVERROR_IO; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
339 if (ape->currentframe > ape->totalframes) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
340 return AVERROR_IO; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
341 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
342 aud_vfs_fseek(pb, ape->frames[ape->currentframe].pos, SEEK_SET); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
343 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
344 /* Calculate how many blocks there are in this frame */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
345 if (ape->currentframe == (ape->totalframes - 1)) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
346 nblocks = ape->finalframeblocks; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
347 else |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
348 nblocks = ape->blocksperframe; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
349 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
350 /*if (av_new_packet(pkt, ape->frames[ape->currentframe].size + extra_size) < 0) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
351 return AVERROR_NOMEM;*/ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
352 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
353 AV_WL32(pkt , nblocks); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
354 AV_WL32(pkt + 4, ape->frames[ape->currentframe].skip); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
355 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
356 ret = aud_vfs_fread(pkt + extra_size, 1, ape->frames[ape->currentframe].size, pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
357 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
358 /*pkt->pts = ape->frames[ape->currentframe].pts; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
359 pkt->stream_index = 0;*/ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
360 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
361 /* note: we need to modify the packet size here to handle the last |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
362 packet */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
363 /*pkt->size = ret + extra_size;*/ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
364 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
365 ape->currentframe++; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
366 *pkt_size = ape->frames[ape->currentframe].size + extra_size; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
367 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
368 return 0; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
369 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
370 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
371 int ape_read_close(APEContext *ape) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
372 { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
373 if(ape->frames != NULL) free(ape->frames); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
374 if(ape->seektable != NULL) free(ape->seektable); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
375 return 0; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
376 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
377 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
378 /* |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
379 static int ape_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
380 { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
381 AVStream *st = s->streams[stream_index]; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
382 APEContext *ape = s->priv_data; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
383 int index = av_index_search_timestamp(st, timestamp, flags); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
384 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
385 if (index < 0) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
386 return -1; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
387 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
388 ape->currentframe = index; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
389 return 0; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
390 }*/ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
391 |