.github
CMakeModules
dist
externals
SDL
Vulkan-Headers
cmake-modules
cubeb
discord-rpc
dynarmic
ffmpeg
compat
doc
ffbuild
fftools
libavcodec
libavdevice
libavfilter
libavformat
tests
.gitignore
3dostr.c
4xm.c
Makefile
a64.c
aacdec.c
aadec.c
ac3dec.c
acm.c
act.c
adp.c
ads.c
adtsenc.c
adxdec.c
aea.c
afc.c
aiff.h
aiffdec.c
aiffenc.c
aixdec.c
allformats.c
alp.c
amr.c
anm.c
apc.c
ape.c
apetag.c
apetag.h
apm.c
apngdec.c
apngenc.c
aptxdec.c
aqtitledec.c
argo_asf.c
asf.c
asf.h
asfcrypt.c
asfcrypt.h
asfdec_f.c
asfdec_o.c
asfenc.c
assdec.c
assenc.c
ast.c
ast.h
astdec.c
astenc.c
async.c
au.c
av1.c
av1.h
av1dec.c
avc.c
avc.h
avformat.h
avformatres.rc
avi.h
avidec.c
avienc.c
avio.c
avio.h
avio_internal.h
aviobuf.c
avisynth.c
avlanguage.c
avlanguage.h
avr.c
avs.c
bethsoftvid.c
bfi.c
bink.c
bintext.c
bit.c
bluray.c
bmv.c
boadec.c
brstm.c
c93.c
cache.c
caf.c
caf.h
cafdec.c
cafenc.c
cavsvideodec.c
cdg.c
cdxl.c
chromaprint.c
cinedec.c
codec2.c
concat.c
concatdec.c
crcenc.c
crypto.c
cutils.c
dash.c
dash.h
dashdec.c
dashenc.c
data_uri.c
dauddec.c
daudenc.c
davs2.c
dcstr.c
derf.c
dfa.c
dhav.c
diracdec.c
dnxhddec.c
dsfdec.c
dsicin.c
dss.c
dtsdec.c
dtshddec.c
dump.c
dv.c
dv.h
dvbsub.c
dvbtxt.c
dvenc.c
dxa.c
eacdata.c
electronicarts.c
epafdec.c
ffmeta.h
ffmetadec.c
ffmetaenc.c
fifo.c
fifo_test.c
file.c
file_open.c
filmstripdec.c
filmstripenc.c
fitsdec.c
fitsenc.c
flac_picture.c
flac_picture.h
flacdec.c
flacenc.c
flacenc.h
flacenc_header.c
flic.c
flv.h
flvdec.c
flvenc.c
format.c
framecrcenc.c
framehash.c
frmdec.c
fsb.c
ftp.c
fwse.c
g722.c
g723_1.c
g726.c
g729dec.c
gdv.c
genh.c
gif.c
gifdec.c
golomb_tab.c
gopher.c
gsmdec.c
gxf.c
gxf.h
gxfenc.c
h261dec.c
h263dec.c
h264dec.c
hashenc.c
hca.c
hcom.c
hdsenc.c
hevc.c
hevc.h
hevcdec.c
hls.c
hlsenc.c
hlsplaylist.c
hlsplaylist.h
hlsproto.c
hnm.c
http.c
http.h
httpauth.c
httpauth.h
icecast.c
icodec.c
icoenc.c
id3v1.c
id3v1.h
id3v2.c
id3v2.h
id3v2enc.c
idcin.c
idroqdec.c
idroqenc.c
iff.c
ifv.c
ilbc.c
img2.c
img2.h
img2_alias_pix.c
img2_brender_pix.c
img2dec.c
img2enc.c
ingenientdec.c
internal.h
ip.c
ip.h
ipmovie.c
ircam.c
ircam.h
ircamdec.c
ircamenc.c
isom.c
isom.h
iss.c
iv8.c
ivfdec.c
ivfenc.c
jacosubdec.c
jacosubenc.c
jvdec.c
kvag.c
latmenc.c
libamqp.c
libavformat.v
libgme.c
libmodplug.c
libopenmpt.c
librtmp.c
libsmbclient.c
libsrt.c
libssh.c
libzmq.c
lmlm4.c
loasdec.c
log2_tab.c
lrc.c
lrc.h
lrcdec.c
lrcenc.c
lvfdec.c
lxfdec.c
m4vdec.c
matroska.c
matroska.h
matroskadec.c
matroskaenc.c
mccdec.c
md5proto.c
metadata.c
metadata.h
mgsts.c
microdvddec.c
microdvdenc.c
mj2kdec.c
mkvtimestamp_v2.c
mlpdec.c
mlvdec.c
mm.c
mmf.c
mms.c
mms.h
mmsh.c
mmst.c
mov.c
mov_chan.c
mov_chan.h
mov_esds.c
movenc.c
movenc.h
movenccenc.c
movenccenc.h
movenchint.c
mp3dec.c
mp3enc.c
mpc.c
mpc8.c
mpeg.c
mpeg.h
mpegenc.c
mpegts.c
mpegts.h
mpegtsenc.c
mpegvideodec.c
mpjpeg.c
mpjpegdec.c
mpl2dec.c
mpsubdec.c
msf.c
msnwc_tcp.c
mtaf.c
mtv.c
musx.c
mux.c
mvdec.c
mvi.c
mxf.c
mxf.h
mxfdec.c
mxfenc.c
mxg.c
ncdec.c
network.c
network.h
nistspheredec.c
nspdec.c
nsvdec.c
nullenc.c
nut.c
nut.h
nutdec.c
nutenc.c
nuv.c
oggdec.c
oggdec.h
oggenc.c
oggparsecelt.c
oggparsedirac.c
oggparseflac.c
oggparseogm.c
oggparseopus.c
oggparseskeleton.c
oggparsespeex.c
oggparsetheora.c
oggparsevorbis.c
oggparsevp8.c
oma.c
oma.h
omadec.c
omaenc.c
options.c
options_table.h
os_support.c
os_support.h
paf.c
pcm.c
pcm.h
pcmdec.c
pcmenc.c
pjsdec.c
pmpdec.c
pp_bnk.c
prompeg.c
protocols.c
psxstr.c
pva.c
pvfdec.c
qcp.c
qtpalette.c
qtpalette.h
r3d.c
rawdec.c
rawdec.h
rawenc.c
rawenc.h
rawutils.c
rawvideodec.c
rdt.c
rdt.h
realtextdec.c
redspark.c
replaygain.c
replaygain.h
riff.c
riff.h
riffdec.c
riffenc.c
rl2.c
rm.c
rm.h
rmdec.c
rmenc.c
rmsipr.c
rmsipr.h
rpl.c
rsd.c
rso.c
rso.h
rsodec.c
rsoenc.c
rtmp.h
rtmpcrypt.c
rtmpcrypt.h
rtmpdh.c
rtmpdh.h
rtmpdigest.c
rtmphttp.c
rtmppkt.c
rtmppkt.h
rtmpproto.c
rtp.c
rtp.h
rtpdec.c
rtpdec.h
rtpdec_ac3.c
rtpdec_amr.c
rtpdec_asf.c
rtpdec_dv.c
rtpdec_formats.h
rtpdec_g726.c
rtpdec_h261.c
rtpdec_h263.c
rtpdec_h263_rfc2190.c
rtpdec_h264.c
rtpdec_hevc.c
rtpdec_ilbc.c
rtpdec_jpeg.c
rtpdec_latm.c
rtpdec_mpa_robust.c
rtpdec_mpeg12.c
rtpdec_mpeg4.c
rtpdec_mpegts.c
rtpdec_qcelp.c
rtpdec_qdm2.c
rtpdec_qt.c
rtpdec_rfc4175.c
rtpdec_svq3.c
rtpdec_vc2hq.c
rtpdec_vp8.c
rtpdec_vp9.c
rtpdec_xiph.c
rtpenc.c
rtpenc.h
rtpenc_aac.c
rtpenc_amr.c
rtpenc_chain.c
rtpenc_chain.h
rtpenc_h261.c
rtpenc_h263.c
rtpenc_h263_rfc2190.c
rtpenc_h264_hevc.c
rtpenc_jpeg.c
rtpenc_latm.c
rtpenc_mpegts.c
rtpenc_mpv.c
rtpenc_vc2hq.c
rtpenc_vp8.c
rtpenc_vp9.c
rtpenc_xiph.c
rtpproto.c
rtpproto.h
rtsp.c
rtsp.h
rtspcodes.h
rtspdec.c
rtspenc.c
s337m.c
samidec.c
sapdec.c
sapenc.c
sauce.c
sauce.h
sbcdec.c
sbgdec.c
sccdec.c
sccenc.c
sctp.c
sdp.c
sdr2.c
sdsdec.c
sdxdec.c
segafilm.c
segafilmenc.c
segment.c
serdec.c
shortendec.c
sierravmd.c
siff.c
smacker.c
smjpeg.c
smjpeg.h
smjpegdec.c
smjpegenc.c
smoothstreamingenc.c
smush.c
sol.c
sox.h
soxdec.c
soxenc.c
spdif.c
spdif.h
spdifdec.c
spdifenc.c
srtdec.c
srtenc.c
srtp.c
srtp.h
srtpproto.c
stldec.c
subfile.c
subtitles.c
subtitles.h
subviewer1dec.c
subviewerdec.c
supdec.c
supenc.c
svag.c
swf.c
swf.h
swfdec.c
swfenc.c
takdec.c
tcp.c
tedcaptionsdec.c
tee.c
tee_common.c
tee_common.h
teeproto.c
thp.c
tiertexseq.c
tls.c
tls.h
tls_gnutls.c
tls_libtls.c
tls_mbedtls.c
tls_openssl.c
tls_schannel.c
tls_securetransport.c
tmv.c
tta.c
ttaenc.c
tty.c
txd.c
ty.c
udp.c
uncodedframecrcenc.c
unix.c
url.c
url.h
urldecode.c
urldecode.h
utils.c
v210.c
vag.c
vapoursynth.c
vc1dec.c
vc1test.c
vc1testenc.c
version.h
vividas.c
vivo.c
voc.c
voc.h
voc_packet.c
vocdec.c
vocenc.c
vorbiscomment.c
vorbiscomment.h
vpcc.c
vpcc.h
vpk.c
vplayerdec.c
vqf.c
w64.c
w64.h
wavdec.c
wavenc.c
wc3movie.c
webm_chunk.c
webmdashenc.c
webpenc.c
webvttdec.c
webvttenc.c
westwood_aud.c
westwood_vqa.c
wsddec.c
wtv.h
wtv_common.c
wtvdec.c
wtvenc.c
wv.c
wv.h
wvdec.c
wvedec.c
wvenc.c
xa.c
xmv.c
xvag.c
xwma.c
yop.c
yuv4mpeg.h
yuv4mpegdec.c
yuv4mpegenc.c
libavresample
libavutil
libpostproc
libswresample
libswscale
presets
tests
tools
.gitattributes
.gitignore
.mailmap
.travis.yml
CONTRIBUTING.md
COPYING.GPLv2
COPYING.GPLv3
COPYING.LGPLv2.1
COPYING.LGPLv3
CREDITS
Changelog
INSTALL.md
LICENSE.md
MAINTAINERS
Makefile
README.md
RELEASE
RELEASE_NOTES
configure
find-modules
getopt
glad
httplib
inih
libressl
libusb
libzip
mbedtls
microprofile
opus
sirit
soundtouch
xbyak
CMakeLists.txt
patches
src
CMakeLists.txt
LICENSE
README.md
license.txt
162 lines
4.4 KiB
C
162 lines
4.4 KiB
C
![]() |
/*
|
||
|
* RedSpark demuxer
|
||
|
* Copyright (c) 2013 James Almer
|
||
|
*
|
||
|
* This file is part of FFmpeg.
|
||
|
*
|
||
|
* FFmpeg is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Lesser General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
|
* version 2.1 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* FFmpeg is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Lesser General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Lesser General Public
|
||
|
* License along with FFmpeg; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||
|
*/
|
||
|
|
||
|
#include "libavcodec/bytestream.h"
|
||
|
#include "libavutil/intreadwrite.h"
|
||
|
#include "avformat.h"
|
||
|
#include "avio.h"
|
||
|
#include "internal.h"
|
||
|
|
||
|
#define HEADER_SIZE 4096
|
||
|
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
|
||
|
|
||
|
typedef struct RedSparkContext {
|
||
|
int samples_count;
|
||
|
} RedSparkContext;
|
||
|
|
||
|
static int redspark_probe(const AVProbeData *p)
|
||
|
{
|
||
|
uint32_t key, data;
|
||
|
uint8_t header[8];
|
||
|
|
||
|
/* Decrypt first 8 bytes of the header */
|
||
|
data = AV_RB32(p->buf);
|
||
|
key = data ^ 0x52656453;
|
||
|
data ^= key;
|
||
|
AV_WB32(header, data);
|
||
|
key = rol(key, 11);
|
||
|
|
||
|
key += rol(key, 3);
|
||
|
data = AV_RB32(p->buf + 4) ^ key;
|
||
|
AV_WB32(header + 4, data);
|
||
|
|
||
|
if (AV_RB64(header) == AV_RB64("RedSpark"))
|
||
|
return AVPROBE_SCORE_MAX;
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
static int redspark_read_header(AVFormatContext *s)
|
||
|
{
|
||
|
AVIOContext *pb = s->pb;
|
||
|
RedSparkContext *redspark = s->priv_data;
|
||
|
AVCodecParameters *par;
|
||
|
GetByteContext gbc;
|
||
|
int i, coef_off, ret = 0;
|
||
|
uint32_t key, data;
|
||
|
uint8_t header[HEADER_SIZE];
|
||
|
AVStream *st;
|
||
|
|
||
|
st = avformat_new_stream(s, NULL);
|
||
|
if (!st)
|
||
|
return AVERROR(ENOMEM);
|
||
|
par = st->codecpar;
|
||
|
|
||
|
/* Decrypt header */
|
||
|
data = avio_rb32(pb);
|
||
|
key = data ^ 0x52656453;
|
||
|
data ^= key;
|
||
|
AV_WB32(header, data);
|
||
|
key = rol(key, 11);
|
||
|
|
||
|
for (i = 4; i < HEADER_SIZE; i += 4) {
|
||
|
key += rol(key, 3);
|
||
|
data = avio_rb32(pb) ^ key;
|
||
|
AV_WB32(header + i, data);
|
||
|
}
|
||
|
|
||
|
par->codec_id = AV_CODEC_ID_ADPCM_THP;
|
||
|
par->codec_type = AVMEDIA_TYPE_AUDIO;
|
||
|
|
||
|
bytestream2_init(&gbc, header, HEADER_SIZE);
|
||
|
bytestream2_seek(&gbc, 0x3c, SEEK_SET);
|
||
|
par->sample_rate = bytestream2_get_be32u(&gbc);
|
||
|
if (par->sample_rate <= 0 || par->sample_rate > 96000) {
|
||
|
av_log(s, AV_LOG_ERROR, "Invalid sample rate: %d\n", par->sample_rate);
|
||
|
return AVERROR_INVALIDDATA;
|
||
|
}
|
||
|
|
||
|
st->duration = bytestream2_get_be32u(&gbc) * 14;
|
||
|
redspark->samples_count = 0;
|
||
|
bytestream2_skipu(&gbc, 10);
|
||
|
par->channels = bytestream2_get_byteu(&gbc);
|
||
|
if (!par->channels) {
|
||
|
return AVERROR_INVALIDDATA;
|
||
|
}
|
||
|
|
||
|
coef_off = 0x54 + par->channels * 8;
|
||
|
if (bytestream2_get_byteu(&gbc)) // Loop flag
|
||
|
coef_off += 16;
|
||
|
|
||
|
if (coef_off + par->channels * (32 + 14) > HEADER_SIZE) {
|
||
|
return AVERROR_INVALIDDATA;
|
||
|
}
|
||
|
|
||
|
if (ff_alloc_extradata(par, 32 * par->channels)) {
|
||
|
return AVERROR_INVALIDDATA;
|
||
|
}
|
||
|
|
||
|
/* Get the ADPCM table */
|
||
|
bytestream2_seek(&gbc, coef_off, SEEK_SET);
|
||
|
for (i = 0; i < par->channels; i++) {
|
||
|
if (bytestream2_get_bufferu(&gbc, par->extradata + i * 32, 32) != 32) {
|
||
|
return AVERROR_INVALIDDATA;
|
||
|
}
|
||
|
bytestream2_skipu(&gbc, 14);
|
||
|
}
|
||
|
|
||
|
avpriv_set_pts_info(st, 64, 1, par->sample_rate);
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
static int redspark_read_packet(AVFormatContext *s, AVPacket *pkt)
|
||
|
{
|
||
|
AVCodecParameters *par = s->streams[0]->codecpar;
|
||
|
RedSparkContext *redspark = s->priv_data;
|
||
|
uint32_t size = 8 * par->channels;
|
||
|
int ret;
|
||
|
|
||
|
if (avio_feof(s->pb) || redspark->samples_count == s->streams[0]->duration)
|
||
|
return AVERROR_EOF;
|
||
|
|
||
|
ret = av_get_packet(s->pb, pkt, size);
|
||
|
if (ret != size) {
|
||
|
return AVERROR(EIO);
|
||
|
}
|
||
|
|
||
|
pkt->duration = 14;
|
||
|
redspark->samples_count += pkt->duration;
|
||
|
pkt->stream_index = 0;
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
AVInputFormat ff_redspark_demuxer = {
|
||
|
.name = "redspark",
|
||
|
.long_name = NULL_IF_CONFIG_SMALL("RedSpark"),
|
||
|
.priv_data_size = sizeof(RedSparkContext),
|
||
|
.read_probe = redspark_probe,
|
||
|
.read_header = redspark_read_header,
|
||
|
.read_packet = redspark_read_packet,
|
||
|
.extensions = "rsd",
|
||
|
};
|