DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
dpvsimpledecode.h File Reference
#include "qtypes.h"
#include "qdefs.h"
#include "cvar.h"
#include "cl_video.h"
#include "draw.h"
+ Include dependency graph for dpvsimpledecode.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DPVSIMPLEDECODEERROR_COLORMASKSEXCEEDBPP   8
 
#define DPVSIMPLEDECODEERROR_COLORMASKSOVERLAP   7
 
#define DPVSIMPLEDECODEERROR_EOF   1
 
#define DPVSIMPLEDECODEERROR_INVALIDBMASK   6
 
#define DPVSIMPLEDECODEERROR_INVALIDGMASK   5
 
#define DPVSIMPLEDECODEERROR_INVALIDRMASK   4
 
#define DPVSIMPLEDECODEERROR_NONE   0
 
#define DPVSIMPLEDECODEERROR_READERROR   2
 
#define DPVSIMPLEDECODEERROR_SOUNDBUFFERTOOSMALL   3
 
#define DPVSIMPLEDECODEERROR_UNSUPPORTEDBPP   9
 

Functions

void dpvsimpledecode_close (void *stream)
 
int dpvsimpledecode_error (void *stream, const char **errorstring)
 
double dpvsimpledecode_getaspectratio (void *stream)
 
double dpvsimpledecode_getframerate (void *stream)
 
unsigned int dpvsimpledecode_getheight (void *stream)
 
unsigned int dpvsimpledecode_getwidth (void *stream)
 
voiddpvsimpledecode_open (clvideo_t *video, char *filename, const char **errorstring)
 
int dpvsimpledecode_video (void *stream, void *imagedata, unsigned int Rmask, unsigned int Gmask, unsigned int Bmask, unsigned int bytesperpixel, int imagebytesperrow)
 

Macro Definition Documentation

◆ DPVSIMPLEDECODEERROR_COLORMASKSEXCEEDBPP

#define DPVSIMPLEDECODEERROR_COLORMASKSEXCEEDBPP   8

Definition at line 38 of file dpvsimpledecode.h.

Referenced by dpvsimpledecode_error(), and dpvsimpledecode_setpixelformat().

◆ DPVSIMPLEDECODEERROR_COLORMASKSOVERLAP

#define DPVSIMPLEDECODEERROR_COLORMASKSOVERLAP   7

Definition at line 37 of file dpvsimpledecode.h.

Referenced by dpvsimpledecode_error(), and dpvsimpledecode_setpixelformat().

◆ DPVSIMPLEDECODEERROR_EOF

#define DPVSIMPLEDECODEERROR_EOF   1

Definition at line 31 of file dpvsimpledecode.h.

Referenced by dpvsimpledecode_error(), and dpvsimpledecode_video().

◆ DPVSIMPLEDECODEERROR_INVALIDBMASK

#define DPVSIMPLEDECODEERROR_INVALIDBMASK   6

Definition at line 36 of file dpvsimpledecode.h.

Referenced by dpvsimpledecode_error(), and dpvsimpledecode_setpixelformat().

◆ DPVSIMPLEDECODEERROR_INVALIDGMASK

#define DPVSIMPLEDECODEERROR_INVALIDGMASK   5

Definition at line 35 of file dpvsimpledecode.h.

Referenced by dpvsimpledecode_error(), and dpvsimpledecode_setpixelformat().

◆ DPVSIMPLEDECODEERROR_INVALIDRMASK

#define DPVSIMPLEDECODEERROR_INVALIDRMASK   4

Definition at line 34 of file dpvsimpledecode.h.

Referenced by dpvsimpledecode_error(), and dpvsimpledecode_setpixelformat().

◆ DPVSIMPLEDECODEERROR_NONE

#define DPVSIMPLEDECODEERROR_NONE   0

Definition at line 30 of file dpvsimpledecode.h.

Referenced by dpvsimpledecode_error(), and dpvsimpledecode_video().

◆ DPVSIMPLEDECODEERROR_READERROR

#define DPVSIMPLEDECODEERROR_READERROR   2

Definition at line 32 of file dpvsimpledecode.h.

Referenced by dpvsimpledecode_error(), and dpvsimpledecode_video().

◆ DPVSIMPLEDECODEERROR_SOUNDBUFFERTOOSMALL

#define DPVSIMPLEDECODEERROR_SOUNDBUFFERTOOSMALL   3

Definition at line 33 of file dpvsimpledecode.h.

Referenced by dpvsimpledecode_error().

◆ DPVSIMPLEDECODEERROR_UNSUPPORTEDBPP

#define DPVSIMPLEDECODEERROR_UNSUPPORTEDBPP   9

Definition at line 39 of file dpvsimpledecode.h.

Referenced by dpvsimpledecode_error(), and dpvsimpledecode_setpixelformat().

Function Documentation

◆ dpvsimpledecode_close()

void dpvsimpledecode_close ( void * stream)

Definition at line 447 of file dpvsimpledecode.c.

448{
450 if (s == NULL)
451 return;
452 if (s->videopixels)
454 if (s->sndchan != -1)
455 S_StopChannel (s->sndchan, true, true);
456 if (s->framedatablocks)
458 if (s->bitstream)
460 Z_Free(s);
461}
static void hz_bitstream_read_close(hz_bitstream_read_t *stream)
static void hz_bitstream_read_blocks_free(hz_bitstream_readblocks_t *blocks)
#define NULL
Definition qtypes.h:12
void S_StopChannel(unsigned int channel_ind, qbool lockmutex, qbool freesfx)
Definition snd_main.c:1648
hz_bitstream_read_t * bitstream
hz_bitstream_readblocks_t * framedatablocks
#define Z_Free(data)
Definition zone.h:164

References dpvsimpledecodestream_t::bitstream, dpvsimpledecodestream_t::framedatablocks, hz_bitstream_read_blocks_free(), hz_bitstream_read_close(), NULL, S_StopChannel(), dpvsimpledecodestream_t::sndchan, dpvsimpledecodestream_t::videopixels, and Z_Free.

Referenced by dpvsimpledecode_open().

◆ dpvsimpledecode_error()

int dpvsimpledecode_error ( void * stream,
const char ** errorstring )

Definition at line 469 of file dpvsimpledecode.c.

470{
472 int e;
473 e = s->error;
474 s->error = 0;
475 if (errorstring)
476 {
477 switch (e)
478 {
480 *errorstring = "no error";
481 break;
483 *errorstring = "end of file reached (this is not an error)";
484 break;
486 *errorstring = "read error (corrupt or incomplete file)";
487 break;
489 *errorstring = "sound buffer is too small for decoding frame (please allocate it as large as dpvsimpledecode_getneededsoundbufferlength suggests)";
490 break;
492 *errorstring = "invalid red bits mask";
493 break;
495 *errorstring = "invalid green bits mask";
496 break;
498 *errorstring = "invalid blue bits mask";
499 break;
501 *errorstring = "color bit masks overlap";
502 break;
504 *errorstring = "color masks too big for specified bytes per pixel";
505 break;
507 *errorstring = "unsupported bytes per pixel (must be 2 for 16bit, or 4 for 32bit)";
508 break;
509 default:
510 *errorstring = "unknown error";
511 break;
512 }
513 }
514 return e;
515}
#define DPVSIMPLEDECODEERROR_SOUNDBUFFERTOOSMALL
#define DPVSIMPLEDECODEERROR_INVALIDBMASK
#define DPVSIMPLEDECODEERROR_INVALIDRMASK
#define DPVSIMPLEDECODEERROR_READERROR
#define DPVSIMPLEDECODEERROR_COLORMASKSEXCEEDBPP
#define DPVSIMPLEDECODEERROR_INVALIDGMASK
#define DPVSIMPLEDECODEERROR_UNSUPPORTEDBPP
#define DPVSIMPLEDECODEERROR_COLORMASKSOVERLAP
#define DPVSIMPLEDECODEERROR_NONE
#define DPVSIMPLEDECODEERROR_EOF

References DPVSIMPLEDECODEERROR_COLORMASKSEXCEEDBPP, DPVSIMPLEDECODEERROR_COLORMASKSOVERLAP, DPVSIMPLEDECODEERROR_EOF, DPVSIMPLEDECODEERROR_INVALIDBMASK, DPVSIMPLEDECODEERROR_INVALIDGMASK, DPVSIMPLEDECODEERROR_INVALIDRMASK, DPVSIMPLEDECODEERROR_NONE, DPVSIMPLEDECODEERROR_READERROR, DPVSIMPLEDECODEERROR_SOUNDBUFFERTOOSMALL, DPVSIMPLEDECODEERROR_UNSUPPORTEDBPP, and dpvsimpledecodestream_t::error.

◆ dpvsimpledecode_getaspectratio()

double dpvsimpledecode_getaspectratio ( void * stream)

Definition at line 539 of file dpvsimpledecode.c.

540{
542 return s->info_aspectratio;
543}

References dpvsimpledecodestream_t::info_aspectratio.

Referenced by dpvsimpledecode_open().

◆ dpvsimpledecode_getframerate()

double dpvsimpledecode_getframerate ( void * stream)

Definition at line 532 of file dpvsimpledecode.c.

533{
535 return s->info_framerate;
536}

References dpvsimpledecodestream_t::info_framerate.

Referenced by dpvsimpledecode_open().

◆ dpvsimpledecode_getheight()

unsigned int dpvsimpledecode_getheight ( void * stream)

Definition at line 525 of file dpvsimpledecode.c.

526{
528 return s->info_imageheight;
529}

References dpvsimpledecodestream_t::info_imageheight.

Referenced by dpvsimpledecode_open().

◆ dpvsimpledecode_getwidth()

unsigned int dpvsimpledecode_getwidth ( void * stream)

Definition at line 518 of file dpvsimpledecode.c.

519{
521 return s->info_imagewidth;
522}

References dpvsimpledecodestream_t::info_imagewidth.

Referenced by dpvsimpledecode_open().

◆ dpvsimpledecode_open()

void * dpvsimpledecode_open ( clvideo_t * video,
char * filename,
const char ** errorstring )

Definition at line 356 of file dpvsimpledecode.c.

357{
359 char t[8], *wavename;
360 if (errorstring != NULL)
361 *errorstring = NULL;
363 if (s != NULL)
364 {
365 s->bitstream = hz_bitstream_read_open(filename);
366 if (s->bitstream != NULL)
367 {
368 // check file identification
370 if (s->framedatablocks != NULL)
371 {
374 if (!memcmp(t, "DPVideo", 8))
375 {
376 // check version number
379 {
383 s->info_framerate = (double) hz_bitstream_read_int(s->framedatablocks) * (1.0 / 65536.0);
384 s->info_aspectratio = (double)s->info_imagewidth / (double)s->info_imageheight;
385
386 if (s->info_framerate > 0.0)
387 {
388 s->videopixels = (unsigned int *)Z_Malloc(s->info_imagewidth * s->info_imageheight * sizeof(*s->videopixels));
389 if (s->videopixels != NULL)
390 {
391 size_t namelen;
392
393 namelen = strlen(filename) + 10;
394 wavename = (char *)Z_Malloc(namelen);
395 if (wavename)
396 {
397 sfx_t* sfx;
398
399 FS_StripExtension(filename, wavename, namelen);
400 dp_strlcat(wavename, ".wav", namelen);
401 sfx = S_PrecacheSound (wavename, false, false);
402 if (sfx != NULL)
403 s->sndchan = S_StartSound (-1, 0, sfx, vec3_origin, 1.0f, 0);
404 else
405 s->sndchan = -1;
406 Z_Free(wavename);
407 }
408 // all is well...
409 // set the module functions
410 s->videoframenum = -10000;
417
418 return s;
419 }
420 else if (errorstring != NULL)
421 *errorstring = "unable to allocate video image buffer";
422 }
423 else if (errorstring != NULL)
424 *errorstring = "error in video info chunk";
425 }
426 else if (errorstring != NULL)
427 *errorstring = "read error";
428 }
429 else if (errorstring != NULL)
430 *errorstring = "not a dpvideo file";
432 }
433 else if (errorstring != NULL)
434 *errorstring = "unable to allocate memory for reading buffer";
436 }
437 else if (errorstring != NULL)
438 *errorstring = "unable to open file";
439 Z_Free(s);
440 }
441 else if (errorstring != NULL)
442 *errorstring = "unable to allocate memory for stream info structure";
443 return NULL;
444}
#define dp_strlcat(dst, src, dsize)
Definition common.h:304
static unsigned int hz_bitstream_read_int(hz_bitstream_readblocks_t *blocks)
static hz_bitstream_read_t * hz_bitstream_read_open(char *filename)
double dpvsimpledecode_getframerate(void *stream)
unsigned int dpvsimpledecode_getwidth(void *stream)
static void hz_bitstream_read_bytes(hz_bitstream_readblocks_t *blocks, void *outdata, unsigned int size)
void dpvsimpledecode_close(void *stream)
static int hz_bitstream_read_blocks_read(hz_bitstream_readblocks_t *blocks, hz_bitstream_read_t *stream, unsigned int size)
double dpvsimpledecode_getaspectratio(void *stream)
int dpvsimpledecode_video(void *stream, void *imagedata, unsigned int Rmask, unsigned int Gmask, unsigned int Bmask, unsigned int bytesperpixel, int imagebytesperrow)
static hz_bitstream_readblocks_t * hz_bitstream_read_blocks_new(void)
unsigned int dpvsimpledecode_getheight(void *stream)
static unsigned int hz_bitstream_read_short(hz_bitstream_readblocks_t *blocks)
void FS_StripExtension(const char *in, char *out, size_t size_out)
Definition fs.c:3611
vec3_t vec3_origin
Definition mathlib.c:26
float strlen(string s)
int S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
S_StartSound returns the channel index, or -1 if an error occurred.
Definition snd_main.c:1643
sfx_t * S_PrecacheSound(const char *name, qbool complain, qbool levelsound)
Definition snd_main.c:1048
void(* close)(void *stream)
Definition cl_video.h:62
double(* getframerate)(void *stream)
Definition cl_video.h:65
unsigned int(* getheight)(void *stream)
Definition cl_video.h:64
int(* decodeframe)(void *stream, void *imagedata, unsigned int Rmask, unsigned int Gmask, unsigned int Bmask, unsigned int bytesperpixel, int imagebytesperrow)
Definition cl_video.h:67
double(* getaspectratio)(void *stream)
Definition cl_video.h:66
unsigned int(* getwidth)(void *stream)
Definition cl_video.h:63
#define Z_Malloc(size)
Definition zone.h:161

References dpvsimpledecodestream_t::bitstream, clvideo_t::close, clvideo_t::decodeframe, dp_strlcat, dpvsimpledecode_close(), dpvsimpledecode_getaspectratio(), dpvsimpledecode_getframerate(), dpvsimpledecode_getheight(), dpvsimpledecode_getwidth(), dpvsimpledecode_video(), dpvsimpledecodestream_t::framedatablocks, FS_StripExtension(), clvideo_t::getaspectratio, clvideo_t::getframerate, clvideo_t::getheight, clvideo_t::getwidth, hz_bitstream_read_blocks_free(), hz_bitstream_read_blocks_new(), hz_bitstream_read_blocks_read(), hz_bitstream_read_bytes(), hz_bitstream_read_close(), hz_bitstream_read_int(), hz_bitstream_read_open(), hz_bitstream_read_short(), dpvsimpledecodestream_t::info_aspectratio, dpvsimpledecodestream_t::info_framerate, dpvsimpledecodestream_t::info_imageheight, dpvsimpledecodestream_t::info_imagewidth, NULL, S_PrecacheSound(), S_StartSound(), dpvsimpledecodestream_t::sndchan, strlen(), vec3_origin, dpvsimpledecodestream_t::videoframenum, dpvsimpledecodestream_t::videopixels, Z_Free, and Z_Malloc.

Referenced by OpenStream().

◆ dpvsimpledecode_video()

int dpvsimpledecode_video ( void * stream,
void * imagedata,
unsigned int Rmask,
unsigned int Gmask,
unsigned int Bmask,
unsigned int bytesperpixel,
int imagebytesperrow )

Definition at line 651 of file dpvsimpledecode.c.

652{
654 unsigned int framedatasize;
655 char t[4];
657 if (dpvsimpledecode_setpixelformat(s, Rmask, Gmask, Bmask, bytesperpixel))
658 return s->error;
659
662 if (memcmp(t, "VID0", 4))
663 {
664 if (t[0] == 0)
665 return (s->error = DPVSIMPLEDECODEERROR_EOF);
666 else
668 }
669 framedatasize = hz_bitstream_read_int(s->framedatablocks);
672 return s->error;
673
674 dpvsimpledecode_convertpixels(s, imagedata, imagebytesperrow);
675 return s->error;
676}
static int dpvsimpledecode_decompressimage(dpvsimpledecodestream_t *s)
static int dpvsimpledecode_convertpixels(dpvsimpledecodestream_t *s, void *imagedata, int imagebytesperrow)
static int dpvsimpledecode_setpixelformat(dpvsimpledecodestream_t *s, unsigned int Rmask, unsigned int Gmask, unsigned int Bmask, unsigned int bytesperpixel)

References dpvsimpledecodestream_t::bitstream, dpvsimpledecode_convertpixels(), dpvsimpledecode_decompressimage(), dpvsimpledecode_setpixelformat(), DPVSIMPLEDECODEERROR_EOF, DPVSIMPLEDECODEERROR_NONE, DPVSIMPLEDECODEERROR_READERROR, dpvsimpledecodestream_t::error, dpvsimpledecodestream_t::framedatablocks, hz_bitstream_read_blocks_read(), hz_bitstream_read_bytes(), and hz_bitstream_read_int().

Referenced by dpvsimpledecode_open().