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 */
32
33 #define SCD_MAGIC ((uint64_t)MKBETAG('S', 'E', 'D', 'B') << 32 | \
34 MKBETAG('S', 'S', 'C', 'F'))
35 #define SCD_MIN_HEADER_SIZE 20
36 #define SCD_OFFSET_HEADER_SIZE 28
37 #define SCD_TRACK_HEADER_SIZE 32
38
39 #define SCD_TRACK_ID_PCM 0
40 #define SCD_TRACK_ID_OGG 6
41 #define SCD_TRACK_ID_MP3 7
42 #define SCD_TRACK_ID_MS_ADPCM 12
43
49
52 uint32_t
version;
/* Verison number. We only know about 3. */
53 uint16_t
unk1;
/* Unknown, 260 in Drakengard 3, 1024 in FFXIV. */
55 uint32_t
file_size;
/* Is often 0, just ignore it. */
56
60 uint16_t
unk2;
/* Unknown, not a count. */
61 uint32_t
unk3;
/* Unknown, not an offset. */
62 uint32_t
unk4;
/* Unknown, offset to offset. */
64
74
78
84
86 {
88 return 0;
89
91 }
92
94 {
96
99
102
105
106 for (
size_t i = 0;
i <
table->count;
i++)
108
110 for (
size_t i = 0;
i <
table->count;
i++)
112
113 return 0;
114 }
115
117 {
121
124
134
137
140
143
144 return 0;
145 }
146
148 {
150 uint32_t hoffset;
155
156 /* Mark as experimental until I find more files from more than just one game. */
159 "add '-strict %d' if you want to use it.\n",
162 }
163
164 hoffset =
ctx->hdr.table1.entries[
index];
165
168
171
180
181 /* Sanity checks */
185
188
189 /* Not sure what to do with these, it seems to be fine to ignore them. */
192
195
202
203 /* TODO: Check this with other types. Drakengard 3 MP3s have 47999 instead of 48000. */
206
208
211
214
217
223 break;
227 break;
230 default:
233 }
234
235 return 0;
236 }
237
239 {
243
246
252
255
256 if (
ctx->hdr.version != 3) {
259 }
260
263
266
269
273
274 for (
int i = 0;
i <
ctx->hdr.table1.count;
i++) {
277 }
278
279 if (
ctx->hdr.table1.count == 0)
280 return 0;
281
284
285 return 0;
286 }
287
289 {
292
293 /* Streams aren't interleaved, round-robin them. */
294 for (
int i = 0;
i <
ctx->hdr.table1.count;
i++) {
298
299 ctx->current_track %=
ctx->hdr.table1.count;
300
301 trk =
ctx->tracks +
ctx->current_track;
302 par =
s->streams[
ctx->current_track]->codecpar;
303
305 continue;
306
309
313 break;
315 default:
317 break;
318 }
319
323 continue;
324 }
else if (
ret < 0) {
326 }
327
331 }
332
336
337 ctx->current_track++;
338 return 0;
339 }
340
342 }
343
346 {
348
351
352 for(
int i = 0;
i <
ctx->hdr.table1.count; ++
i)
353 ctx->tracks[
i].bytes_read = 0;
354
355 return 0;
356 }
357
359 {
361
366 return 0;
367 }
368
379 };
#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
enum AVMediaType codec_type
General type of the encoded data.
This struct describes the properties of an encoded stream.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#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.
#define FF_INFMT_FLAG_INIT_CLEANUP
For an FFInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
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)
#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.
const FFInputFormat ff_scd_demuxer
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 Thu Sep 26 2024 23:15:51 for FFmpeg by
doxygen
1.8.17