X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=cl_video.c;h=9e5ca0d65016d2121250e022f079c39928fd32f7;hp=aca8249e26494b7450c91f165bd9172966bb23f2;hb=1ff3bc8e953680793a28ea923f2d1e58cdf2c9f0;hpb=2dbe17fce49258350f4a501edc8923470f224cb5 diff --git a/cl_video.c b/cl_video.c index aca8249e..9e5ca0d6 100644 --- a/cl_video.c +++ b/cl_video.c @@ -1,14 +1,6 @@ #include "quakedef.h" -#include "cl_dyntexture.h" #include "cl_video.h" -#include "dpvsimpledecode.h" - -// VorteX: JAM video module used by Blood Omnicide -//#define USEJAM -#ifdef USEJAM - #include "jamdecode.c" -#endif // cvars cvar_t cl_video_subtitles = {CVAR_SAVE, "cl_video_subtitles", "0", "show subtitles for videos (if they are present)"}; @@ -22,6 +14,19 @@ cvar_t cl_video_keepaspectratio = {CVAR_SAVE, "cl_video_keepaspectratio", "0", " cvar_t cl_video_fadein = {CVAR_SAVE, "cl_video_fadein", "0", "fading-from-black effect once video is started, in seconds"}; cvar_t cl_video_fadeout = {CVAR_SAVE, "cl_video_fadeout", "0", "fading-to-black effect once video is ended, in seconds"}; +cvar_t v_glslgamma_video = {CVAR_SAVE, "v_glslgamma_video", "1", "applies GLSL gamma to played video, could be a fraction, requires r_glslgamma_2d 1."}; + +// DPV stream decoder +#include "dpvsimpledecode.h" + +// VorteX: libavcodec implementation +#include "cl_video_libavw.c" + +// JAM video decoder used by Blood Omnicide +#ifdef JAMVIDEO +#include "cl_video_jamdecode.c" +#endif + // constants (and semi-constants) static int cl_videormask; static int cl_videobmask; @@ -44,39 +49,42 @@ static clvideo_t *FindUnusedVid( void ) static qboolean OpenStream( clvideo_t * video ) { const char *errorstring; + video->stream = dpvsimpledecode_open( video, video->filename, &errorstring); - if (!video->stream ) - { -#ifdef USEJAM - video->stream = jam_open( video, video->filename, &errorstring); - if (video->stream) - return true; + if (video->stream) + return true; + +#ifdef JAMVIDEO + video->stream = jam_open( video, video->filename, &errorstring); + if (video->stream) + return true; #endif - Con_Printf("unable to open \"%s\", error: %s\n", video->filename, errorstring); - return false; - } - return true; + + video->stream = LibAvW_OpenVideo( video, video->filename, &errorstring); + if (video->stream) + return true; + + Con_Printf("unable to open \"%s\", error: %s\n", video->filename, errorstring); + return false; } static void VideoUpdateCallback(rtexture_t *rt, void *data) { clvideo_t *video = (clvideo_t *) data; - R_UpdateTexture( video->cpif.tex, (unsigned char *)video->imagedata, 0, 0, video->cpif.width, video->cpif.height ); + Draw_NewPic(video->name, video->width, video->height, (unsigned char *)video->imagedata, TEXTYPE_BGRA, TEXF_CLAMP); } static void LinkVideoTexture( clvideo_t *video ) { - video->cpif.tex = R_LoadTexture2D( cl_videotexturepool, video->cpif.name, video->cpif.width, video->cpif.height, NULL, TEXTYPE_BGRA, TEXF_PERSISTENT | TEXF_CLAMP, -1, NULL ); - R_MakeTextureDynamic( video->cpif.tex, VideoUpdateCallback, video ); - CL_LinkDynTexture( video->cpif.name, video->cpif.tex ); + video->cachepic = Draw_NewPic(video->name, video->width, video->height, NULL, TEXTYPE_BGRA, TEXF_CLAMP); + // make R_GetTexture() call our VideoUpdateCallback + R_MakeTextureDynamic(Draw_GetPicTexture(video->cachepic), VideoUpdateCallback, video); } static void UnlinkVideoTexture( clvideo_t *video ) { - CL_UnlinkDynTexture( video->cpif.name ); - // free the texture - R_FreeTexture( video->cpif.tex ); - video->cpif.tex = NULL; + // free the texture (this does not destroy the cachepic_t, which is eternal) + Draw_FreePic(video->name); // free the image data Mem_Free( video->imagedata ); } @@ -89,7 +97,11 @@ static void SuspendVideo( clvideo_t * video ) UnlinkVideoTexture(video); // if we are in firstframe mode, also close the stream if (video->state == CLVIDEO_FIRSTFRAME) - video->close(video->stream); + { + if (video->stream) + video->close(video->stream); + video->stream = NULL; + } } static qboolean WakeVideo( clvideo_t * video ) @@ -104,7 +116,7 @@ static qboolean WakeVideo( clvideo_t * video ) return false; } - video->imagedata = Mem_Alloc( cls.permanentmempool, video->cpif.width * video->cpif.height * cl_videobytesperpixel ); + video->imagedata = Mem_Alloc( cls.permanentmempool, video->width * video->height * cl_videobytesperpixel ); LinkVideoTexture( video ); // update starttime @@ -129,7 +141,7 @@ static void LoadSubtitles( clvideo_t *video, const char *subtitlesfile ) subtitle_text = NULL; if (langcvar) { - dpsnprintf(overridename, sizeof(overridename), "script/locale/%s/%s", langcvar->string, subtitlesfile); + dpsnprintf(overridename, sizeof(overridename), "locale/%s/%s", langcvar->string, subtitlesfile); subtitle_text = (char *)FS_LoadFile(overridename, cls.permanentmempool, false, NULL); } if (!subtitle_text) @@ -202,11 +214,12 @@ static void LoadSubtitles( clvideo_t *video, const char *subtitlesfile ) static clvideo_t* OpenVideo( clvideo_t *video, const char *filename, const char *name, int owner, const char *subtitlesfile ) { - strlcpy( video->filename, filename, sizeof(video->filename) ); + strlcpy(video->filename, filename, sizeof(video->filename)); + dpsnprintf(video->name, sizeof(video->name), CLVIDEOPREFIX "%s", name); video->ownertag = owner; if( strncmp( name, CLVIDEOPREFIX, sizeof( CLVIDEOPREFIX ) - 1 ) ) return NULL; - strlcpy( video->cpif.name, name, sizeof(video->cpif.name) ); + video->cachepic = Draw_CachePic_Flags(name, CACHEPICFLAG_NOTPERSISTENT | CACHEPICFLAG_QUIET); if( !OpenStream( video ) ) return NULL; @@ -217,9 +230,9 @@ static clvideo_t* OpenVideo( clvideo_t *video, const char *filename, const char video->lasttime = realtime; video->subtitles = 0; - video->cpif.width = video->getwidth( video->stream ); - video->cpif.height = video->getheight( video->stream ); - video->imagedata = Mem_Alloc( cls.permanentmempool, video->cpif.width * video->cpif.height * cl_videobytesperpixel ); + video->width = video->getwidth( video->stream ); + video->height = video->getheight( video->stream ); + video->imagedata = Mem_Alloc( cls.permanentmempool, video->width * video->height * cl_videobytesperpixel ); LinkVideoTexture( video ); // VorteX: load simple subtitle_text file @@ -274,7 +287,7 @@ clvideo_t *CL_GetVideoByName( const char *name ) for( i = 0 ; i < cl_num_videos ; i++ ) if( cl_videos[ i ].state != CLVIDEO_UNUSED - && !strcmp( cl_videos[ i ].cpif.name , name ) ) + && !strcmp( cl_videos[ i ].name , name ) ) break; if( i != cl_num_videos ) return CL_GetVideoBySlot( i ); @@ -303,7 +316,9 @@ void CL_RestartVideo(clvideo_t *video) video->framenum = -1; // reopen stream - video->close(video->stream); + if (video->stream) + video->close(video->stream); + video->stream = NULL; if (!OpenStream(video)) video->state = CLVIDEO_UNUSED; } @@ -318,7 +333,11 @@ void CL_CloseVideo(clvideo_t * video) // close stream if (!video->suspended || video->state != CLVIDEO_FIRSTFRAME) - video->close(video->stream); + { + if (video->stream) + video->close(video->stream); + video->stream = NULL; + } // unlink texture if (!video->suspended) UnlinkVideoTexture(video); @@ -366,7 +385,7 @@ void CL_Video_Frame(void) { do { video->framenum++; - if (video->decodeframe(video->stream, video->imagedata, cl_videormask, cl_videogmask, cl_videobmask, cl_videobytesperpixel, cl_videobytesperpixel * video->cpif.width)) + if (video->decodeframe(video->stream, video->imagedata, cl_videormask, cl_videogmask, cl_videobmask, cl_videobytesperpixel, cl_videobytesperpixel * video->width)) { // finished? CL_RestartVideo(video); @@ -375,7 +394,7 @@ void CL_Video_Frame(void) return; } } while(video->framenum < destframe); - R_MarkDirtyTexture(video->cpif.tex); + R_MarkDirtyTexture(Draw_GetPicTexture(video->cachepic)); } } } @@ -389,13 +408,6 @@ void CL_Video_Frame(void) cl_num_videos--; } -void CL_Video_Shutdown( void ) -{ - int i; - for (i = 0 ; i < cl_num_videos ; i++) - CL_CloseVideo(&cl_videos[ i ]); -} - void CL_PurgeOwner( int owner ) { int i; @@ -418,7 +430,7 @@ typedef struct } cl_video_subtitle_info_t; -float CL_DrawVideo_WordWidthFunc(void *passthrough, const char *w, size_t *length, float maxWidth) +static float CL_DrawVideo_WordWidthFunc(void *passthrough, const char *w, size_t *length, float maxWidth) { cl_video_subtitle_info_t *si = (cl_video_subtitle_info_t *) passthrough; @@ -432,7 +444,7 @@ float CL_DrawVideo_WordWidthFunc(void *passthrough, const char *w, size_t *lengt return 0; } -int CL_DrawVideo_DisplaySubtitleLine(void *passthrough, const char *line, size_t length, float width, qboolean isContinuation) +static int CL_DrawVideo_DisplaySubtitleLine(void *passthrough, const char *line, size_t length, float width, qboolean isContinuation) { cl_video_subtitle_info_t *si = (cl_video_subtitle_info_t *) passthrough; @@ -474,7 +486,7 @@ void CL_DrawVideo(void) st[6] = 1.0; st[7] = 1.0; if (cl_video_keepaspectratio.integer) { - float a = ((float)video->cpif.width / (float)video->cpif.height) / ((float)vid.width / (float)vid.height); + float a = video->getaspectratio(video->stream) / ((float)vid.width / (float)vid.height); if (cl_video_keepaspectratio.integer >= 2) { // clip instead of scale @@ -522,29 +534,21 @@ void CL_DrawVideo(void) DrawQ_Fill(0, 0, vid_conwidth.integer, vid_conheight.integer, 0, 0, 0, 1, 0); // enable video-only polygon stipple (of global stipple is not active) - if (qglPolygonStipple && !scr_stipple.integer && cl_video_stipple.integer) + if (!scr_stipple.integer && cl_video_stipple.integer) { - GLubyte stipple[128]; - int i, s, width, parts; - - s = cl_video_stipple.integer; - parts = (s & 007); - width = (s & 070) >> 3; - qglEnable(GL_POLYGON_STIPPLE);CHECKGLERROR // 0x0B42 - for(i = 0; i < 128; ++i) - { - int line = i/4; - stipple[i] = ((line >> width) & ((1 << parts) - 1)) ? 0x00 : 0xFF; - } - qglPolygonStipple(stipple);CHECKGLERROR + Con_Print("FIXME: cl_video_stipple not implemented\n"); + Cvar_SetValueQuick(&cl_video_stipple, 0); } // draw video - DrawQ_SuperPic(px, py, &video->cpif, sx, sy, st[0], st[1], b, b, b, 1, st[2], st[3], b, b, b, 1, st[4], st[5], b, b, b, 1, st[6], st[7], b, b, b, 1, 0); - - // disable video-only stipple - if (qglPolygonStipple && !scr_stipple.integer && cl_video_stipple.integer) - qglDisable(GL_POLYGON_STIPPLE);CHECKGLERROR + if (v_glslgamma_video.value >= 1) + DrawQ_SuperPic(px, py, video->cachepic, sx, sy, st[0], st[1], b, b, b, 1, st[2], st[3], b, b, b, 1, st[4], st[5], b, b, b, 1, st[6], st[7], b, b, b, 1, 0); + else + { + DrawQ_SuperPic(px, py, video->cachepic, sx, sy, st[0], st[1], b, b, b, 1, st[2], st[3], b, b, b, 1, st[4], st[5], b, b, b, 1, st[6], st[7], b, b, b, 1, DRAWFLAG_NOGAMMA); + if (v_glslgamma_video.value > 0.0) + DrawQ_SuperPic(px, py, video->cachepic, sx, sy, st[0], st[1], b, b, b, v_glslgamma_video.value, st[2], st[3], b, b, b, v_glslgamma_video.value, st[4], st[5], b, b, b, v_glslgamma_video.value, st[6], st[7], b, b, b, v_glslgamma_video.value, 0); + } // VorteX: draw subtitle_text if (!video->subtitles || !cl_video_subtitles.integer) @@ -578,7 +582,7 @@ void CL_VideoStart(char *filename, const char *subtitlesfile) if( cl_videos->state != CLVIDEO_UNUSED ) CL_CloseVideo( cl_videos ); // already contains video/ - if( !OpenVideo( cl_videos, filename, va( CLDYNTEXTUREPREFIX "%s", filename ), 0, subtitlesfile ) ) + if( !OpenVideo( cl_videos, filename, filename, 0, subtitlesfile ) ) return; // expand the active range to include the new entry cl_num_videos = max(cl_num_videos, 1); @@ -613,6 +617,9 @@ static void CL_PlayVideo_f(void) Host_StartVideo(); + if (COM_CheckParm("-benchmark")) + return; + if (Cmd_Argc() < 2) { Con_Print("usage: playvideo [custom_subtitles_file]\nplays video named video/.dpv\nif custom subtitles file is not presented\nit tries video/.sub"); @@ -696,5 +703,19 @@ void CL_Video_Init( void ) Cvar_RegisterVariable(&cl_video_fadein); Cvar_RegisterVariable(&cl_video_fadeout); + Cvar_RegisterVariable(&v_glslgamma_video); + R_RegisterModule( "CL_Video", cl_video_start, cl_video_shutdown, cl_video_newmap, NULL, NULL ); -} \ No newline at end of file + + LibAvW_OpenLibrary(); +} + +void CL_Video_Shutdown( void ) +{ + int i; + + for (i = 0 ; i < cl_num_videos ; i++) + CL_CloseVideo(&cl_videos[ i ]); + + LibAvW_CloseLibrary(); +}