2017-10-13 17:50:28 +00:00
|
|
|
#include "../plugin.h"
|
|
|
|
#include "../engine.h"
|
|
|
|
|
|
|
|
#include "libavcodec/avcodec.h"
|
|
|
|
#include "libavformat/avformat.h"
|
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
static size_t activedecoders;
|
2019-01-20 16:26:50 +00:00
|
|
|
static cvar_t *ffmpeg_audiodecoder, *pdeveloper;
|
2017-10-13 17:50:28 +00:00
|
|
|
|
2018-11-19 06:37:25 +00:00
|
|
|
#define HAVE_DECOUPLED_API (LIBAVCODEC_VERSION_MAJOR>57 || (LIBAVCODEC_VERSION_MAJOR==57&&LIBAVCODEC_VERSION_MINOR>=36))
|
|
|
|
|
2017-10-13 17:50:28 +00:00
|
|
|
struct avaudioctx
|
|
|
|
{
|
|
|
|
//raw file
|
|
|
|
uint8_t *filedata;
|
|
|
|
size_t fileofs;
|
|
|
|
size_t filesize;
|
|
|
|
|
|
|
|
//avformat stuff
|
|
|
|
AVFormatContext *pFormatCtx;
|
|
|
|
int audioStream;
|
|
|
|
|
|
|
|
AVCodecContext *pACodecCtx;
|
|
|
|
AVFrame *pAFrame;
|
|
|
|
|
|
|
|
//decoding
|
|
|
|
int64_t lasttime;
|
|
|
|
|
|
|
|
//output audio
|
|
|
|
//we throw away data if the format changes. which is awkward, but gah.
|
2020-04-29 10:43:22 +00:00
|
|
|
int64_t samples_framestart;
|
2017-10-13 17:50:28 +00:00
|
|
|
int samples_channels;
|
|
|
|
int samples_speed;
|
2020-04-29 10:43:22 +00:00
|
|
|
qaudiofmt_t samples_format;
|
2017-10-13 17:50:28 +00:00
|
|
|
qbyte *samples_buffer;
|
2020-04-29 10:43:22 +00:00
|
|
|
size_t samples_framecount;
|
|
|
|
size_t samples_maxbytes;
|
2017-10-13 17:50:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void S_AV_Purge(sfx_t *s)
|
|
|
|
{
|
|
|
|
struct avaudioctx *ctx = (struct avaudioctx*)s->decoder.buf;
|
|
|
|
|
|
|
|
s->loadstate = SLS_NOTLOADED;
|
|
|
|
|
|
|
|
// Free the audio decoder
|
|
|
|
if (ctx->pACodecCtx)
|
|
|
|
avcodec_close(ctx->pACodecCtx);
|
|
|
|
av_free(ctx->pAFrame);
|
|
|
|
|
|
|
|
// Close the video file
|
|
|
|
avformat_close_input(&ctx->pFormatCtx);
|
|
|
|
|
|
|
|
//free the decoded buffer
|
|
|
|
free(ctx->samples_buffer);
|
|
|
|
|
|
|
|
//file storage will be cleared here too
|
|
|
|
free(ctx);
|
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
if (s->decoder.ended)
|
|
|
|
activedecoders--;
|
2017-10-13 17:50:28 +00:00
|
|
|
memset(&s->decoder, 0, sizeof(s->decoder));
|
|
|
|
}
|
2020-04-29 10:43:22 +00:00
|
|
|
#define QAF_U8 0x81
|
|
|
|
#define QAF_S32 0x04
|
|
|
|
#ifndef MIXER_F32
|
|
|
|
#define QAF_F32 0x84
|
|
|
|
#endif
|
|
|
|
#define QAF_F64 0x88
|
2018-11-19 06:37:25 +00:00
|
|
|
static void S_AV_ReadFrame(struct avaudioctx *ctx)
|
|
|
|
{ //reads an audioframe and spits its data into the output sound file for the game engine to use.
|
2020-04-29 10:43:22 +00:00
|
|
|
qaudiofmt_t outformat = QAF_S16, informat=QAF_S16;
|
2018-11-19 06:37:25 +00:00
|
|
|
int channels = ctx->pACodecCtx->channels;
|
2020-04-29 10:43:22 +00:00
|
|
|
int planes = 1, p;
|
2018-11-19 06:37:25 +00:00
|
|
|
unsigned int auddatasize = av_samples_get_buffer_size(NULL, ctx->pACodecCtx->channels, ctx->pAFrame->nb_samples, ctx->pACodecCtx->sample_fmt, 1);
|
|
|
|
switch(ctx->pACodecCtx->sample_fmt)
|
|
|
|
{ //we don't support planar audio. we just treat it as mono instead.
|
|
|
|
default:
|
|
|
|
auddatasize = 0;
|
|
|
|
break;
|
|
|
|
case AV_SAMPLE_FMT_U8P:
|
2020-04-29 10:43:22 +00:00
|
|
|
planes = channels;
|
|
|
|
outformat = QAF_S8;
|
|
|
|
informat = QAF_U8;
|
|
|
|
break;
|
2018-11-19 06:37:25 +00:00
|
|
|
case AV_SAMPLE_FMT_U8:
|
2020-04-29 10:43:22 +00:00
|
|
|
planes = 1;
|
|
|
|
outformat = QAF_S8;
|
|
|
|
informat = QAF_U8;
|
2018-11-19 06:37:25 +00:00
|
|
|
break;
|
|
|
|
case AV_SAMPLE_FMT_S16P:
|
2020-04-29 10:43:22 +00:00
|
|
|
planes = channels;
|
|
|
|
outformat = QAF_S16;
|
|
|
|
informat = QAF_S16;
|
|
|
|
break;
|
2018-11-19 06:37:25 +00:00
|
|
|
case AV_SAMPLE_FMT_S16:
|
2020-04-29 10:43:22 +00:00
|
|
|
planes = 1;
|
|
|
|
outformat = QAF_S16;
|
|
|
|
informat = QAF_S16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AV_SAMPLE_FMT_S32P:
|
|
|
|
planes = channels;
|
|
|
|
outformat = QAF_S16;
|
|
|
|
informat = QAF_S32;
|
|
|
|
break;
|
|
|
|
case AV_SAMPLE_FMT_S32:
|
|
|
|
planes = 1;
|
|
|
|
outformat = QAF_S16;
|
|
|
|
informat = QAF_S32;
|
2018-11-19 06:37:25 +00:00
|
|
|
break;
|
|
|
|
|
2020-04-29 10:43:22 +00:00
|
|
|
#ifdef MIXER_F32
|
2018-11-19 06:37:25 +00:00
|
|
|
case AV_SAMPLE_FMT_FLTP:
|
2020-04-29 10:43:22 +00:00
|
|
|
planes = channels;
|
|
|
|
outformat = QAF_F32;
|
|
|
|
informat = QAF_F32;
|
2018-11-19 06:37:25 +00:00
|
|
|
break;
|
|
|
|
case AV_SAMPLE_FMT_FLT:
|
2020-04-29 10:43:22 +00:00
|
|
|
planes = 1;
|
|
|
|
outformat = QAF_F32;
|
|
|
|
informat = QAF_F32;
|
2019-08-28 02:47:00 +00:00
|
|
|
break;
|
2018-11-19 06:37:25 +00:00
|
|
|
|
|
|
|
case AV_SAMPLE_FMT_DBLP:
|
2020-04-29 10:43:22 +00:00
|
|
|
planes = channels;
|
|
|
|
outformat = QAF_F32;
|
|
|
|
informat = QAF_F64;
|
|
|
|
break;
|
2018-11-19 06:37:25 +00:00
|
|
|
case AV_SAMPLE_FMT_DBL:
|
2020-04-29 10:43:22 +00:00
|
|
|
planes = 1;
|
|
|
|
outformat = QAF_F32;
|
|
|
|
informat = QAF_F64;
|
|
|
|
break;
|
|
|
|
#else
|
|
|
|
case AV_SAMPLE_FMT_FLTP:
|
|
|
|
planes = channels;
|
|
|
|
outformat = QAF_S16;
|
|
|
|
informat = QAF_F32;
|
|
|
|
break;
|
|
|
|
case AV_SAMPLE_FMT_FLT:
|
|
|
|
planes = 1;
|
|
|
|
outformat = QAF_S16;
|
|
|
|
informat = QAF_F32;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AV_SAMPLE_FMT_DBLP:
|
|
|
|
planes = channels;
|
|
|
|
outformat = QAF_S16;
|
|
|
|
informat = QAF_F64;
|
2018-11-19 06:37:25 +00:00
|
|
|
break;
|
2020-04-29 10:43:22 +00:00
|
|
|
case AV_SAMPLE_FMT_DBL:
|
|
|
|
planes = 1;
|
|
|
|
outformat = QAF_S16;
|
|
|
|
informat = QAF_F64;
|
|
|
|
break;
|
|
|
|
#endif
|
2018-11-19 06:37:25 +00:00
|
|
|
}
|
2020-04-29 10:43:22 +00:00
|
|
|
|
|
|
|
if (ctx->samples_channels != channels || ctx->samples_speed != ctx->pACodecCtx->sample_rate || ctx->samples_format != outformat)
|
2018-11-19 06:37:25 +00:00
|
|
|
{ //something changed, update
|
|
|
|
ctx->samples_channels = channels;
|
|
|
|
ctx->samples_speed = ctx->pACodecCtx->sample_rate;
|
2020-04-29 10:43:22 +00:00
|
|
|
ctx->samples_format = outformat;
|
2018-11-19 06:37:25 +00:00
|
|
|
|
|
|
|
//and discard any decoded audio. this might loose some.
|
2020-04-29 10:43:22 +00:00
|
|
|
ctx->samples_framestart += ctx->samples_framecount;
|
|
|
|
ctx->samples_framecount = 0;
|
2018-11-19 06:37:25 +00:00
|
|
|
}
|
2020-04-29 10:43:22 +00:00
|
|
|
if (ctx->samples_maxbytes < (ctx->samples_framecount*QAF_BYTES(ctx->samples_format)*ctx->samples_channels)+auddatasize)
|
2018-11-19 06:37:25 +00:00
|
|
|
{
|
2020-04-29 10:43:22 +00:00
|
|
|
ctx->samples_maxbytes = (ctx->samples_framecount*QAF_BYTES(ctx->samples_format)*ctx->samples_channels)+auddatasize;
|
|
|
|
ctx->samples_maxbytes *= 2; //slop
|
|
|
|
ctx->samples_buffer = realloc(ctx->samples_buffer, ctx->samples_maxbytes);
|
2018-11-19 06:37:25 +00:00
|
|
|
}
|
2020-04-29 10:43:22 +00:00
|
|
|
if (planes==1 && outformat != QAF_S8 && informat==outformat)
|
|
|
|
memcpy(ctx->samples_buffer + ctx->samples_framecount*(QAF_BYTES(ctx->samples_format)*ctx->samples_channels), ctx->pAFrame->data[0], auddatasize);
|
2018-11-19 06:37:25 +00:00
|
|
|
else
|
2020-04-29 10:43:22 +00:00
|
|
|
{
|
|
|
|
void *fte_restrict outv = (ctx->samples_buffer + ctx->samples_framecount*(QAF_BYTES(ctx->samples_format)*ctx->samples_channels));
|
|
|
|
size_t i, samples = auddatasize / (planes*QAF_BYTES(informat));
|
|
|
|
if (outformat == QAF_S8 && informat == QAF_U8)
|
|
|
|
{
|
|
|
|
char *out = outv;
|
|
|
|
for (p = 0; p < planes; p++, out++)
|
|
|
|
{
|
|
|
|
unsigned char *in = ctx->pAFrame->data[p];
|
|
|
|
for (i = 0; i < samples; i++)
|
|
|
|
out[i*planes] = in[i]-128; //convert from u8 to s8.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (outformat == QAF_S16 && informat == QAF_S16)
|
|
|
|
{
|
|
|
|
signed short *out = outv;
|
|
|
|
for (p = 0; p < planes; p++, out++)
|
|
|
|
{
|
|
|
|
signed short *in = (signed short *)ctx->pAFrame->data[p];
|
|
|
|
for (i = 0; i < samples; i++)
|
|
|
|
out[i*planes] = in[i]; //no conversion needed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (outformat == QAF_S16 && informat == QAF_S32)
|
|
|
|
{
|
|
|
|
signed short *out = outv;
|
|
|
|
for (p = 0; p < planes; p++, out++)
|
|
|
|
{
|
|
|
|
signed int *in = (signed int *)ctx->pAFrame->data[p];
|
|
|
|
for (i = 0; i < samples; i++)
|
|
|
|
out[i*planes] = in[i]>>16; //just use the MSBs, no clamping needed.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef MIXER_F32
|
|
|
|
else if (outformat == QAF_F32 && informat == QAF_F32)
|
|
|
|
{
|
|
|
|
float *out = outv;
|
|
|
|
for (p = 0; p < planes; p++, out++)
|
|
|
|
{
|
|
|
|
float *in = (float *)ctx->pAFrame->data[p];
|
|
|
|
for (i = 0; i < samples; i++)
|
|
|
|
out[i*planes] = in[i]; //no conversion needed.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (outformat == QAF_F32 && informat == QAF_F64)
|
|
|
|
{
|
|
|
|
float *out = outv;
|
|
|
|
for (p = 0; p < planes; p++, out++)
|
|
|
|
{
|
|
|
|
double *in = (double *)ctx->pAFrame->data[p];
|
|
|
|
for (i = 0; i < samples; i++)
|
|
|
|
out[i*planes] = in[i]; //no clamping needed.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
else if (outformat == QAF_S16 && informat == QAF_F32)
|
|
|
|
{
|
|
|
|
signed short *out = outv;
|
|
|
|
for (p = 0; p < planes; p++, out++)
|
|
|
|
{
|
|
|
|
float *in = (float *)ctx->pAFrame->data[p];
|
|
|
|
for (i = 0; i < samples; i++)
|
|
|
|
{
|
|
|
|
int v = in[i] * 32767;
|
|
|
|
if (v < -32768)
|
|
|
|
v = -32768;
|
|
|
|
if (v > 32767)
|
|
|
|
v = 32767;
|
|
|
|
out[i*planes] = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (outformat == QAF_S16 && informat == QAF_F64)
|
|
|
|
{
|
|
|
|
signed short *out = outv;
|
|
|
|
for (p = 0; p < planes; p++, out++)
|
|
|
|
{
|
|
|
|
double *in = (double *)ctx->pAFrame->data[p];
|
|
|
|
for (i = 0; i < samples; i++)
|
|
|
|
{
|
|
|
|
int v = in[i] * 32767;
|
|
|
|
if (v < -32768)
|
|
|
|
v = -32768;
|
|
|
|
if (v > 32767)
|
|
|
|
v = 32767;
|
|
|
|
out[i*planes] = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
ctx->samples_framecount += auddatasize/(QAF_BYTES(informat)*ctx->samples_channels);
|
2018-11-19 06:37:25 +00:00
|
|
|
}
|
2017-10-13 17:50:28 +00:00
|
|
|
static sfxcache_t *S_AV_Locate(sfx_t *sfx, sfxcache_t *buf, ssamplepos_t start, int length)
|
|
|
|
{ //warning: can be called on a different thread.
|
|
|
|
struct avaudioctx *ctx = (struct avaudioctx*)sfx->decoder.buf;
|
|
|
|
AVPacket packet;
|
|
|
|
int64_t curtime;
|
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
curtime = start + length;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2020-04-29 10:43:22 +00:00
|
|
|
if (start < ctx->samples_framestart)
|
2018-11-19 06:37:25 +00:00
|
|
|
break; //o.O rewind!
|
|
|
|
|
2020-04-29 10:43:22 +00:00
|
|
|
if (ctx->samples_framestart+ctx->samples_framecount > curtime)
|
2018-11-19 06:37:25 +00:00
|
|
|
break; //no need yet.
|
|
|
|
|
|
|
|
#ifdef HAVE_DECOUPLED_API
|
|
|
|
if(0==avcodec_receive_frame(ctx->pACodecCtx, ctx->pAFrame))
|
|
|
|
{
|
|
|
|
S_AV_ReadFrame(ctx);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
2017-10-13 17:50:28 +00:00
|
|
|
|
|
|
|
// We're ahead of the previous frame. try and read the next.
|
|
|
|
if (av_read_frame(ctx->pFormatCtx, &packet) < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Is this a packet from the video stream?
|
|
|
|
if(packet.stream_index==ctx->audioStream)
|
|
|
|
{
|
2018-11-19 06:37:25 +00:00
|
|
|
#ifdef HAVE_DECOUPLED_API
|
|
|
|
avcodec_send_packet(ctx->pACodecCtx, &packet);
|
|
|
|
#else
|
2017-10-13 17:50:28 +00:00
|
|
|
int okay;
|
|
|
|
int len;
|
|
|
|
void *odata = packet.data;
|
|
|
|
while (packet.size > 0)
|
2018-11-19 06:37:25 +00:00
|
|
|
{ //this old api only decodes part of the packet with each itteration, so keep reading until we decoded the entire thing.
|
2017-10-13 17:50:28 +00:00
|
|
|
okay = false;
|
|
|
|
len = avcodec_decode_audio4(ctx->pACodecCtx, ctx->pAFrame, &okay, &packet);
|
|
|
|
if (len < 0)
|
|
|
|
break;
|
|
|
|
packet.size -= len;
|
|
|
|
packet.data += len;
|
|
|
|
if (okay)
|
2018-11-19 06:37:25 +00:00
|
|
|
S_AV_ReadFrame(ctx);
|
2017-10-13 17:50:28 +00:00
|
|
|
}
|
|
|
|
packet.data = odata;
|
2018-11-19 06:37:25 +00:00
|
|
|
#endif
|
2017-10-13 17:50:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Free the packet that was allocated by av_read_frame
|
|
|
|
av_packet_unref(&packet);
|
|
|
|
}
|
|
|
|
|
2020-04-29 10:43:22 +00:00
|
|
|
buf->length = ctx->samples_framecount;
|
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
|
|
|
buf->speed = ctx->samples_speed;
|
2020-04-29 10:43:22 +00:00
|
|
|
buf->format = ctx->samples_format;
|
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
|
|
|
buf->numchannels = ctx->samples_channels;
|
2020-04-29 10:43:22 +00:00
|
|
|
buf->soundoffset = ctx->samples_framestart;
|
2017-10-13 17:50:28 +00:00
|
|
|
buf->data = ctx->samples_buffer;
|
|
|
|
|
|
|
|
//if we couldn't return any new data, then we're at an eof, return NULL to signal that.
|
|
|
|
if (start == buf->soundoffset + buf->length && length > 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
|
|
|
static float S_AV_Query(struct sfx_s *sfx, struct sfxcache_s *buf, char *title, size_t titlesize)
|
|
|
|
{
|
|
|
|
struct avaudioctx *ctx = (struct avaudioctx*)sfx->decoder.buf;
|
|
|
|
if (!ctx)
|
|
|
|
return -1;
|
|
|
|
if (buf)
|
|
|
|
{
|
|
|
|
buf->data = NULL;
|
|
|
|
buf->soundoffset = 0;
|
|
|
|
buf->length = 0;
|
|
|
|
buf->numchannels = ctx->samples_channels;
|
|
|
|
buf->speed = ctx->samples_speed;
|
2020-04-29 10:43:22 +00:00
|
|
|
buf->format = ctx->samples_format;
|
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
|
|
|
}
|
|
|
|
return ctx->pFormatCtx->duration / (float)AV_TIME_BASE;
|
2017-10-13 17:50:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int AVIO_Mem_Read(void *opaque, uint8_t *buf, int buf_size)
|
|
|
|
{
|
|
|
|
struct avaudioctx *ctx = opaque;
|
|
|
|
if (ctx->fileofs > ctx->filesize)
|
|
|
|
buf_size = 0;
|
|
|
|
if (buf_size > ctx->filesize-ctx->fileofs)
|
|
|
|
buf_size = ctx->filesize-ctx->fileofs;
|
|
|
|
if (buf_size > 0)
|
|
|
|
{
|
|
|
|
memcpy(buf, ctx->filedata + ctx->fileofs, buf_size);
|
|
|
|
ctx->fileofs += buf_size;
|
|
|
|
return buf_size;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static int64_t AVIO_Mem_Seek(void *opaque, int64_t offset, int whence)
|
|
|
|
{
|
|
|
|
struct avaudioctx *ctx = opaque;
|
|
|
|
whence &= ~AVSEEK_FORCE;
|
|
|
|
switch(whence)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
case SEEK_SET:
|
|
|
|
ctx->fileofs = offset;
|
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
|
|
|
ctx->fileofs += offset;
|
|
|
|
break;
|
|
|
|
case SEEK_END:
|
|
|
|
ctx->fileofs = ctx->filesize + offset;
|
|
|
|
break;
|
|
|
|
case AVSEEK_SIZE:
|
|
|
|
return ctx->filesize;
|
|
|
|
}
|
|
|
|
if (ctx->fileofs < 0)
|
|
|
|
ctx->fileofs = 0;
|
|
|
|
return ctx->fileofs;
|
|
|
|
}
|
|
|
|
|
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
|
|
|
/*const char *COM_GetFileExtension (const char *in)
|
|
|
|
{
|
|
|
|
const char *dot;
|
|
|
|
|
|
|
|
for (dot = in + strlen(in); dot >= in && *dot != '.'; dot--)
|
|
|
|
;
|
|
|
|
if (dot < in)
|
|
|
|
return "";
|
|
|
|
in = dot+1;
|
|
|
|
return in;
|
2017-10-13 17:50:28 +00:00
|
|
|
}*/
|
|
|
|
static qboolean QDECL S_LoadAVSound (sfx_t *s, qbyte *data, size_t datalen, int sndspeed)
|
|
|
|
{
|
|
|
|
struct avaudioctx *ctx;
|
|
|
|
int i;
|
|
|
|
AVCodec *pCodec;
|
|
|
|
const int iBufSize = 4 * 1024;
|
|
|
|
|
|
|
|
if (!ffmpeg_audiodecoder)
|
2018-04-06 17:21:15 +00:00
|
|
|
return false;
|
2019-09-04 07:59:40 +00:00
|
|
|
if (!ffmpeg_audiodecoder->ival /* && *ffmpeg_audiodecoder.string */)
|
2017-10-13 17:50:28 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
if (!data || !datalen)
|
|
|
|
return false;
|
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
//ignore it if it looks like a wav file. that means we don't need to figure out how to calculate loopstart.
|
|
|
|
//FIXME: this also blocks playing the audio from avi files too!
|
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
|
|
|
if (datalen >= 4 && !strncmp(data, "RIFF", 4))
|
2019-09-04 07:59:40 +00:00
|
|
|
return false;
|
|
|
|
|
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
|
|
|
// if (strcasecmp(COM_GetFileExtension(s->name), "wav")) //don't do .wav - I've no idea how to read the loopstart tag with ffmpeg.
|
2017-10-13 17:50:28 +00:00
|
|
|
// return false;
|
|
|
|
|
|
|
|
s->decoder.buf = ctx = malloc(sizeof(*ctx) + datalen);
|
|
|
|
if (!ctx)
|
|
|
|
return false; //o.O
|
|
|
|
memset(ctx, 0, sizeof(*ctx));
|
|
|
|
|
|
|
|
// Create internal io buffer for FFmpeg
|
|
|
|
ctx->filedata = data; //defer that copy
|
|
|
|
ctx->filesize = datalen; //defer that copy
|
|
|
|
ctx->pFormatCtx = avformat_alloc_context();
|
|
|
|
ctx->pFormatCtx->pb = avio_alloc_context(av_malloc(iBufSize), iBufSize, 0, ctx, AVIO_Mem_Read, 0, AVIO_Mem_Seek);
|
|
|
|
|
|
|
|
// Open file
|
|
|
|
if(avformat_open_input(&ctx->pFormatCtx, s->name, NULL, NULL)==0)
|
|
|
|
{
|
|
|
|
// Retrieve stream information
|
|
|
|
if(avformat_find_stream_info(ctx->pFormatCtx, NULL)>=0)
|
|
|
|
{
|
|
|
|
ctx->audioStream=-1;
|
|
|
|
for(i=0; i<ctx->pFormatCtx->nb_streams; i++)
|
2018-11-19 06:37:25 +00:00
|
|
|
#if LIBAVFORMAT_VERSION_MAJOR >= 57
|
|
|
|
if(ctx->pFormatCtx->streams[i]->codecpar->codec_type==AVMEDIA_TYPE_AUDIO)
|
|
|
|
#else
|
2017-10-13 17:50:28 +00:00
|
|
|
if(ctx->pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO)
|
2018-11-19 06:37:25 +00:00
|
|
|
#endif
|
2017-10-13 17:50:28 +00:00
|
|
|
{
|
|
|
|
ctx->audioStream=i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(ctx->audioStream!=-1)
|
|
|
|
{
|
2018-11-19 06:37:25 +00:00
|
|
|
#if LIBAVFORMAT_VERSION_MAJOR >= 57
|
|
|
|
pCodec=avcodec_find_decoder(ctx->pFormatCtx->streams[ctx->audioStream]->codecpar->codec_id);
|
|
|
|
ctx->pACodecCtx = avcodec_alloc_context3(pCodec);
|
|
|
|
if (avcodec_parameters_to_context(ctx->pACodecCtx, ctx->pFormatCtx->streams[ctx->audioStream]->codecpar) < 0)
|
|
|
|
{
|
|
|
|
avcodec_free_context(&ctx->pACodecCtx);
|
|
|
|
pCodec = NULL;
|
|
|
|
}
|
|
|
|
#else
|
2017-10-13 17:50:28 +00:00
|
|
|
ctx->pACodecCtx=ctx->pFormatCtx->streams[ctx->audioStream]->codec;
|
|
|
|
pCodec=avcodec_find_decoder(ctx->pACodecCtx->codec_id);
|
2018-11-19 06:37:25 +00:00
|
|
|
#endif
|
2017-10-13 17:50:28 +00:00
|
|
|
ctx->pAFrame=av_frame_alloc();
|
|
|
|
if(pCodec!=NULL && ctx->pAFrame && avcodec_open2(ctx->pACodecCtx, pCodec, NULL) >= 0)
|
|
|
|
{ //success
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ctx->audioStream = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->audioStream != -1)
|
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
|
|
|
{
|
|
|
|
//sucky copy
|
2017-10-13 17:50:28 +00:00
|
|
|
ctx->filedata = (uint8_t*)(ctx+1);
|
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
|
|
|
memcpy(ctx->filedata, data, datalen);
|
|
|
|
|
|
|
|
s->decoder.ended = S_AV_Purge;
|
|
|
|
s->decoder.purge = S_AV_Purge;
|
|
|
|
s->decoder.decodedata = S_AV_Locate;
|
2017-10-13 17:50:28 +00:00
|
|
|
s->decoder.querydata = S_AV_Query;
|
2019-09-04 07:59:40 +00:00
|
|
|
activedecoders++;
|
2017-10-13 17:50:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
S_AV_Purge(s);
|
|
|
|
return false;
|
|
|
|
}
|
2019-09-04 07:59:40 +00:00
|
|
|
qboolean AVAudio_MayUnload(void)
|
|
|
|
{
|
|
|
|
return activedecoders==0;
|
|
|
|
}
|
2017-10-13 17:50:28 +00:00
|
|
|
static qboolean AVAudio_Init(void)
|
|
|
|
{
|
2019-09-04 07:59:40 +00:00
|
|
|
if (!plugfuncs->ExportFunction("MayUnload", AVAudio_MayUnload) ||
|
|
|
|
!plugfuncs->ExportFunction("S_LoadSound", S_LoadAVSound))
|
2017-10-13 17:50:28 +00:00
|
|
|
{
|
2019-09-04 07:59:40 +00:00
|
|
|
Con_Printf("ffmpeg: Engine doesn't support audio decoder plugins\n");
|
2017-10-13 17:50:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-09-04 07:59:40 +00:00
|
|
|
ffmpeg_audiodecoder = cvarfuncs->GetNVFDG("ffmpeg_audiodecoder_wip", "1", 0, "Enables the use of ffmpeg's decoder for pure audio files.", "ffmpeg");
|
|
|
|
if (!ffmpeg_audiodecoder->ival)
|
|
|
|
Con_Printf("ffmpeg: audio decoding disabled, use \"set %s 1\" to enable ffmpeg audio decoding\n", ffmpeg_audiodecoder->name);
|
2017-10-13 17:50:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//generic module stuff. this has to go somewhere.
|
|
|
|
static void AVLogCallback(void *avcl, int level, const char *fmt, va_list vl)
|
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
|
|
|
{ //needs to be reenterant
|
|
|
|
#ifdef _DEBUG
|
|
|
|
char string[1024];
|
|
|
|
Q_vsnprintf (string, sizeof(string), fmt, vl);
|
2019-01-20 16:26:50 +00:00
|
|
|
if (pdeveloper && pdeveloper->ival)
|
2019-09-04 07:59:40 +00:00
|
|
|
Con_Printf("%s", string);
|
2017-10-13 17:50:28 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//get the encoder/decoders to register themselves with the engine, then make sure avformat/avcodec have registered all they have to give.
|
|
|
|
qboolean AVEnc_Init(void);
|
|
|
|
qboolean AVDec_Init(void);
|
2019-09-04 07:59:40 +00:00
|
|
|
qboolean Plug_Init(void)
|
2017-10-13 17:50:28 +00:00
|
|
|
{
|
|
|
|
qboolean okay = false;
|
|
|
|
|
|
|
|
okay |= AVAudio_Init();
|
|
|
|
okay |= AVDec_Init();
|
|
|
|
okay |= AVEnc_Init();
|
|
|
|
if (okay)
|
|
|
|
{
|
2018-11-19 06:37:25 +00:00
|
|
|
#if ( LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58,9,100) )
|
2017-10-13 17:50:28 +00:00
|
|
|
av_register_all();
|
|
|
|
avcodec_register_all();
|
2018-11-19 06:37:25 +00:00
|
|
|
#endif
|
2017-10-13 17:50:28 +00:00
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
pdeveloper = cvarfuncs->GetNVFDG("developer", "0", 0, "Developer spam.", "ffmpeg");
|
2017-10-13 17:50:28 +00:00
|
|
|
av_log_set_level(AV_LOG_WARNING);
|
|
|
|
av_log_set_callback(AVLogCallback);
|
|
|
|
}
|
|
|
|
return okay;
|
|
|
|
}
|
|
|
|
|