my attempt at linux-friendly plugin code. cross compiling for win32 should be okay now, just need to add the setting to the buildbot.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4335 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
11c7f5965a
commit
78185c2721
5 changed files with 839 additions and 747 deletions
|
@ -1,9 +1,53 @@
|
||||||
|
|
||||||
|
#windows is special as always, but we don't support itanium, and microsoft don't support anything else (not even arm with the nt win32 api)
|
||||||
|
ifeq ($(FTE_TARGET),win32)
|
||||||
|
PLUG_NATIVE_EXT=x86.dll
|
||||||
|
PLUG_LDFLAGS=-Lavplug/lib32 -L../engine/libs/mingw-libs -lzlib
|
||||||
|
endif
|
||||||
|
ifeq ($(FTE_TARGET),win64)
|
||||||
|
PLUG_NATIVE_EXT=amd.dll
|
||||||
|
PLUG_LDFLAGS=-Lavplug/lib64 -L../engine/libs/mingw64-libs -lz -Wl,--support-old-code
|
||||||
|
endif
|
||||||
|
|
||||||
|
PLUG_LDFLAGS?=-L/usr/local/lib -Wl,-R/usr/local/lib -lz
|
||||||
|
|
||||||
|
ifneq ($(PLUG_NATIVE_EXT),)
|
||||||
|
#if we're on windows, we'll put our windows-specific hacks here.
|
||||||
|
PLUG_DEFFILE=plugin.def
|
||||||
|
PLUG_CFLAGS=
|
||||||
|
|
||||||
|
$(OUT_DIR)/fteplug_avplug$(PLUG_NATIVE_EXT): avplug/libavformat/avformat.h
|
||||||
|
endif
|
||||||
|
|
||||||
|
#if they're not on windows, we'll try asking the compiler directly
|
||||||
|
#the check to see if its already set is to avoid asking msvc, which would probably break things.
|
||||||
|
ifeq ($(PLUG_NATIVE_EXT),)
|
||||||
|
ifneq ($(shell echo|$(CC) -E -dM -|grep __amd64__),)
|
||||||
|
PLUG_NATIVE_EXT=amd.so
|
||||||
|
endif
|
||||||
|
ifneq ($(shell echo|$(CC) -E -dM -|grep __i386__),)
|
||||||
|
PLUG_NATIVE_EXT=x86.so
|
||||||
|
endif
|
||||||
|
ifneq ($(shell echo|$(CC) -E -dM -|grep __arm__),)
|
||||||
|
PLUG_NATIVE_EXT=arm.so
|
||||||
|
endif
|
||||||
|
ifneq ($(shell echo|$(CC) -E -dM -|grep __ppc__),)
|
||||||
|
PLUG_NATIVE_EXT=ppc.so
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
#fallback
|
||||||
|
PLUG_NATIVE_EXT?=unk.so
|
||||||
|
|
||||||
|
PLUG_DEFFILE?=
|
||||||
|
PLUG_CFLAGS?=-fPIC -Wl,--no-undefined
|
||||||
|
PLUG_LDFLAGS?=
|
||||||
|
|
||||||
all: ezscript hud irc
|
all: ezscript hud irc
|
||||||
|
|
||||||
clean: ezscript-clean hud-clean irc-clean
|
clean: ezscript-clean hud-clean irc-clean
|
||||||
|
|
||||||
.PHONY: all ezscript hud irc
|
.PHONY: all ezscript hud irc native distclean clean
|
||||||
|
|
||||||
help:
|
help:
|
||||||
@-echo make a subdirectory
|
@-echo make a subdirectory
|
||||||
|
@ -26,7 +70,37 @@ irc:
|
||||||
irc-clean:
|
irc-clean:
|
||||||
$(MAKE) clean -C irc
|
$(MAKE) clean -C irc
|
||||||
|
|
||||||
|
#small script to download+install avformat for windows cross compiles.
|
||||||
|
#linux users are expected to have the library installed locally already. If your version is too old or missing, run the following command to install it (to /usr/local), then delete the gz and directory.
|
||||||
|
#wget http://ffmpeg.org/releases/ffmpeg-1.2.tar.gz && cd tar xvfz ffmpeg-1.2.tar.gz && cd ffmpeg-1.2/ && ./configure --disable-yasm --enable-shared && make && sudo make install
|
||||||
|
#we use ffmpeg's version for some reason, as opposed to libav. not sure what the differences are meant to be, but libav seemed to have non-depricated functions defined, docs that say to use them, and these functions missing.
|
||||||
|
AV7Z_VER=ffmpeg-1.2
|
||||||
|
AV7Z_W32=$(AV7Z_VER)-win32-dev.7z
|
||||||
|
AV7Z_URL32=http://ffmpeg.zeranoe.com/builds/win32/dev/$(AV7Z_W32)
|
||||||
|
AV7Z_PRE32=$(AV7Z_VER)-win32-dev/
|
||||||
|
AV7Z_W64=$(AV7Z_VER)-win64-dev.7z
|
||||||
|
AV7Z_URL64=http://ffmpeg.zeranoe.com/builds/win64/dev/$(AV7Z_W64)
|
||||||
|
AV7Z_PRE64=$(AV7Z_VER)-win64-dev/
|
||||||
|
avplug/libavformat/avformat.h:
|
||||||
|
wget $(AV7Z_URL32)
|
||||||
|
mkdir -p avplug/libavformat && cd avplug/libavformat && 7z e -y ../../$(AV7Z_W32) $(AV7Z_PRE32)include/libavformat/ && cd -
|
||||||
|
mkdir -p avplug/libavcodec && cd avplug/libavcodec && 7z e -y ../../$(AV7Z_W32) $(AV7Z_PRE32)include/libavcodec/ && cd -
|
||||||
|
mkdir -p avplug/libavutil && cd avplug/libavutil && 7z e -y ../../$(AV7Z_W32) $(AV7Z_PRE32)include/libavutil/ && cd -
|
||||||
|
mkdir -p avplug/libswscale && cd avplug/libswscale && 7z e -y ../../$(AV7Z_W32) $(AV7Z_PRE32)include/libswscale/ && cd -
|
||||||
|
mkdir -p avplug/lib32 && cd avplug/lib32 && 7z e -y ../../$(AV7Z_W32) $(AV7Z_PRE32)lib/avformat.lib $(AV7Z_PRE32)lib/avcodec.lib $(AV7Z_PRE32)lib/avutil.lib $(AV7Z_PRE32)lib/swscale.lib && cd -
|
||||||
|
rm $(AV7Z_W32)
|
||||||
|
wget $(AV7Z_URL64)
|
||||||
|
mkdir -p avplug/lib64 && cd avplug/lib64 && 7z e -y ../../$(AV7Z_W64) $(AV7Z_PRE64)lib/avformat.lib $(AV7Z_PRE64)lib/avcodec.lib $(AV7Z_PRE64)lib/avutil.lib $(AV7Z_PRE64)lib/swscale.lib && cd -
|
||||||
|
rm $(AV7Z_W64)
|
||||||
|
distclean:
|
||||||
|
rm avplug/libavformat/avformat.h
|
||||||
|
|
||||||
|
$(OUT_DIR)/fteplug_avplug$(PLUG_NATIVE_EXT): avplug/avencode.c avplug/avdecode.c plugin.c
|
||||||
|
$(CC) $(BASE_CFLAGS) -DFTEPLUGIN -s -o $(OUT_DIR)/fteplug_avplug$(PLUG_NATIVE_EXT) -shared $(PLUG_CFLAGS) -Iavplug/msvc_lib $^ $(PLUG_DEFFILE) $(PLUG_LDFLAGS) -lavcodec -lavformat -lavutil -lswscale
|
||||||
|
native: $(OUT_DIR)/fteplug_avplug$(PLUG_NATIVE_EXT)
|
||||||
|
|
||||||
|
$(OUT_DIR)/fteplug_mpq$(PLUG_NATIVE_EXT): mpq/fs_mpq.c mpq/blast.c plugin.c qvm_api.c
|
||||||
|
$(CC) $(BASE_CFLAGS) -DFTEPLUGIN -o $(OUT_DIR)/fteplug_mpq$(PLUG_NATIVE_EXT) -shared $(PLUG_CFLAGS) -Impq $^ $(PLUG_DEFFILE) $(PLUG_LDFLAGS)
|
||||||
|
native: $(OUT_DIR)/fteplug_mpq$(PLUG_NATIVE_EXT)
|
||||||
|
|
||||||
native:
|
native:
|
||||||
@echo outdir = $(OUT_DIR)
|
|
||||||
$(CC) -o $(OUT_DIR)/fteplug_avplugx86.dll -shared -Iavplug -Iavplug/libavformat -Iavplug/libavcodec -Iavplug/libavutil -Iavplug/libswscale -Iavplug/msvc_lib avplug/avencode.c avplug/avdecode.c plugin.def plugin.c -Lavplug/lib32 -lavcodec -lavformat -lavutil -lswscale -lwinmm
|
|
||||||
$(CC) $(BASE_CFLAGS) -DFTEPLUGIN -o $(OUT_DIR)/fteplug_mpqx86.dll -shared -Impq mpq/fs_mpq.c mpq/blast.c plugin.def plugin.c qvm_api.c -Lavplug/lib32 -L../engine/libs/mingw-libs -lzlib
|
|
|
@ -1,10 +1,22 @@
|
||||||
#include "../plugin.h"
|
#include "../plugin.h"
|
||||||
#include "../engine.h"
|
#include "../engine.h"
|
||||||
|
|
||||||
#include <avcodec.h>
|
#include <libavcodec/avcodec.h>
|
||||||
#include <avformat.h>
|
#include <libavformat/avformat.h>
|
||||||
#include <swscale.h>
|
#include <libswscale/swscale.h>
|
||||||
#include <windows.h>
|
|
||||||
|
//between av 52.31 and 54.35, lots of constants etc got renamed to gain an extra AV_ prefix.
|
||||||
|
/*
|
||||||
|
#define AV_PIX_FMT_BGRA PIX_FMT_BGRA
|
||||||
|
#define AVMEDIA_TYPE_AUDIO CODEC_TYPE_AUDIO
|
||||||
|
#define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
|
||||||
|
#define AV_PIX_FMT_BGRA PIX_FMT_BGRA
|
||||||
|
#define AV_SAMPLE_FMT_U8 SAMPLE_FMT_U8
|
||||||
|
#define AV_SAMPLE_FMT_S16 SAMPLE_FMT_S16
|
||||||
|
#define AV_SAMPLE_FMT_FLT SAMPLE_FMT_FLT
|
||||||
|
#define AVIOContext ByteIOContext
|
||||||
|
#define avio_alloc_context av_alloc_put_byte
|
||||||
|
*/
|
||||||
|
|
||||||
#define ARGNAMES ,sourceid, data, speed, samples, channels, width
|
#define ARGNAMES ,sourceid, data, speed, samples, channels, width
|
||||||
BUILTIN(void, S_RawAudio, (int sourceid, void *data, int speed, int samples, int channels, int width));
|
BUILTIN(void, S_RawAudio, (int sourceid, void *data, int speed, int samples, int channels, int width));
|
||||||
|
@ -71,7 +83,7 @@ static int AVIO_Read(void *opaque, uint8_t *buf, int buf_size)
|
||||||
{
|
{
|
||||||
struct decctx *ctx = opaque;
|
struct decctx *ctx = opaque;
|
||||||
int ammount;
|
int ammount;
|
||||||
ammount = FS_Read(ctx->file, buf, buf_size);
|
ammount = pFS_Read(ctx->file, buf, buf_size);
|
||||||
if (ammount > 0)
|
if (ammount > 0)
|
||||||
ctx->fileofs += ammount;
|
ctx->fileofs += ammount;
|
||||||
return ammount;
|
return ammount;
|
||||||
|
@ -95,7 +107,7 @@ static int64_t AVIO_Seek(void *opaque, int64_t offset, int whence)
|
||||||
case AVSEEK_SIZE:
|
case AVSEEK_SIZE:
|
||||||
return ctx->filelen;
|
return ctx->filelen;
|
||||||
}
|
}
|
||||||
FS_Seek(ctx->file, ctx->fileofs & 0xffffffff, ctx->fileofs>>32);
|
pFS_Seek(ctx->file, ctx->fileofs & 0xffffffff, ctx->fileofs>>32);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,10 +125,10 @@ static void AVDec_Destroy(void *vctx)
|
||||||
avcodec_close(ctx->pACodecCtx);
|
avcodec_close(ctx->pACodecCtx);
|
||||||
|
|
||||||
// Close the video file
|
// Close the video file
|
||||||
av_close_input_file(ctx->pFormatCtx);
|
avformat_close_input(&ctx->pFormatCtx);
|
||||||
|
|
||||||
if (ctx->file >= 0)
|
if (ctx->file >= 0)
|
||||||
FS_Close(ctx->file);
|
pFS_Close(ctx->file);
|
||||||
|
|
||||||
free(ctx);
|
free(ctx);
|
||||||
}
|
}
|
||||||
|
@ -148,17 +160,17 @@ static void *AVDec_Create(char *medianame)
|
||||||
|
|
||||||
//so we always decode the first frame instantly.
|
//so we always decode the first frame instantly.
|
||||||
|
|
||||||
ctx->starttime = timeGetTime();
|
ctx->starttime = pSys_Milliseconds();
|
||||||
|
|
||||||
ctx->file = -1;
|
ctx->file = -1;
|
||||||
if (useioctx)
|
if (useioctx)
|
||||||
{
|
{
|
||||||
// Create internal Buffer for FFmpeg:
|
// Create internal Buffer for FFmpeg:
|
||||||
const int iBufSize = 32 * 1024;
|
const int iBufSize = 32 * 1024;
|
||||||
BYTE *pBuffer = malloc(iBufSize);
|
char *pBuffer = malloc(iBufSize);
|
||||||
AVIOContext *ioctx;
|
AVIOContext *ioctx;
|
||||||
|
|
||||||
ctx->filelen = FS_Open(medianame, &ctx->file, 1);
|
ctx->filelen = pFS_Open(medianame, &ctx->file, 1);
|
||||||
if (ctx->filelen < 0)
|
if (ctx->filelen < 0)
|
||||||
{
|
{
|
||||||
Con_Printf("Unable to open %s\n", medianame);
|
Con_Printf("Unable to open %s\n", medianame);
|
||||||
|
@ -177,7 +189,7 @@ static void *AVDec_Create(char *medianame)
|
||||||
if(avformat_open_input(&ctx->pFormatCtx, medianame, NULL, NULL)==0)
|
if(avformat_open_input(&ctx->pFormatCtx, medianame, NULL, NULL)==0)
|
||||||
{
|
{
|
||||||
// Retrieve stream information
|
// Retrieve stream information
|
||||||
if(av_find_stream_info(ctx->pFormatCtx)>=0)
|
if(avformat_find_stream_info(ctx->pFormatCtx, NULL)>=0)
|
||||||
{
|
{
|
||||||
ctx->audioStream=-1;
|
ctx->audioStream=-1;
|
||||||
for(i=0; i<ctx->pFormatCtx->nb_streams; i++)
|
for(i=0; i<ctx->pFormatCtx->nb_streams; i++)
|
||||||
|
@ -192,7 +204,7 @@ static void *AVDec_Create(char *medianame)
|
||||||
pCodec=avcodec_find_decoder(ctx->pACodecCtx->codec_id);
|
pCodec=avcodec_find_decoder(ctx->pACodecCtx->codec_id);
|
||||||
|
|
||||||
ctx->pAFrame=avcodec_alloc_frame();
|
ctx->pAFrame=avcodec_alloc_frame();
|
||||||
if(pCodec!=NULL && ctx->pAFrame && avcodec_open(ctx->pACodecCtx, pCodec) >= 0)
|
if(pCodec!=NULL && ctx->pAFrame && avcodec_open2(ctx->pACodecCtx, pCodec, NULL) >= 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -218,7 +230,7 @@ static void *AVDec_Create(char *medianame)
|
||||||
pCodec=avcodec_find_decoder(ctx->pVCodecCtx->codec_id);
|
pCodec=avcodec_find_decoder(ctx->pVCodecCtx->codec_id);
|
||||||
|
|
||||||
// Open codec
|
// Open codec
|
||||||
if(pCodec!=NULL && avcodec_open(ctx->pVCodecCtx, pCodec) >= 0)
|
if(pCodec!=NULL && avcodec_open2(ctx->pVCodecCtx, pCodec, NULL) >= 0)
|
||||||
{
|
{
|
||||||
// Allocate video frame
|
// Allocate video frame
|
||||||
ctx->pVFrame=avcodec_alloc_frame();
|
ctx->pVFrame=avcodec_alloc_frame();
|
||||||
|
@ -237,7 +249,7 @@ static void *AVDec_Create(char *medianame)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *AVDec_DisplayFrame(void *vctx, qboolean nosound, enum uploadfmt_e *fmt, int *width, int *height)
|
static void *AVDec_DisplayFrame(void *vctx, qboolean nosound, uploadfmt_t *fmt, int *width, int *height)
|
||||||
{
|
{
|
||||||
struct decctx *ctx = (struct decctx*)vctx;
|
struct decctx *ctx = (struct decctx*)vctx;
|
||||||
AVPacket packet;
|
AVPacket packet;
|
||||||
|
@ -245,7 +257,7 @@ static void *AVDec_DisplayFrame(void *vctx, qboolean nosound, enum uploadfmt_e *
|
||||||
qboolean repainted = false;
|
qboolean repainted = false;
|
||||||
int64_t curtime, lasttime;
|
int64_t curtime, lasttime;
|
||||||
|
|
||||||
curtime = ((timeGetTime() - ctx->starttime) * ctx->denum);
|
curtime = ((pSys_Milliseconds() - ctx->starttime) * ctx->denum);
|
||||||
curtime /= (ctx->num * 1000);
|
curtime /= (ctx->num * 1000);
|
||||||
|
|
||||||
*fmt = TF_BGRA32;
|
*fmt = TF_BGRA32;
|
||||||
|
@ -275,7 +287,7 @@ static void *AVDec_DisplayFrame(void *vctx, qboolean nosound, enum uploadfmt_e *
|
||||||
ctx->pScaleCtx = sws_getCachedContext(ctx->pScaleCtx, ctx->pVCodecCtx->width, ctx->pVCodecCtx->height, ctx->pVCodecCtx->pix_fmt, ctx->width, ctx->height, AV_PIX_FMT_BGRA, SWS_POINT, 0, 0, 0);
|
ctx->pScaleCtx = sws_getCachedContext(ctx->pScaleCtx, ctx->pVCodecCtx->width, ctx->pVCodecCtx->height, ctx->pVCodecCtx->pix_fmt, ctx->width, ctx->height, AV_PIX_FMT_BGRA, SWS_POINT, 0, 0, 0);
|
||||||
|
|
||||||
// Convert the image from its native format to RGB
|
// Convert the image from its native format to RGB
|
||||||
sws_scale(ctx->pScaleCtx, ctx->pVFrame->data, ctx->pVFrame->linesize, 0, ctx->pVCodecCtx->height, ctx->pFrameRGB.data, ctx->pFrameRGB.linesize);
|
sws_scale(ctx->pScaleCtx, (void*)ctx->pVFrame->data, ctx->pVFrame->linesize, 0, ctx->pVCodecCtx->height, ctx->pFrameRGB.data, ctx->pFrameRGB.linesize);
|
||||||
|
|
||||||
repainted = true;
|
repainted = true;
|
||||||
}
|
}
|
||||||
|
@ -323,7 +335,7 @@ static void *AVDec_DisplayFrame(void *vctx, qboolean nosound, enum uploadfmt_e *
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
S_RawAudio(-1, auddata, ctx->pACodecCtx->sample_rate, auddatasize/(ctx->pACodecCtx->channels*width), ctx->pACodecCtx->channels, width);
|
pS_RawAudio(-1, auddata, ctx->pACodecCtx->sample_rate, auddatasize/(ctx->pACodecCtx->channels*width), ctx->pACodecCtx->channels, width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
packet.data = odata;
|
packet.data = odata;
|
||||||
|
@ -365,7 +377,7 @@ static void AVDec_Rewind(void *vctx)
|
||||||
if (ctx->audioStream >= 0)
|
if (ctx->audioStream >= 0)
|
||||||
av_seek_frame(ctx->pFormatCtx, ctx->audioStream, 0, AVSEEK_FLAG_BACKWARD);
|
av_seek_frame(ctx->pFormatCtx, ctx->audioStream, 0, AVSEEK_FLAG_BACKWARD);
|
||||||
|
|
||||||
ctx->starttime = timeGetTime();
|
ctx->starttime = pSys_Milliseconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -393,7 +405,7 @@ static media_decoder_funcs_t decoderfuncs =
|
||||||
|
|
||||||
static qboolean AVDec_Init(void)
|
static qboolean AVDec_Init(void)
|
||||||
{
|
{
|
||||||
if (!Plug_ExportNative("Media_VideoDecoder", &decoderfuncs))
|
if (!pPlug_ExportNative("Media_VideoDecoder", &decoderfuncs))
|
||||||
{
|
{
|
||||||
Con_Printf("avplug: Engine doesn't support media decoder plugins\n");
|
Con_Printf("avplug: Engine doesn't support media decoder plugins\n");
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#include "../plugin.h"
|
#include "../plugin.h"
|
||||||
#include "../engine.h"
|
#include "../engine.h"
|
||||||
|
|
||||||
#include "avformat.h"
|
#include <libavformat/avformat.h>
|
||||||
#include "avio.h"
|
#include <libavformat/avio.h>
|
||||||
#include "avcodec.h"
|
#include <libavcodec/avcodec.h>
|
||||||
#include "swscale.h"
|
#include <libswscale/swscale.h>
|
||||||
|
//#include <libavutil/channel_layout.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Most of the logic in here came from here:
|
Most of the logic in here came from here:
|
||||||
|
@ -54,9 +55,9 @@ AVStream *add_video_stream(struct encctx *ctx, AVCodec *codec, int fps, int widt
|
||||||
AVCodecContext *c;
|
AVCodecContext *c;
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
char prof[128];
|
char prof[128];
|
||||||
int bitrate = (int)Cvar_GetFloat("avplug_videobitrate");
|
int bitrate = (int)pCvar_GetFloat("avplug_videobitrate");
|
||||||
int forcewidth = (int)Cvar_GetFloat("avplug_videoforcewidth");
|
int forcewidth = (int)pCvar_GetFloat("avplug_videoforcewidth");
|
||||||
int forceheight = (int)Cvar_GetFloat("avplug_videoforceheight");
|
int forceheight = (int)pCvar_GetFloat("avplug_videoforceheight");
|
||||||
|
|
||||||
st = avformat_new_stream(ctx->fc, codec);
|
st = avformat_new_stream(ctx->fc, codec);
|
||||||
if (!st)
|
if (!st)
|
||||||
|
@ -96,7 +97,7 @@ AVStream *add_video_stream(struct encctx *ctx, AVCodec *codec, int fps, int widt
|
||||||
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
|
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
|
||||||
|
|
||||||
*prof = 0;
|
*prof = 0;
|
||||||
Cvar_GetString("avplug_format", prof, sizeof(prof));
|
pCvar_GetString("avplug_format", prof, sizeof(prof));
|
||||||
// av_opt_set(c->priv_data, "profile", prof, AV_OPT_SEARCH_CHILDREN);
|
// av_opt_set(c->priv_data, "profile", prof, AV_OPT_SEARCH_CHILDREN);
|
||||||
|
|
||||||
return st;
|
return st;
|
||||||
|
@ -118,7 +119,7 @@ static void AVEnc_Video (void *vctx, void *data, int frame, int width, int heigh
|
||||||
{
|
{
|
||||||
struct encctx *ctx = vctx;
|
struct encctx *ctx = vctx;
|
||||||
//weird maths to flip it.
|
//weird maths to flip it.
|
||||||
uint8_t *srcslices[2] = {(uint8_t*)data + (height-1)*width*3, NULL};
|
const uint8_t *srcslices[2] = {(uint8_t*)data + (height-1)*width*3, NULL};
|
||||||
int srcstride[2] = {-width*3, 0};
|
int srcstride[2] = {-width*3, 0};
|
||||||
int success;
|
int success;
|
||||||
AVPacket pkt;
|
AVPacket pkt;
|
||||||
|
@ -152,7 +153,7 @@ AVStream *add_audio_stream(struct encctx *ctx, AVCodec *codec, int samplerate, i
|
||||||
{
|
{
|
||||||
AVCodecContext *c;
|
AVCodecContext *c;
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
int bitrate = (int)Cvar_GetFloat("avplug_audiobitrate");
|
int bitrate = (int)pCvar_GetFloat("avplug_audiobitrate");
|
||||||
|
|
||||||
st = avformat_new_stream(ctx->fc, codec);
|
st = avformat_new_stream(ctx->fc, codec);
|
||||||
if (!st)
|
if (!st)
|
||||||
|
@ -231,7 +232,7 @@ static void *AVEnc_Begin (char *streamname, int videorate, int width, int height
|
||||||
AVCodec *audiocodec = NULL;
|
AVCodec *audiocodec = NULL;
|
||||||
char formatname[64];
|
char formatname[64];
|
||||||
formatname[0] = 0;
|
formatname[0] = 0;
|
||||||
Cvar_GetString("avplug_format", formatname, sizeof(formatname));
|
pCvar_GetString("avplug_format", formatname, sizeof(formatname));
|
||||||
|
|
||||||
if (*formatname)
|
if (*formatname)
|
||||||
{
|
{
|
||||||
|
@ -259,7 +260,7 @@ static void *AVEnc_Begin (char *streamname, int videorate, int width, int height
|
||||||
{
|
{
|
||||||
char codecname[64];
|
char codecname[64];
|
||||||
codecname[0] = 0;
|
codecname[0] = 0;
|
||||||
Cvar_GetString("avplug_videocodec", codecname, sizeof(codecname));
|
pCvar_GetString("avplug_videocodec", codecname, sizeof(codecname));
|
||||||
|
|
||||||
if (strcmp(codecname, "none"))
|
if (strcmp(codecname, "none"))
|
||||||
{
|
{
|
||||||
|
@ -280,7 +281,7 @@ static void *AVEnc_Begin (char *streamname, int videorate, int width, int height
|
||||||
{
|
{
|
||||||
char codecname[64];
|
char codecname[64];
|
||||||
codecname[0] = 0;
|
codecname[0] = 0;
|
||||||
Cvar_GetString("avplug_audiocodec", codecname, sizeof(codecname));
|
pCvar_GetString("avplug_audiocodec", codecname, sizeof(codecname));
|
||||||
|
|
||||||
if (strcmp(codecname, "none"))
|
if (strcmp(codecname, "none"))
|
||||||
{
|
{
|
||||||
|
@ -411,21 +412,19 @@ static media_encoder_funcs_t encoderfuncs =
|
||||||
AVEnc_End
|
AVEnc_End
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
qboolean AVEnc_Init(void)
|
qboolean AVEnc_Init(void)
|
||||||
{
|
{
|
||||||
Cvar_Register("avplug_format", "", 0, "avplug");
|
pCvar_Register("avplug_format", "", 0, "avplug");
|
||||||
|
|
||||||
Cvar_Register("avplug_videocodec", "", 0, "avplug");
|
pCvar_Register("avplug_videocodec", "", 0, "avplug");
|
||||||
Cvar_Register("avplug_videocodecprofile", "", 0, "avplug");
|
pCvar_Register("avplug_videocodecprofile", "", 0, "avplug");
|
||||||
Cvar_Register("avplug_videobitrate", "4000000", 0, "avplug");
|
pCvar_Register("avplug_videobitrate", "4000000", 0, "avplug");
|
||||||
Cvar_Register("avplug_videoforcewidth", "", 0, "avplug");
|
pCvar_Register("avplug_videoforcewidth", "", 0, "avplug");
|
||||||
Cvar_Register("avplug_videoforceheight", "", 0, "avplug");
|
pCvar_Register("avplug_videoforceheight", "", 0, "avplug");
|
||||||
Cvar_Register("avplug_audiocodec", "", 0, "avplug");
|
pCvar_Register("avplug_audiocodec", "", 0, "avplug");
|
||||||
Cvar_Register("avplug_audiobitrate", "64000", 0, "avplug");
|
pCvar_Register("avplug_audiobitrate", "64000", 0, "avplug");
|
||||||
|
|
||||||
if (!Plug_ExportNative("Media_VideoEncoder", &encoderfuncs))
|
if (!pPlug_ExportNative("Media_VideoEncoder", &encoderfuncs))
|
||||||
{
|
{
|
||||||
Con_Printf("avplug: Engine doesn't support media encoder plugins\n");
|
Con_Printf("avplug: Engine doesn't support media encoder plugins\n");
|
||||||
return false;
|
return false;
|
||||||
|
@ -433,3 +432,4 @@ qboolean AVEnc_Init(void)
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifndef FTEPLUGIN
|
||||||
typedef enum uploadfmt_e
|
typedef enum uploadfmt_e
|
||||||
{
|
{
|
||||||
TF_INVALID,
|
TF_INVALID,
|
||||||
|
@ -10,7 +11,7 @@ typedef enum uploadfmt_e
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
void *(QDECL *createdecoder)(char *name); //needed
|
void *(QDECL *createdecoder)(char *name); //needed
|
||||||
void *(QDECL *decodeframe)(void *ctx, qboolean nosound, enum uploadfmt_e *fmt, int *width, int *height); //needed
|
void *(QDECL *decodeframe)(void *ctx, qboolean nosound, uploadfmt_t *fmt, int *width, int *height); //needed
|
||||||
void (QDECL *doneframe)(void *ctx, void *img); //basically a free()
|
void (QDECL *doneframe)(void *ctx, void *img); //basically a free()
|
||||||
void (QDECL *shutdown)(void *ctx); //probably needed...
|
void (QDECL *shutdown)(void *ctx); //probably needed...
|
||||||
void (QDECL *rewind)(void *ctx);
|
void (QDECL *rewind)(void *ctx);
|
||||||
|
@ -30,3 +31,5 @@ typedef struct
|
||||||
void (QDECL *capture_audio) (void *ctx, void *data, int bytes);
|
void (QDECL *capture_audio) (void *ctx, void *data, int bytes);
|
||||||
void (QDECL *capture_end) (void *ctx);
|
void (QDECL *capture_end) (void *ctx);
|
||||||
} media_encoder_funcs_t;
|
} media_encoder_funcs_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,10 @@ void strlcpy(char *d, const char *s, int n);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef FTEPLUGIN
|
#ifdef FTEPLUGIN
|
||||||
|
#define qfalse false
|
||||||
|
#define qtrue true
|
||||||
|
#else
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
typedef enum {qfalse, qtrue} qboolean;
|
typedef enum {qfalse, qtrue} qboolean;
|
||||||
#else
|
#else
|
||||||
|
@ -140,7 +143,7 @@ typedef enum {qfalse, qtrue} qboolean;
|
||||||
typedef float vec3_t[3];
|
typedef float vec3_t[3];
|
||||||
typedef unsigned char qbyte;
|
typedef unsigned char qbyte;
|
||||||
#endif
|
#endif
|
||||||
typedef void *qhandle_t;
|
typedef int qhandle_t;
|
||||||
typedef void* funcptr_t;
|
typedef void* funcptr_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue