libavformat/adxdec.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Justin Ruggles
3  *
4  * This file is part of Libav.
5  *
6  * Libav 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  * Libav 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 Libav; 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 
26 #include "libavutil/intreadwrite.h"
27 #include "libavcodec/adx.h"
28 #include "avformat.h"
29 #include "internal.h"
30 
31 #define BLOCK_SIZE 18
32 #define BLOCK_SAMPLES 32
33 
34 typedef struct ADXDemuxerContext {
37 
39 {
41  AVCodecContext *avctx = s->streams[0]->codec;
42  int ret, size;
43 
44  size = BLOCK_SIZE * avctx->channels;
45 
46  pkt->pos = avio_tell(s->pb);
47  pkt->stream_index = 0;
48 
49  ret = av_get_packet(s->pb, pkt, size);
50  if (ret != size) {
51  av_free_packet(pkt);
52  return ret < 0 ? ret : AVERROR(EIO);
53  }
54  if (AV_RB16(pkt->data) & 0x8000) {
55  av_free_packet(pkt);
56  return AVERROR_EOF;
57  }
58  pkt->size = size;
59  pkt->duration = 1;
60  pkt->pts = (pkt->pos - c->header_size) / size;
61 
62  return 0;
63 }
64 
66 {
68  AVCodecContext *avctx;
69  int ret;
70 
72  if (!st)
73  return AVERROR(ENOMEM);
74  avctx = s->streams[0]->codec;
75 
76  if (avio_rb16(s->pb) != 0x8000)
77  return AVERROR_INVALIDDATA;
78  c->header_size = avio_rb16(s->pb) + 4;
79  avio_seek(s->pb, -4, SEEK_CUR);
80 
82  if (!avctx->extradata)
83  return AVERROR(ENOMEM);
84  if (avio_read(s->pb, avctx->extradata, c->header_size) < c->header_size) {
85  av_freep(&avctx->extradata);
86  return AVERROR(EIO);
87  }
88  avctx->extradata_size = c->header_size;
89 
90  ret = avpriv_adx_decode_header(avctx, avctx->extradata,
91  avctx->extradata_size, &c->header_size,
92  NULL);
93  if (ret)
94  return ret;
95 
98 
100 
101  return 0;
102 }
103 
105  .name = "adx",
106  .long_name = NULL_IF_CONFIG_SMALL("CRI ADX"),
107  .priv_data_size = sizeof(ADXDemuxerContext),
110  .extensions = "adx",
111  .raw_codec_id = AV_CODEC_ID_ADPCM_ADX,
113 };
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
const char * s
Definition: avisynth_c.h:668
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
void av_free_packet(AVPacket *pkt)
Free a packet.
Definition: avpacket.c:242
int64_t pos
byte position in stream, -1 if unknown
static int adx_read_packet(AVFormatContext *s, AVPacket *pkt)
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:199
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:595
#define BLOCK_SAMPLES
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
Format I/O context.
Definition: avformat.h:944
static AVPacket pkt
Definition: demuxing.c:56
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
Definition: avformat.h:992
uint8_t * data
#define AVERROR_EOF
End of file.
Definition: error.h:55
static int adx_read_header(AVFormatContext *s)
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.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:248
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:478
#define BLOCK_SIZE
#define AV_RB16
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int size
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
ret
Definition: avfilter.c:821
struct ADXDemuxerContext ADXDemuxerContext
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:517
Stream structure.
Definition: avformat.h:643
NULL
Definition: eval.c:55
enum AVMediaType codec_type
enum AVCodecID codec_id
int sample_rate
samples per second
AVIOContext * pb
I/O context.
Definition: avformat.h:977
main external API structure.
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:114
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:353
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
int raw_codec_id
Raw demuxers store their codec ID here.
Definition: avformat.h:500
static int flags
Definition: cpu.c:23
int avpriv_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf, int bufsize, int *header_size, int *coeff)
Decode ADX stream header.
Definition: adx.c:38
Main libavformat public API header.
static double c[64]
struct AVInputFormat * iformat
Can only be iformat or oformat, not both at the same time.
Definition: avformat.h:957
int channels
number of audio channels
void * priv_data
Format private data.
Definition: avformat.h:964
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:461
SEGA CRI adx codecs.
AVInputFormat ff_adx_demuxer
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...