FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
acm.c
Go to the documentation of this file.
1 /*
2  * ACM demuxer
3  * Copyright (c) 2015 Paul B Mahol
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/intreadwrite.h"
23 #include "avformat.h"
24 #include "rawdec.h"
25 #include "internal.h"
26 
27 static int acm_probe(AVProbeData *p)
28 {
29  if (AV_RB32(p->buf) != 0x97280301)
30  return 0;
31 
32  return AVPROBE_SCORE_MAX / 3 * 2;
33 }
34 
36 {
37  AVStream *st;
38  int ret;
39 
40  st = avformat_new_stream(s, NULL);
41  if (!st)
42  return AVERROR(ENOMEM);
43 
46 
48  if (!st->codecpar->extradata)
49  return AVERROR(ENOMEM);
50  ret = avio_read(s->pb, st->codecpar->extradata, 14);
51  if (ret < 10)
52  return ret < 0 ? ret : AVERROR_EOF;
53 
54  st->codecpar->channels = AV_RL16(st->codecpar->extradata + 8);
55  st->codecpar->sample_rate = AV_RL16(st->codecpar->extradata + 10);
56  if (st->codecpar->channels <= 0 || st->codecpar->sample_rate <= 0)
57  return AVERROR_INVALIDDATA;
58  st->start_time = 0;
59  st->duration = AV_RL32(st->codecpar->extradata + 4) / st->codecpar->channels;
61  avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
62 
63  return 0;
64 }
65 
67  .name = "acm",
68  .long_name = NULL_IF_CONFIG_SMALL("Interplay ACM"),
69  .read_probe = acm_probe,
70  .read_header = acm_read_header,
71  .read_packet = ff_raw_read_partial_packet,
73  .extensions = "acm",
74  .raw_codec_id = AV_CODEC_ID_INTERPLAY_ACM,
75 };
#define NULL
Definition: coverity.c:32
#define AVFMT_NOBINSEARCH
Format does not allow to fall back on binary search via read_timestamp.
Definition: avformat.h:492
const char * s
Definition: avisynth_c.h:768
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
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.
Definition: utils.c:4560
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3980
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:87
static int acm_read_header(AVFormatContext *s)
Definition: acm.c:35
Format I/O context.
Definition: avformat.h:1338
enum AVStreamParseType need_parsing
Definition: avformat.h:1076
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4193
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
Definition: bytestream.h:87
#define AVERROR_EOF
End of file.
Definition: error.h:55
static int acm_probe(AVProbeData *p)
Definition: acm.c:27
full parsing and repack with timestamp and position generation by parser for raw this assumes that ea...
Definition: avformat.h:814
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:604
#define AVERROR(e)
Definition: error.h:43
int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rawdec.c:35
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3976
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:463
int ff_alloc_extradata(AVCodecParameters *par, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0...
Definition: utils.c:3175
AVInputFormat ff_acm_demuxer
Definition: acm.c:66
Stream structure.
Definition: avformat.h:889
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:486
AVIOContext * pb
I/O context.
Definition: avformat.h:1380
#define AVFMT_NOGENSEARCH
Format does not allow to fall back on generic search.
Definition: avformat.h:493
This structure contains the data a format has to probe a file.
Definition: avformat.h:461
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:943
int sample_rate
Audio only.
Definition: avcodec.h:4090
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:473
Main libavformat public API header.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
Definition: avformat.h:936
#define AVFMT_NO_BYTE_SEEK
Format does not allow seeking by bytes.
Definition: avformat.h:494
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3994
int channels
Audio only.
Definition: avcodec.h:4086
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:664
AVCodecParameters * codecpar
Definition: avformat.h:1241
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:87