+static void VideoFrame( clvideo_t *video )
+{
+ int destframe;
+
+ if( video->state == CLVIDEO_FIRSTFRAME )
+ destframe = 0;
+ else
+ destframe = (realtime - video->starttime) * video->framerate;
+ if( destframe < 0 )
+ destframe = 0;
+ if( video->framenum < destframe ) {
+ do {
+ video->framenum++;
+ if( dpvsimpledecode_video( video->stream, video->imagedata, cl_videormask,
+ cl_videogmask, cl_videobmask, cl_videobytesperpixel,
+ cl_videobytesperpixel * video->cpif.width )
+ ) { // finished?
+ video->framenum = -1;
+ if( video->state == CLVIDEO_LOOP )
+ video->starttime = realtime;
+ else if( video->state == CLVIDEO_PLAY )
+ video->state = CLVIDEO_FIRSTFRAME;
+ return;
+ }
+ } while( video->framenum < destframe );
+ R_UpdateTexture( video->cpif.tex, video->imagedata );
+ }
+}
+
+void CL_VideoFrame( void ) // update all videos
+{
+ int i;
+ clvideo_t *video;
+
+ for( video = videoarray, i = 0 ; i < MAXCLVIDEOS ; video++, i++ )
+ if( video->state != CLVIDEO_UNUSED && !video->suspended )
+ if( realtime - video->lasttime > CLTHRESHOLD )
+ SuspendVideo( video );
+ else if( video->state == CLVIDEO_PAUSE )
+ video->starttime = realtime + video->framenum * video->framerate;
+ else
+ VideoFrame( video );
+
+ if( videoarray->state == CLVIDEO_FIRSTFRAME )
+ CL_VideoStop();
+}
+
+void CL_Video_Shutdown( void )
+{
+ int i;
+ for( i = 0 ; i < MAXCLVIDEOS ; i++ )
+ CL_CloseVideo( &videoarray[ i ] );
+
+ R_FreeTexturePool( &cl_videotexturepool );
+ Mem_FreePool( &cl_videomempool );
+}
+
+void CL_PurgeOwner( int owner )
+{
+ int i;
+ for( i = 0 ; i < MAXCLVIDEOS ; i++ )
+ if( videoarray[ i ].ownertag == owner )
+ CL_CloseVideo( &videoarray[ i ] );
+}
+
+int cl_videoplaying = false; // old, but still supported
+