FFmpeg
Loading...
Searching...
No Matches
aeadec.c
Go to the documentation of this file.
1/*
2 * MD STUDIO audio demuxer
3 *
4 * Copyright (c) 2009 Benjamin Larsson
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
25#include "avformat.h"
26#include "avio_internal.h"
27#include "demux.h"
28#include "internal.h"
29#include "pcm.h"
30
31#define AT1_SU_SIZE 212
32
33static int aea_read_probe(const AVProbeData *p)
34{
35 if (p->buf_size <= 2048+AT1_SU_SIZE)
36 return 0;
37
38 /* Magic is '00 08 00 00' in little-endian*/
39 if (AV_RL32(p->buf)==0x800) {
40 int ch, block_size, score = 0;
41 ch = p->buf[264];
42
43 if (ch != 1 && ch != 2)
44 return 0;
45
46 block_size = ch * AT1_SU_SIZE;
47 /* Check so that the redundant bsm bytes and info bytes are valid
48 * the block size mode bytes have to be the same
49 * the info bytes have to be the same
50 */
51 for (int i = 2048 + block_size; i + block_size <= p->buf_size; i += block_size) {
52 if (AV_RN16(p->buf+i) != AV_RN16(p->buf+i+AT1_SU_SIZE))
53 return 0;
54 score++;
55 }
56 return FFMIN(AVPROBE_SCORE_MAX / 4 + score, AVPROBE_SCORE_MAX);
57 }
58 return 0;
59}
60
62{
64 char title[256 + 1];
65 int channels, ret;
66 if (!st)
67 return AVERROR(ENOMEM);
68
69 /* Read the title, parse the number of channels and skip to pos 2048(0x800) */
70 avio_rl32(s->pb); // magic
71 ret = ffio_read_size(s->pb, title, sizeof(title) - 1);
72 if (ret < 0)
73 return ret;
74 title[sizeof(title) - 1] = '\0';
75 if (title[0] != '\0')
76 av_dict_set(&st->metadata, "title", title, 0);
77 avio_rl32(s->pb); // Block count
78 channels = avio_r8(s->pb);
79 avio_skip(s->pb, 1783);
80
81
84 st->codecpar->sample_rate = 44100;
85 st->codecpar->bit_rate = 146000 * channels;
86
88 av_log(s, AV_LOG_ERROR, "Channels %d not supported!\n", channels);
90 }
91
93
95 avpriv_set_pts_info(st, 64, 1, 44100);
96 return 0;
97}
98
100{
101 return av_get_packet(s->pb, pkt, s->streams[0]->codecpar->block_align);
102}
103
105 .p.name = "aea",
106 .p.long_name = NULL_IF_CONFIG_SMALL("MD STUDIO audio"),
107 .p.flags = AVFMT_GENERIC_INDEX,
108 .p.extensions = "aea",
109 .read_probe = aea_read_probe,
110 .read_header = aea_read_header,
111 .read_packet = aea_read_packet,
112 .read_seek = ff_pcm_read_seek,
113};
static int aea_read_probe(const AVProbeData *p)
Definition aeadec.c:33
static int aea_read_header(AVFormatContext *s)
Definition aeadec.c:61
const FFInputFormat ff_aea_demuxer
Definition aeadec.c:104
static int aea_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition aeadec.c:99
channels
Definition aptx.h:31
#define AT1_SU_SIZE
number of bytes in a sound unit
Definition atrac1.c:48
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:834
Main libavformat public API header.
#define AVPROBE_SCORE_MAX
maximum score
Definition avformat.h:483
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition utils.c:98
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition avformat.h:499
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition aviobuf.c:321
unsigned int avio_rl32(AVIOContext *s)
Definition aviobuf.c:733
int avio_r8(AVIOContext *s)
Definition aviobuf.c:606
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition aviobuf.c:665
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
Public libavutil channel layout APIs header.
#define NULL
Definition coverity.c:32
static AVPacket * pkt
@ AV_CODEC_ID_ATRAC1
Definition codec_id.h:499
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition dict.c:86
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
#define AV_RL32(p)
#define AV_RN16(p)
int ff_pcm_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition pcm.c:73
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
#define FFMIN(a, b)
Definition macros.h:49
int nb_channels
Number of channels in this layout.
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition codec_par.h:99
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
int block_align
The number of bytes per coded audio frame, required by some formats.
Definition codec_par.h:221
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
int sample_rate
The number of audio samples per second.
Definition codec_par.h:213
Format I/O context.
Definition avformat.h:1333
This structure stores compressed data.
Definition packet.h:580
This structure contains the data a format has to probe a file.
Definition avformat.h:471
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
AVDictionary * metadata
Definition avformat.h:846
#define av_log(a,...)