36#define AA_MAGIC 1469084982
37#define MAX_TOC_ENTRIES 16
38#define MAX_DICTIONARY_ENTRIES 128
39#define TEA_BLOCK_SIZE 8
40#define CHAPTER_HEADER_SIZE 8
42#define MP3_FRAME_SIZE 104
63 if (!strcmp(codec_name,
"mp332")) {
65 }
else if (!strcmp(codec_name,
"acelp16")) {
67 }
else if (!strcmp(codec_name,
"acelp85")) {
77 uint32_t toc_size, npairs, header_seed = 0, start;
78 char codec_name[64] = {0};
80 int64_t largest_size = -1, current_size = -1, chapter_pos;
85 uint8_t header_key[16] = {0};
87 char file_key[2 *
sizeof(
c->file_key) + 1];
100 for (uint32_t
i = 0;
i < toc_size;
i++) {
109 for (uint32_t
i = 0;
i < npairs;
i++) {
118 if (!strcmp(
key,
"codec")) {
121 }
else if (!strcmp(
key,
"HeaderSeed")) {
123 header_seed = atoi(
val);
124 }
else if (!strcmp(
key,
"HeaderKey")) {
125 uint32_t header_key_part[4];
128 ret = sscanf(
val,
"%"SCNu32
"%"SCNu32
"%"SCNu32
"%"SCNu32,
129 &header_key_part[0], &header_key_part[1], &header_key_part[2], &header_key_part[3]);
133 for (
int idx = 0; idx < 4; idx++)
134 AV_WB32(&header_key[idx * 4], header_key_part[idx]);
143 if (
c->aa_fixed_key_len != 16) {
159 for (
int i = 0;
i < 6;
i++)
174 if (!strcmp(codec_name,
"mp332")) {
180 }
else if (!strcmp(codec_name,
"acelp85")) {
188 }
else if (!strcmp(codec_name,
"acelp16")) {
199 for (uint32_t
i = 1;
i < toc_size;
i++) {
200 current_size = TOC[
i].size;
201 if (current_size > largest_size) {
203 largest_size = current_size;
206 start = TOC[largest_idx].offset;
212 c->content_start = start;
213 c->content_end = start + largest_size;
215 while ((chapter_pos =
avio_tell(pb)) >= 0 && chapter_pos < c->content_end) {
216 unsigned chapter_idx =
s->nb_chapters;
232 c->current_chapter_size = 0;
245 if (
pos >=
c->content_end) {
250 if (
c->current_chapter_size == 0) {
252 if (
c->current_chapter_size == 0) {
255 av_log(
s,
AV_LOG_DEBUG,
"Chapter %d (%" PRId64
" bytes)\n",
c->chapter_idx,
c->current_chapter_size);
256 c->chapter_idx =
c->chapter_idx + 1;
258 c->current_codec_second_size =
c->codec_second_size;
262 if (
c->current_chapter_size /
c->current_codec_second_size == 0) {
263 c->current_codec_second_size =
c->current_chapter_size %
c->current_codec_second_size;
267 if (ret !=
c->current_codec_second_size)
276 c->current_chapter_size =
c->current_chapter_size -
c->current_codec_second_size;
277 if (
c->current_chapter_size <= 0)
278 c->current_chapter_size = 0;
280 if (
c->seek_offset >
c->current_codec_second_size)
282 pkt->data +=
c->seek_offset;
283 pkt->size -=
c->seek_offset;
294 int64_t chapter_pos, chapter_start, chapter_size;
301 while (chapter_idx < s->nb_chapters && timestamp >=
s->chapters[chapter_idx]->end) {
305 if (chapter_idx >=
s->nb_chapters) {
306 chapter_idx =
s->nb_chapters - 1;
307 if (chapter_idx < 0)
return -1;
308 timestamp =
s->chapters[chapter_idx]->end;
311 ch =
s->chapters[chapter_idx];
316 1,
c->codec_second_size,
318 *
c->codec_second_size;
319 if (chapter_pos >= chapter_size)
320 chapter_pos = chapter_size;
324 avio_seek(
s->pb, chapter_start + chapter_pos, SEEK_SET);
325 c->current_codec_second_size =
c->codec_second_size;
326 c->current_chapter_size = chapter_size - chapter_pos;
327 c->chapter_idx = 1 + chapter_idx;
341 uint8_t *buf = p->buf;
359#define OFFSET(x) offsetof(AADemuxContext, x)
362 "Fixed key used for handling Audible AA files",
OFFSET(aa_fixed_key),
379 .p.extensions =
"aa",
static int aa_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
static int aa_read_header(AVFormatContext *s)
static int aa_probe(const AVProbeData *p)
#define CHAPTER_HEADER_SIZE
static int get_second_size(char *codec_name)
#define MAX_DICTIONARY_ENTRIES
static const AVClass aa_class
const FFInputFormat ff_aa_demuxer
static const AVOption aa_options[]
static int aa_read_close(AVFormatContext *s)
static int aa_read_packet(AVFormatContext *s, AVPacket *pkt)
static double val(void *priv, double ch)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
unsigned int avio_rb32(AVIOContext *s)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static int read_probe(const AVProbeData *p)
AVChapter * avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base, int64_t start, int64_t end, const char *title)
Add a new chapter.
#define FF_INFMT_FLAG_INIT_CLEANUP
For an FFInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
void avpriv_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp)
Update cur_dts of all streams based on the given timestamp and AVStream.
static int read_header(FFV1Context *f, RangeCoder *c)
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
@ AV_OPT_TYPE_BINARY
Underlying C type is a uint8_t* that is either NULL or points to an array allocated with the av_mallo...
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
@ AV_ROUND_DOWN
Round toward -infinity.
@ AV_ROUND_UP
Round toward +infinity.
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
void av_tea_init(AVTEA *ctx, const uint8_t key[16], int rounds)
Initialize an AVTEA context.
struct AVTEA * av_tea_alloc(void)
Allocate an AVTEA context To free the struct: av_free(ptr)
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 LIBAVUTIL_VERSION_INT
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold int read_close(AVFormatContext *ctx)
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Memory handling functions.
int64_t current_chapter_size
int current_codec_second_size
int nb_channels
Number of channels in this layout.
int64_t end
chapter start/end time in time_base units
Describe the class of an AVClass context structure.
AVChannelLayout ch_layout
The channel layout and number of channels.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
enum AVMediaType codec_type
General type of the encoded data.
int block_align
The number of bytes per coded audio frame, required by some formats.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int sample_rate
The number of audio samples per second.
This structure stores compressed data.
This structure contains the data a format has to probe a file.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int64_t duration
Decoding: duration of the stream, in stream time base.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
enum AVStreamParseType need_parsing
Public header for libavutil TEA algorithm.