Go to the documentation of this file.
1 /*
2  * Simon & Schuster Interactive VAG demuxer
3  *
4  * Copyright (C) 2020 Zane van Iperen (zane@zanevaniperen.com)
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
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 #include "avformat.h"
23 #include "internal.h"
24 #include "libavutil/intreadwrite.h"
26 #define KVAG_TAG MKTAG('K', 'V', 'A', 'G')
27 #define KVAG_HEADER_SIZE 14
28 #define KVAG_MAX_READ_SIZE 4096
30 typedef struct KVAGHeader {
31  uint32_t magic;
32  uint32_t data_size;
33  uint32_t sample_rate;
34  uint16_t stereo;
35 } KVAGHeader;
37 static int kvag_probe(const AVProbeData *p)
38 {
39  if (AV_RL32(p->buf) != KVAG_TAG)
40  return 0;
43 }
46 {
47  int ret;
48  AVStream *st;
49  KVAGHeader hdr;
50  AVCodecParameters *par;
53  if (!(st = avformat_new_stream(s, NULL)))
54  return AVERROR(ENOMEM);
56  if ((ret = avio_read(s->pb, buf, KVAG_HEADER_SIZE)) < 0)
57  return ret;
58  else if (ret != KVAG_HEADER_SIZE)
59  return AVERROR(EIO);
61  hdr.magic = AV_RL32(buf + 0);
62  hdr.data_size = AV_RL32(buf + 4);
63  hdr.sample_rate = AV_RL32(buf + 8);
64  hdr.stereo = AV_RL16(buf + 12);
66  par = st->codecpar;
71  if (hdr.stereo) {
73  par->channels = 2;
74  } else {
76  par->channels = 1;
77  }
79  par->sample_rate = hdr.sample_rate;
80  par->bits_per_coded_sample = 4;
81  par->bits_per_raw_sample = 16;
82  par->block_align = 1;
83  par->bit_rate = par->channels *
84  par->sample_rate *
87  avpriv_set_pts_info(st, 64, 1, par->sample_rate);
88  st->start_time = 0;
89  st->duration = hdr.data_size *
90  (8 / par->bits_per_coded_sample) /
91  par->channels;
93  return 0;
94 }
97 {
98  int ret;
99  AVCodecParameters *par = s->streams[0]->codecpar;
101  if ((ret = av_get_packet(s->pb, pkt, KVAG_MAX_READ_SIZE)) < 0)
102  return ret;
104  pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
105  pkt->stream_index = 0;
106  pkt->duration = ret * (8 / par->bits_per_coded_sample) / par->channels;
108  return 0;
109 }
112  .name = "kvag",
113  .long_name = NULL_IF_CONFIG_SMALL("Simon & Schuster Interactive VAG"),
114  .read_probe = kvag_probe,
115  .read_header = kvag_read_header,
116  .read_packet = kvag_read_packet
117 };
#define NULL
Definition: coverity.c:32
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:4943
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:4036
AVInputFormat ff_kvag_demuxer
Definition: kvag.c:111
static AVPacket pkt
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:87
This struct describes the properties of an encoded stream.
Definition: avcodec.h:4028
Format I/O context.
Definition: avformat.h:1353
Definition: kvag.c:28
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1551
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4524
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1421
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:308
uint64_t channel_layout
Audio only.
Definition: avcodec.h:4138
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:645
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: avcodec.h:4065
static int kvag_probe(const AVProbeData *p)
Definition: kvag.c:37
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:4032
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1539
uint32_t magic
Definition: kvag.c:31
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:443
int block_align
Audio only.
Definition: avcodec.h:4153
static int kvag_read_header(AVFormatContext *s)
Definition: kvag.c:45
#define s(width, name)
Definition: cbs_vp9.c:257
uint32_t sample_rate
Definition: kvag.c:33
#define KVAG_TAG
Definition: kvag.c:26
Stream structure.
Definition: avformat.h:876
AVIOContext * pb
I/O context.
Definition: avformat.h:1395
Definition: kvag.c:27
score for file extension
Definition: avformat.h:451
This structure contains the data a format has to probe a file.
Definition: avformat.h:441
int bits_per_raw_sample
This is the number of valid bits in each output sample.
Definition: avcodec.h:4091
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:925
int sample_rate
Audio only.
Definition: avcodec.h:4146
Main libavformat public API header.
uint16_t stereo
Definition: kvag.c:34
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
Definition: avformat.h:915
signed 16 bits
Definition: samplefmt.h:61
uint32_t data_size
Definition: kvag.c:32
The packet content is corrupted.
Definition: avcodec.h:1566
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: avcodec.h:4078
int channels
Audio only.
Definition: avcodec.h:4142
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:650
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1023
int stream_index
Definition: avcodec.h:1535
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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.Frame references ownership and permissions
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:87
This structure stores compressed data.
Definition: avcodec.h:1510
static int kvag_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: kvag.c:96