FFmpeg
Loading...
Searching...
No Matches
siff.c
Go to the documentation of this file.
1/*
2 * Beam Software SIFF demuxer
3 * Copyright (c) 2007 Konstantin Shishkov
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
24
25#include "avformat.h"
26#include "demux.h"
27#include "internal.h"
28#include "avio_internal.h"
29
31 TAG_SIFF = MKTAG('S', 'I', 'F', 'F'),
32 TAG_BODY = MKTAG('B', 'O', 'D', 'Y'),
33 TAG_VBHD = MKTAG('V', 'B', 'H', 'D'),
34 TAG_SHDR = MKTAG('S', 'H', 'D', 'R'),
35 TAG_VBV1 = MKTAG('V', 'B', 'V', '1'),
36 TAG_SOUN = MKTAG('S', 'O', 'U', 'N'),
37};
38
46
47typedef struct SIFFContext {
48 int frames;
50 int rate;
51 int bits;
53
56
58 unsigned int pktsize;
60 unsigned int sndsize;
61
62 unsigned int flags;
63 uint8_t gmc[4];
65
66static int siff_probe(const AVProbeData *p)
67{
68 uint32_t tag = AV_RL32(p->buf + 8);
69 /* check file header */
70 if (AV_RL32(p->buf) != TAG_SIFF ||
71 (tag != TAG_VBV1 && tag != TAG_SOUN))
72 return 0;
73 return AVPROBE_SCORE_MAX;
74}
75
77{
78 AVStream *ast;
80 if (!ast)
81 return AVERROR(ENOMEM);
86 ast->codecpar->sample_rate = c->rate;
87 avpriv_set_pts_info(ast, 16, 1, c->rate);
88 ast->start_time = 0;
89 return 0;
90}
91
93{
94 AVStream *st;
95 int width, height;
96
97 if (avio_rl32(pb) != TAG_VBHD) {
98 av_log(s, AV_LOG_ERROR, "Header chunk is missing\n");
100 }
101 if (avio_rb32(pb) != 32) {
102 av_log(s, AV_LOG_ERROR, "Header chunk size is incorrect\n");
103 return AVERROR_INVALIDDATA;
104 }
105 if (avio_rl16(pb) != 1) {
106 av_log(s, AV_LOG_ERROR, "Incorrect header version\n");
107 return AVERROR_INVALIDDATA;
108 }
109 width = avio_rl16(pb);
110 height = avio_rl16(pb);
111 avio_skip(pb, 4);
112 c->frames = avio_rl16(pb);
113 if (!c->frames) {
114 av_log(s, AV_LOG_ERROR, "File contains no frames ???\n");
115 return AVERROR_INVALIDDATA;
116 }
117 c->bits = avio_rl16(pb);
118 c->rate = avio_rl16(pb);
119 c->block_align = c->rate * (c->bits >> 3);
120
121 avio_skip(pb, 16); // zeroes
122
124 if (!st)
125 return AVERROR(ENOMEM);
128 st->codecpar->codec_tag = MKTAG('V', 'B', 'V', '1');
129 st->codecpar->width = width;
130 st->codecpar->height = height;
132 st->nb_frames =
133 st->duration = c->frames;
134 avpriv_set_pts_info(st, 16, 1, 12);
135
136 c->cur_frame = 0;
137 c->has_video = 1;
138 c->has_audio = !!c->rate;
139 c->curstrm = -1;
140 if (c->has_audio)
141 return create_audio_stream(s, c);
142 return 0;
143}
144
146{
147 if (avio_rl32(pb) != TAG_SHDR) {
148 av_log(s, AV_LOG_ERROR, "Header chunk is missing\n");
149 return AVERROR_INVALIDDATA;
150 }
151 if (avio_rb32(pb) != 8) {
152 av_log(s, AV_LOG_ERROR, "Header chunk size is incorrect\n");
153 return AVERROR_INVALIDDATA;
154 }
155 avio_skip(pb, 4); // unknown value
156 c->rate = avio_rl16(pb);
157 c->bits = avio_rl16(pb);
158 c->block_align = c->rate * (c->bits >> 3);
159 return create_audio_stream(s, c);
160}
161
163{
164 AVIOContext *pb = s->pb;
165 SIFFContext *c = s->priv_data;
166 uint32_t tag;
167 int ret;
168
169 if (avio_rl32(pb) != TAG_SIFF)
170 return AVERROR_INVALIDDATA;
171 avio_skip(pb, 4); // ignore size
172 tag = avio_rl32(pb);
173
174 if (tag != TAG_VBV1 && tag != TAG_SOUN) {
175 av_log(s, AV_LOG_ERROR, "Not a VBV file\n");
176 return AVERROR_INVALIDDATA;
177 }
178
179 if (tag == TAG_VBV1 && (ret = siff_parse_vbv1(s, c, pb)) < 0)
180 return ret;
181 if (tag == TAG_SOUN && (ret = siff_parse_soun(s, c, pb)) < 0)
182 return ret;
183 if (avio_rl32(pb) != MKTAG('B', 'O', 'D', 'Y')) {
184 av_log(s, AV_LOG_ERROR, "'BODY' chunk is missing\n");
185 return AVERROR_INVALIDDATA;
186 }
187 avio_skip(pb, 4); // ignore size
188
189 return 0;
190}
191
193{
194 SIFFContext *c = s->priv_data;
195 int ret;
196
197 if (c->has_video) {
198 unsigned int size;
199 if (c->cur_frame >= c->frames)
200 return AVERROR_EOF;
201 if (c->curstrm == -1) {
202 unsigned pktsize = avio_rl32(s->pb);
203 if (pktsize < 4)
204 return AVERROR_INVALIDDATA;
205 c->pktsize = pktsize - 4;
206 c->flags = avio_rl16(s->pb);
207 if (c->flags & VB_HAS_AUDIO && !c->has_audio)
208 return AVERROR_INVALIDDATA;
209 c->gmcsize = (c->flags & VB_HAS_GMC) ? 4 : 0;
210 if (c->gmcsize)
211 avio_read(s->pb, c->gmc, c->gmcsize);
212 c->sndsize = (c->flags & VB_HAS_AUDIO) ? avio_rl32(s->pb) : 0;
213 c->curstrm = !!(c->flags & VB_HAS_AUDIO);
214 }
215
216 if (!c->curstrm) {
217 if (c->pktsize < 2LL + c->sndsize + c->gmcsize)
218 return AVERROR_INVALIDDATA;
219
220 size = c->pktsize - c->sndsize - c->gmcsize - 2;
221 size = ffio_limit(s->pb, size);
222 if ((ret = av_new_packet(pkt, size + c->gmcsize + 2)) < 0)
223 return ret;
224 AV_WL16(pkt->data, c->flags);
225 if (c->gmcsize)
226 memcpy(pkt->data + 2, c->gmc, c->gmcsize);
227 if (avio_read(s->pb, pkt->data + 2 + c->gmcsize, size) != size) {
228 return AVERROR_INVALIDDATA;
229 }
230 pkt->stream_index = 0;
231 c->curstrm = -1;
232 } else {
233 int pktsize = av_get_packet(s->pb, pkt, c->sndsize - 4);
234 if (pktsize < 0)
235 return AVERROR_INVALIDDATA;
236 pkt->stream_index = 1;
237 pkt->duration = pktsize;
238 c->curstrm = 0;
239 }
240 if (!c->cur_frame || c->curstrm)
241 pkt->flags |= AV_PKT_FLAG_KEY;
242 if (c->curstrm == -1)
243 c->cur_frame++;
244 } else {
245 int pktsize = av_get_packet(s->pb, pkt, c->block_align);
246 if (!pktsize)
247 return AVERROR_EOF;
248 if (pktsize <= 0)
249 return AVERROR_INVALIDDATA;
250 pkt->duration = pktsize;
251 }
252 return pkt->size;
253}
254
256 .p.name = "siff",
257 .p.long_name = NULL_IF_CONFIG_SMALL("Beam Software SIFF"),
258 .p.extensions = "vb,son",
259 .priv_data_size = sizeof(SIFFContext),
263};
const FFInputFormat ff_siff_demuxer
Definition siff.c:255
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
unsigned int avio_rl16(AVIOContext *s)
Definition aviobuf.c:717
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition aviobuf.c:321
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition aviobuf.c:615
unsigned int avio_rl32(AVIOContext *s)
Definition aviobuf.c:733
unsigned int avio_rb32(AVIOContext *s)
Definition aviobuf.c:764
int ffio_limit(AVIOContext *s, int size)
Definition aviobuf.c:1064
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define s(width, name)
Definition cbs_vp9.c:198
static int read_probe(const AVProbeData *p)
Definition cdg.c:30
Public libavutil channel layout APIs header.
#define NULL
Definition coverity.c:32
static AVPacket * pkt
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
@ AV_CODEC_ID_PCM_U8
Definition codec_id.h:335
@ AV_CODEC_ID_VB
Definition codec_id.h:158
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:650
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition packet.c:98
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AV_CHANNEL_LAYOUT_MONO
#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
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define AV_RL32(p)
#define AV_WL16(p, v)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
#define MKTAG(a, b, c, d)
Definition macros.h:55
uint32_t tag
Definition movenc.c:2087
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition pixfmt.h:84
static int siff_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition siff.c:192
static int siff_read_header(AVFormatContext *s)
Definition siff.c:162
static int siff_parse_soun(AVFormatContext *s, SIFFContext *c, AVIOContext *pb)
Definition siff.c:145
static int siff_parse_vbv1(AVFormatContext *s, SIFFContext *c, AVIOContext *pb)
Definition siff.c:92
static int create_audio_stream(AVFormatContext *s, SIFFContext *c)
Definition siff.c:76
static int siff_probe(const AVProbeData *p)
Definition siff.c:66
SIFFTags
Definition siff.c:30
@ TAG_BODY
Definition siff.c:32
@ TAG_VBV1
Definition siff.c:35
@ TAG_SOUN
Definition siff.c:36
@ TAG_SHDR
Definition siff.c:34
@ TAG_VBHD
Definition siff.c:33
@ TAG_SIFF
Definition siff.c:31
An AVChannelLayout holds information about the channel layout of audio data.
int height
The height of the video frame in pixels.
Definition codec_par.h:150
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition codec_par.h:113
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
int width
The width of the video frame in pixels.
Definition codec_par.h:143
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition codec_par.h:61
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
Bytestream IO Context.
Definition avio.h:160
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
int64_t nb_frames
number of frames in this stream if known or 0
Definition avformat.h:827
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition avformat.h:825
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Definition avformat.h:815
int has_audio
Definition siff.c:55
int has_video
Definition siff.c:54
int gmcsize
Definition siff.c:59
int curstrm
Definition siff.c:57
unsigned int flags
Definition siff.c:62
int rate
Definition siff.c:50
int frames
Definition siff.c:48
int cur_frame
Definition siff.c:49
int bits
Definition siff.c:51
int block_align
Definition siff.c:52
uint8_t gmc[4]
Definition siff.c:63
unsigned int pktsize
Definition siff.c:58
unsigned int sndsize
Definition siff.c:60
#define av_log(a,...)
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
int size
VBFlags
Definition vb.c:34
@ VB_HAS_VIDEO
Definition vb.c:37
@ VB_HAS_PALETTE
Definition vb.c:38
@ VB_HAS_LENGTH
Definition vb.c:39
@ VB_HAS_AUDIO
Definition vb.c:36
@ VB_HAS_GMC
Definition vb.c:35
static double c[64]