FFmpeg: libavformat/scd.c Source File
Go to the documentation of this file. 1 /*
2 * Square Enix SCD demuxer
3 * Copyright (C) 2021 Zane van Iperen (zane@zanevaniperen.com)
4 *
5 * Based off documentation:
6 * http://ffxivexplorer.fragmenterworks.com/research/scd%20files.txt
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
31
32 #define SCD_MAGIC ((uint64_t)MKBETAG('S', 'E', 'D', 'B') << 32 | \
33 MKBETAG('S', 'S', 'C', 'F'))
34 #define SCD_MIN_HEADER_SIZE 20
35 #define SCD_OFFSET_HEADER_SIZE 28
36 #define SCD_TRACK_HEADER_SIZE 32
37
38 #define SCD_TRACK_ID_PCM 0
39 #define SCD_TRACK_ID_OGG 6
40 #define SCD_TRACK_ID_MP3 7
41 #define SCD_TRACK_ID_MS_ADPCM 12
42
48
51 uint32_t
version;
/* Verison number. We only know about 3. */
52 uint16_t
unk1;
/* Unknown, 260 in Drakengard 3, 1024 in FFXIV. */
54 uint32_t
file_size;
/* Is often 0, just ignore it. */
55
59 uint16_t
unk2;
/* Unknown, not a count. */
60 uint32_t
unk3;
/* Unknown, not an offset. */
61 uint32_t
unk4;
/* Unknown, offset to offset. */
63
73
77
83
85 {
87 return 0;
88
90 }
91
93 {
95
98
101
104
105 for (
size_t i = 0;
i <
table->count;
i++)
107
109 for (
size_t i = 0;
i <
table->count;
i++)
111
112 return 0;
113 }
114
116 {
120
123
133
136
139
142
143 return 0;
144 }
145
147 {
149 uint32_t hoffset;
154
155 /* Mark as experimental until I find more files from more than just one game. */
158 "add '-strict %d' if you want to use it.\n",
161 }
162
163 hoffset =
ctx->hdr.table1.entries[
index];
164
167
170
179
180 /* Sanity checks */
184
187
188 /* Not sure what to do with these, it seems to be fine to ignore them. */
191
194
201
202 /* TODO: Check this with other types. Drakengard 3 MP3s have 47999 instead of 48000. */
205
207
210
213
216
222 break;
226 break;
229 default:
232 }
233
234 return 0;
235 }
236
238 {
242
245
251
254
255 if (
ctx->hdr.version != 3) {
258 }
259
262
265
268
272
273 for (
int i = 0;
i <
ctx->hdr.table1.count;
i++) {
276 }
277
278 if (
ctx->hdr.table1.count == 0)
279 return 0;
280
283
284 return 0;
285 }
286
288 {
291
292 /* Streams aren't interleaved, round-robin them. */
293 for (
int i = 0;
i <
ctx->hdr.table1.count;
i++) {
297
298 ctx->current_track %=
ctx->hdr.table1.count;
299
300 trk =
ctx->tracks +
ctx->current_track;
301 par =
s->streams[
ctx->current_track]->codecpar;
302
304 continue;
305
308
312 break;
314 default:
316 break;
317 }
318
322 continue;
323 }
else if (
ret < 0) {
325 }
326
330 }
331
335
336 ctx->current_track++;
337 return 0;
338 }
339
341 }
342
345 {
347
350
351 for(
int i = 0;
i <
ctx->hdr.table1.count; ++
i)
352 ctx->tracks[
i].bytes_read = 0;
353
354 return 0;
355 }
356
358 {
360
365 return 0;
366 }
367
378 };
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it.
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
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
enum AVMediaType codec_type
General type of the encoded data.
This struct describes the properties of an encoded stream.
#define AVERROR_EOF
End of file.
static const uint16_t table[]
#define SCD_TRACK_ID_MS_ADPCM
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
int nb_channels
Number of channels in this layout.
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
static av_cold int read_close(AVFormatContext *ctx)
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
enum AVStreamParseType need_parsing
AVCodecParameters * codecpar
Codec parameters associated with this stream.
static int read_header(FFV1Context *f)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define SCD_MIN_HEADER_SIZE
static int scd_read_close(AVFormatContext *s)
This structure contains the data a format has to probe a file.
AVChannelLayout ch_layout
Audio only.
int sample_rate
Audio only.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
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
int flags
A combination of AV_PKT_FLAG values.
static int scd_read_offsets(AVFormatContext *s)
static int scd_read_table(AVFormatContext *s, SCDOffsetTable *table)
const AVInputFormat ff_scd_demuxer
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int block_align
Audio only.
static int scd_read_header(AVFormatContext *s)
void * av_calloc(size_t nmemb, size_t size)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
int index
stream index in AVFormatContext
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
static int read_probe(const AVProbeData *p)
int bits_per_coded_sample
The number of bits per sample in the codedwords.
static int scd_probe(const AVProbeData *p)
#define avpriv_request_sample(...)
#define SCD_TRACK_HEADER_SIZE
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
#define flags(name, subs,...)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define SCD_OFFSET_HEADER_SIZE
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
static int scd_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
static int scd_read_packet(AVFormatContext *s, AVPacket *pkt)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_RB64
static int scd_read_track(AVFormatContext *s, SCDTrackHeader *track, int index)
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_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
Generated on Tue Feb 28 2023 21:34:09 for FFmpeg by
doxygen
1.8.17