FFmpeg
Loading...
Searching...
No Matches
adxdec.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Justin Ruggles
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file
23 * CRI ADX demuxer
24 */
25
27#include "avformat.h"
28#include "demux.h"
29#include "internal.h"
30#include "rawdec.h"
31
32#define BLOCK_SIZE 18
33#define BLOCK_SAMPLES 32
34
39
40static int adx_probe(const AVProbeData *p)
41{
42 int offset;
43 if (AV_RB16(p->buf) != 0x8000)
44 return 0;
45 offset = AV_RB16(&p->buf[2]);
46 if ( offset < 8
47 || offset > p->buf_size - 4
48 || memcmp(p->buf + offset - 2, "(c)CRI", 6))
49 return 0;
50 return AVPROBE_SCORE_MAX * 3 / 4;
51}
52
54{
55 ADXDemuxerContext *c = s->priv_data;
56 AVCodecParameters *par = s->streams[0]->codecpar;
57 int ret, size;
58
59 if (par->codec_id == AV_CODEC_ID_AHX)
61
62 if (avio_feof(s->pb))
63 return AVERROR_EOF;
64
66
67 pkt->pos = avio_tell(s->pb);
68 pkt->stream_index = 0;
69
70 ret = av_get_packet(s->pb, pkt, size * 128);
71 if (ret < 0)
72 return ret;
73 if ((ret % size) && ret >= size) {
74 size = ret - (ret % size);
76 pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
77 } else if (ret < size) {
79 } else {
80 size = ret;
81 }
82
83 pkt->duration = size / (BLOCK_SIZE * par->ch_layout.nb_channels);
84 pkt->pts = (pkt->pos - c->header_size) / (BLOCK_SIZE * par->ch_layout.nb_channels);
85
86 return 0;
87}
88
90{
91 ADXDemuxerContext *c = s->priv_data;
93 FFStream *sti;
94 int ret;
95 int channels;
96
98 if (!st)
99 return AVERROR(ENOMEM);
100 par = s->streams[0]->codecpar;
101
102 if (avio_rb16(s->pb) != 0x8000)
103 return AVERROR_INVALIDDATA;
104 c->header_size = avio_rb16(s->pb) + 4;
105 avio_seek(s->pb, -4, SEEK_CUR);
106
107 if ((ret = ff_get_extradata(s, par, s->pb, c->header_size)) < 0)
108 return ret;
109
110 if (par->extradata_size < 12) {
111 av_log(s, AV_LOG_ERROR, "Invalid extradata size.\n");
112 return AVERROR_INVALIDDATA;
113 }
114 channels = AV_RB8 (par->extradata + 7);
115 par->sample_rate = AV_RB32(par->extradata + 8);
116
117 if (channels <= 0) {
118 av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", channels);
119 return AVERROR_INVALIDDATA;
120 }
121
122 if (par->sample_rate <= 0) {
123 av_log(s, AV_LOG_ERROR, "Invalid sample rate %d\n", par->sample_rate);
124 return AVERROR_INVALIDDATA;
125 }
126
127 sti = ffstream(st);
130 switch (par->extradata[4]) {
131 case 3:
136 break;
137 case 16:
140 avpriv_set_pts_info(st, 64, 1, par->sample_rate);
141 break;
142 default:
143 av_log(s, AV_LOG_ERROR, "Unsupported format: %d\n", par->extradata[4]);
144 return AVERROR_INVALIDDATA;
145 }
146
147 return 0;
148}
149
151 .p.name = "adx",
152 .p.long_name = NULL_IF_CONFIG_SMALL("CRI ADX"),
153 .p.extensions = "adx",
154 .p.priv_class = &ff_raw_demuxer_class,
155 .p.flags = AVFMT_GENERIC_INDEX,
156 .read_probe = adx_probe,
157 .priv_data_size = sizeof(ADXDemuxerContext),
160};
#define BLOCK_SAMPLES
Definition adx.h:52
#define BLOCK_SIZE
Definition adx.h:51
channels
Definition aptx.h:31
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
@ AVSTREAM_PARSE_FULL_RAW
full parsing and repack with timestamp and position generation by parser for raw this assumes that ea...
Definition avformat.h:615
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition aviobuf.c:236
unsigned int avio_rb16(AVIOContext *s)
Definition aviobuf.c:749
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition aviobuf.c:349
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition avio.h:494
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
int ff_get_extradata(void *logctx, AVCodecParameters *par, AVIOContext *pb, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0 and f...
static AVPacket * pkt
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
@ AV_CODEC_ID_ADPCM_ADX
Definition codec_id.h:379
@ AV_CODEC_ID_AHX
Definition codec_id.h:561
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition packet.h:651
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition packet.c:113
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_EOF
End of file.
Definition error.h:57
#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_RB8(x)
#define AV_RB32(p)
#define AV_RB16(p)
unsigned offset
Definition libaomenc.c:763
const FFInputFormat ff_adx_demuxer
Definition adxdec.c:150
static int adx_probe(const AVProbeData *p)
Definition adxdec.c:40
static int adx_read_header(AVFormatContext *s)
Definition adxdec.c:89
static int adx_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition adxdec.c:53
static av_always_inline FFStream * ffstream(AVStream *st)
Definition internal.h:365
const AVClass ff_raw_demuxer_class
Definition rawdec.c:141
int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
Definition rawdec.c:33
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
FFRawDemuxerContext rawctx
Definition adxdec.c:36
int nb_channels
Number of channels in this layout.
This struct describes the properties of an encoded stream.
Definition codec_par.h:49
int extradata_size
Size of the extradata content in bytes.
Definition codec_par.h:75
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
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition codec_par.h:71
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
enum AVStreamParseType need_parsing
Definition internal.h:321
#define av_log(a,...)
int size
static double c[64]