4 #include "dpvsimpledecode.h"
6 mempool_t *clvideomempool;
8 int cl_videoplaying = false;
11 double cl_videostarttime;
13 double cl_videoframerate;
15 int cl_videoimagewidth;
16 int cl_videoimageheight;
17 int cl_videoimagedata_rmask;
18 int cl_videoimagedata_gmask;
19 int cl_videoimagedata_bmask;
20 int cl_videoimagedata_bytesperpixel;
21 void *cl_videoimagedata;
23 int cl_videosoundrate;
24 int cl_videosoundlength;
25 short *cl_videosounddata;
26 int cl_videosoundresamplelength;
27 short *cl_videosoundresampledata;
29 rtexture_t *cl_videotexture;
30 rtexturepool_t *cl_videotexturepool;
32 void CL_VideoFrame(void)
34 int frames, framenum, samples, s;
37 framenum = (realtime - cl_videostarttime) * cl_videoframerate;
38 //Con_Printf("frame %i\n", framenum);
42 while (cl_videoframenum < framenum)
46 if (dpvsimpledecode_video(cl_videostream, cl_videoimagedata, cl_videoimagedata_rmask, cl_videoimagedata_gmask, cl_videoimagedata_bmask, cl_videoimagedata_bytesperpixel, cl_videoimagewidth * cl_videoimagedata_bytesperpixel))
54 R_UpdateTexture(cl_videotexture, cl_videoimagedata);
55 //Draw_NewPic("engine_videoframe", cl_videoimagewidth, cl_videoimageheight, false, cl_videoimagedata);
57 if (cl_videosoundrate && (samples = S_RawSamples_QueueWantsMore()))
59 Con_Printf("%i = S_RawSamples_QueueWantsMore()\n", samples);
61 // calculate how much source data we need to fill the output...
62 s = samples * cl_videosoundrate / S_RawSamples_SampleRate();
64 // reallocate processing buffer if needed
65 if (cl_videosoundresamplelength < samples)
67 cl_videosoundresamplelength = samples + 100;
68 if (cl_videosoundresampledata)
69 Mem_Free(cl_videosoundresampledata);
70 cl_videosoundresampledata = Mem_Alloc(clvideomempool, cl_videosoundresamplelength * sizeof(short[2]));
73 // reallocate loading buffer if needed
74 if (cl_videosoundlength < s)
76 cl_videosoundlength = s + 100;
77 if (cl_videosounddata)
78 Mem_Free(cl_videosounddata);
79 cl_videosounddata = Mem_Alloc(clvideomempool, cl_videosoundlength * sizeof(short[2]));
82 dpvsimpledecode_audio(cl_videostream, cl_videosounddata, s);
83 S_ResampleBuffer16Stereo(cl_videosounddata, s, cl_videosoundresampledata, samples);
84 S_RawSamples_Enqueue(cl_videosoundresampledata, samples);
88 void CL_DrawVideo(void)
97 float s1, t1, s2, t2, x1, y1, x2, y2;
108 R_FragmentLocation(cl_videotexture, NULL, NULL, &s1, &t1, &s2, &t2);
109 texcoords[0] = s1;texcoords[1] = t1;
110 texcoords[2] = s2;texcoords[3] = t1;
111 texcoords[4] = s2;texcoords[5] = t2;
112 texcoords[6] = s1;texcoords[7] = t2;
113 R_FillColors(colorsf, 4, r_colorscale, r_colorscale, r_colorscale, 1);
114 vertices[ 0] = x1;vertices[ 1] = y1;vertices[ 2] = 0;vertices[ 3] = 0;
115 vertices[ 4] = x2;vertices[ 5] = y1;vertices[ 6] = 0;vertices[ 7] = 0;
116 vertices[ 8] = x2;vertices[ 9] = y2;vertices[10] = 0;vertices[11] = 0;
117 vertices[12] = x1;vertices[13] = y2;vertices[14] = 0;vertices[15] = 0;
118 mesh.texture = cl_videotexture;
120 mesh.numvertices = 4;
121 mesh.indices = indices;
122 mesh.vertices = vertices;
123 mesh.texcoords = texcoords;
124 mesh.colors = colorsf;
125 DrawQ_Mesh(&mesh, 0);
126 //DrawQ_Pic(0, 0, "engine_videoframe", vid.conwidth, vid.conheight, 1, 1, 1, 1, 0);
130 void CL_VideoStart(char *filename)
133 cl_videostream = dpvsimpledecode_open(filename, &errorstring);
136 Con_Printf("unable to open \"%s\", error: %s\n", filename, errorstring);
140 cl_videoplaying = true;
141 cl_videostarttime = realtime;
142 cl_videoframenum = -1;
143 cl_videoframerate = dpvsimpledecode_getframerate(cl_videostream);
144 cl_videoimagewidth = dpvsimpledecode_getwidth(cl_videostream);
145 cl_videoimageheight = dpvsimpledecode_getheight(cl_videostream);
148 cl_videoimagedata_bytesperpixel = 4;
149 cl_videoimagedata_rmask = BigLong(0xFF000000);
150 cl_videoimagedata_gmask = BigLong(0x00FF0000);
151 cl_videoimagedata_bmask = BigLong(0x0000FF00);
152 cl_videoimagedata = Mem_Alloc(clvideomempool, cl_videoimagewidth * cl_videoimageheight * cl_videoimagedata_bytesperpixel);
153 //memset(cl_videoimagedata, 97, cl_videoimagewidth * cl_videoimageheight * cl_videoimagedata_bytesperpixel);
155 cl_videosoundrate = dpvsimpledecode_getsoundrate(cl_videostream);
156 cl_videosoundlength = 0;
157 cl_videosounddata = NULL;
158 cl_videosoundresamplelength = 0;
159 cl_videosoundresampledata = NULL;
161 cl_videotexturepool = R_AllocTexturePool();
162 cl_videotexture = R_LoadTexture(cl_videotexturepool, "videotexture", cl_videoimagewidth, cl_videoimageheight, NULL, TEXTYPE_RGBA, TEXF_FRAGMENT);
165 void CL_VideoStop(void)
167 cl_videoplaying = false;
169 S_RawSamples_ClearQueue();
172 dpvsimpledecode_close(cl_videostream);
173 cl_videostream = NULL;
175 if (cl_videoimagedata)
176 Mem_Free(cl_videoimagedata);
177 cl_videoimagedata = NULL;
179 if (cl_videosounddata)
180 Mem_Free(cl_videosounddata);
181 cl_videosounddata = NULL;
183 if (cl_videosoundresampledata)
184 Mem_Free(cl_videosoundresampledata);
185 cl_videosoundresampledata = NULL;
187 cl_videotexture = NULL;
188 R_FreeTexturePool(&cl_videotexturepool);
190 Draw_FreePic("engine_videoframe");
193 static void CL_PlayVideo_f(void)
199 Con_Printf ("usage: playvideo <videoname>\nplays video named video/<videoname>.dpv\n");
203 sprintf(name, "%s/video/%s.dpv", com_gamedir, Cmd_Argv(1));
207 static void CL_StopVideo_f(void)
212 void CL_Video_Init(void)
214 Cmd_AddCommand("playvideo", CL_PlayVideo_f);
215 Cmd_AddCommand("stopvideo", CL_StopVideo_f);
217 clvideomempool = Mem_AllocPool("CL_Video");