32 #define AA_MAGIC 1469084982
33 #define MAX_CODEC_SECOND_SIZE 3982
34 #define MAX_TOC_ENTRIES 16
35 #define MAX_DICTIONARY_ENTRIES 128
36 #define TEA_BLOCK_SIZE 8
54 if (!strcmp(codec_name,
"mp332")) {
56 }
else if (!strcmp(codec_name,
"acelp16")) {
58 }
else if (!strcmp(codec_name,
"acelp85")) {
67 int i, j, idx, largest_idx = -1;
68 uint32_t nkey, nval, toc_size, npairs, header_seed,
start;
69 char key[128],
val[128], codec_name[64] = {0};
71 int64_t largest_size = -1, current_size = -1;
76 uint32_t header_key_part[4];
89 for (i = 0; i < toc_size; i++) {
98 for (i = 0; i < npairs; i++) {
99 memset(val, 0,
sizeof(val));
100 memset(key, 0,
sizeof(key));
104 if (nkey >
sizeof(key)) {
109 if (nval >
sizeof(val)) {
114 if (!strcmp(key,
"codec")) {
116 strncpy(codec_name, val,
sizeof(codec_name) - 1);
118 if (!strcmp(key,
"HeaderSeed")) {
120 header_seed = atoi(val);
122 if (!strcmp(key,
"HeaderKey")) {
124 sscanf(val,
"%u%u%u%u", &header_key_part[0], &header_key_part[1], &header_key_part[2], &header_key_part[3]);
125 for (idx = 0; idx < 4; idx++) {
126 AV_WB32(&header_key[idx * 4], header_key_part[idx]);
129 for (i = 0; i < 16; i++)
152 output[0] = output[1] = 0;
153 memcpy(output + 2, header_key, 16);
155 for (i = 0; i < 3; i++) {
157 AV_WB32(src + 4, header_seed + 1);
161 output[idx] = output[idx] ^ dst[j];
164 memcpy(c->
file_key, output + 2, 16);
166 for (i = 0; i < 16; i++)
177 if (!strcmp(codec_name,
"mp332")) {
182 }
else if (!strcmp(codec_name,
"acelp85")) {
187 }
else if (!strcmp(codec_name,
"acelp16")) {
195 for (i = 1; i < toc_size; i++) {
196 current_size = TOC[i].size;
197 if (current_size > largest_size) {
199 largest_size = current_size;
202 start = TOC[largest_idx].offset;
240 for (i = 0; i < blocks; i++) {
248 if (trailing_bytes != 0) {
250 memcpy(buf + written, src, trailing_bytes);
251 written = written + trailing_bytes;
262 memcpy(pkt->
data, buf, written);
287 #define OFFSET(x) offsetof(AADemuxContext, x)
290 "Fixed key used for handling Audible AA files",
OFFSET(aa_fixed_key),
const char const char void * val
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define LIBAVUTIL_VERSION_INT
static int aa_read_packet(AVFormatContext *s, AVPacket *pkt)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
int current_codec_second_size
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
struct AVTEA * av_tea_alloc(void)
Allocate an AVTEA context To free the struct: av_free(ptr)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static int aa_probe(AVProbeData *p)
#define MAX_CODEC_SECOND_SIZE
unsigned int avio_rb32(AVIOContext *s)
static const AVOption aa_options[]
enum AVStreamParseType need_parsing
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
AVInputFormat ff_aa_demuxer
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
preferred ID for decoding MPEG audio layer 1, 2 or 3
static int aa_read_header(AVFormatContext *s)
static const uint8_t offset[127][2]
AVCodecContext * codec
Codec context associated with this stream.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
int64_t current_chapter_size
Public header for libavutil TEA algorithm.
void av_tea_crypt(AVTEA *ctx, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt)
Encrypt or decrypt a buffer using a previously initialized context.
#define MAX_DICTIONARY_ENTRIES
offset must point to a pointer immediately followed by an int for the length
static int read_header(FFV1Context *f)
static int aa_read_close(AVFormatContext *s)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
enum AVMediaType codec_type
int sample_rate
samples per second
AVIOContext * pb
I/O context.
Describe the class of an AVClass context structure.
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
static int get_second_size(char *codec_name)
static const AVClass aa_class
This structure contains the data a format has to probe a file.
void av_tea_init(AVTEA *ctx, const uint8_t key[16], int rounds)
Initialize an AVTEA context.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
int channels
number of audio channels
void * priv_data
Format private data.
This structure stores compressed data.