X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=dpvsimpledecode.c;h=d17ced77d5f4ddbb3601e29810ab606c8e54f08b;hp=0d30b4f703e1a3dec7e85a82191886a9f4ff30a4;hb=694e1787027f9d4baba22603d91f1b7c96964278;hpb=b37129d36872d2d42d861024433c34239b24f6a3 diff --git a/dpvsimpledecode.c b/dpvsimpledecode.c index 0d30b4f7..d17ced77 100644 --- a/dpvsimpledecode.c +++ b/dpvsimpledecode.c @@ -1,26 +1,17 @@ -#include -#include -#include -#include +#include "quakedef.h" #include "dpvsimpledecode.h" -#include "wavefile.h" -#define EMBEDDEDHZREAD 1 - -#ifndef EMBEDDEDHZREAD -#include "hz_read.h" -#include "hz_read.c" -#else #define HZREADERROR_OK 0 #define HZREADERROR_EOF 1 #define HZREADERROR_MALLOCFAILED 2 -#define HZREADBLOCKSIZE 16000 +//#define HZREADBLOCKSIZE 16000 +#define HZREADBLOCKSIZE 1048576 -typedef struct +typedef struct hz_bitstream_read_s { - FILE *file; + qfile_t *file; int endoffile; } hz_bitstream_read_t; @@ -33,7 +24,7 @@ typedef struct hz_bitstream_readblock_s } hz_bitstream_readblock_t; -typedef struct +typedef struct hz_bitstream_readblocks_s { hz_bitstream_readblock_t *blocks; hz_bitstream_readblock_t *current; @@ -45,11 +36,11 @@ hz_bitstream_readblocks_t; hz_bitstream_read_t *hz_bitstream_read_open(char *filename) { - FILE *file; + qfile_t *file; hz_bitstream_read_t *stream; - if ((file = fopen(filename, "rb"))) + if ((file = FS_Open (filename, "rb", false, false))) { - stream = malloc(sizeof(hz_bitstream_read_t)); + stream = (hz_bitstream_read_t *)Z_Malloc(sizeof(hz_bitstream_read_t)); memset(stream, 0, sizeof(*stream)); stream->file = file; return stream; @@ -62,26 +53,15 @@ void hz_bitstream_read_close(hz_bitstream_read_t *stream) { if (stream) { - fclose(stream->file); - free(stream); + FS_Close(stream->file); + Z_Free(stream); } } -unsigned int hz_bitstream_read_currentbyte(hz_bitstream_read_t *stream) -{ - return ftell(stream->file); -} - -int hz_bitstream_read_seek(hz_bitstream_read_t *stream, unsigned int position) -{ - stream->endoffile = 0; - return fseek(stream->file, position, SEEK_SET) != 0; -} - hz_bitstream_readblocks_t *hz_bitstream_read_blocks_new(void) { hz_bitstream_readblocks_t *blocks; - blocks = malloc(sizeof(hz_bitstream_readblocks_t)); + blocks = (hz_bitstream_readblocks_t *)Z_Malloc(sizeof(hz_bitstream_readblocks_t)); if (blocks == NULL) return NULL; memset(blocks, 0, sizeof(hz_bitstream_readblocks_t)); @@ -96,9 +76,9 @@ void hz_bitstream_read_blocks_free(hz_bitstream_readblocks_t *blocks) for (b = blocks->blocks;b;b = n) { n = b->next; - free(b); + Z_Free(b); } - free(blocks); + Z_Free(blocks); } void hz_bitstream_read_flushbits(hz_bitstream_readblocks_t *blocks) @@ -118,7 +98,7 @@ int hz_bitstream_read_blocks_read(hz_bitstream_readblocks_t *blocks, hz_bitstrea { if (b == NULL) { - b = malloc(sizeof(hz_bitstream_readblock_t)); + b = (hz_bitstream_readblock_t *)Z_Malloc(sizeof(hz_bitstream_readblock_t)); if (b == NULL) return HZREADERROR_MALLOCFAILED; b->next = NULL; @@ -133,7 +113,7 @@ int hz_bitstream_read_blocks_read(hz_bitstream_readblocks_t *blocks, hz_bitstrea else b->size = s; s -= b->size; - if (fread(b->data, 1, b->size, stream->file) != b->size) + if (FS_Read(stream->file, b->data, b->size) != (fs_offset_t)b->size) { stream->endoffile = 1; break; @@ -221,11 +201,10 @@ unsigned int hz_bitstream_read_int(hz_bitstream_readblocks_t *blocks) void hz_bitstream_read_bytes(hz_bitstream_readblocks_t *blocks, void *outdata, unsigned int size) { unsigned char *out; - out = outdata; + out = (unsigned char *)outdata; while (size--) *out++ = hz_bitstream_read_byte(blocks); } -#endif #define BLOCKSIZE 8 @@ -258,8 +237,8 @@ typedef struct dpvsimpledecodestream_s // current video frame data (needed because of delta compression) unsigned int *videopixels; - // wav file the sound is being read from - wavefile_t *wavefile; + // channel the sound file is being played on + int sndchan; } dpvsimpledecodestream_t; @@ -385,7 +364,7 @@ void *dpvsimpledecode_open(char *filename, char **errorstring) char t[8], *wavename; if (errorstring != NULL) *errorstring = NULL; - s = malloc(sizeof(dpvsimpledecodestream_t)); + s = (dpvsimpledecodestream_t *)Z_Malloc(sizeof(dpvsimpledecodestream_t)); if (s != NULL) { s->bitstream = hz_bitstream_read_open(filename); @@ -410,16 +389,22 @@ void *dpvsimpledecode_open(char *filename, char **errorstring) if (s->info_framerate > 0.0) { - s->videopixels = malloc(s->info_imagewidth * s->info_imageheight * sizeof(*s->videopixels)); + s->videopixels = (unsigned int *)Z_Malloc(s->info_imagewidth * s->info_imageheight * sizeof(*s->videopixels)); if (s->videopixels != NULL) { - wavename = malloc(strlen(filename) + 10); + wavename = (char *)Z_Malloc(strlen(filename) + 10); if (wavename) { + sfx_t* sfx; + StripExtension(filename, wavename); strcat(wavename, ".wav"); - s->wavefile = waveopen(wavename, NULL); - free(wavename); + sfx = S_PrecacheSound (wavename, false, false); + if (sfx != NULL) + s->sndchan = S_StartSound (-1, 0, sfx, vec3_origin, 1.0f, 0); + else + s->sndchan = -1; + Z_Free(wavename); } // all is well... s->videoframenum = -10000; @@ -444,7 +429,7 @@ void *dpvsimpledecode_open(char *filename, char **errorstring) } else if (errorstring != NULL) *errorstring = "unable to open file"; - free(s); + Z_Free(s); } else if (errorstring != NULL) *errorstring = "unable to allocate memory for stream info structure"; @@ -454,18 +439,18 @@ void *dpvsimpledecode_open(char *filename, char **errorstring) // closes a stream void dpvsimpledecode_close(void *stream) { - dpvsimpledecodestream_t *s = stream; + dpvsimpledecodestream_t *s = (dpvsimpledecodestream_t *)stream; if (s == NULL) return; if (s->videopixels) - free(s->videopixels); - if (s->wavefile) - waveclose(s->wavefile); + Z_Free(s->videopixels); + if (s->sndchan != -1) + S_StopChannel (s->sndchan); if (s->framedatablocks) hz_bitstream_read_blocks_free(s->framedatablocks); if (s->bitstream) hz_bitstream_read_close(s->bitstream); - free(s); + Z_Free(s); } // utilitarian functions @@ -476,7 +461,7 @@ void dpvsimpledecode_close(void *stream) // error message int dpvsimpledecode_error(void *stream, char **errorstring) { - dpvsimpledecodestream_t *s = stream; + dpvsimpledecodestream_t *s = (dpvsimpledecodestream_t *)stream; int e; e = s->error; s->error = 0; @@ -525,31 +510,21 @@ int dpvsimpledecode_error(void *stream, char **errorstring) // returns the width of the image data unsigned int dpvsimpledecode_getwidth(void *stream) { - dpvsimpledecodestream_t *s = stream; + dpvsimpledecodestream_t *s = (dpvsimpledecodestream_t *)stream; return s->info_imagewidth; } // returns the height of the image data unsigned int dpvsimpledecode_getheight(void *stream) { - dpvsimpledecodestream_t *s = stream; + dpvsimpledecodestream_t *s = (dpvsimpledecodestream_t *)stream; return s->info_imageheight; } -// returns the sound sample rate of the stream -unsigned int dpvsimpledecode_getsoundrate(void *stream) -{ - dpvsimpledecodestream_t *s = stream; - if (s->wavefile) - return s->wavefile->info_rate; - else - return 0; -} - // returns the framerate of the stream double dpvsimpledecode_getframerate(void *stream) { - dpvsimpledecodestream_t *s = stream; + dpvsimpledecodestream_t *s = (dpvsimpledecodestream_t *)stream; return s->info_framerate; } @@ -582,7 +557,7 @@ static int dpvsimpledecode_convertpixels(dpvsimpledecodestream_t *s, void *image unsigned int *outrow; for (y = 0;y < height;y++) { - outrow = (void *)((unsigned char *)imagedata + y * imagebytesperrow); + outrow = (unsigned int *)((unsigned char *)imagedata + y * imagebytesperrow); for (x = 0;x < width;x++) { a = *in++; @@ -595,7 +570,7 @@ static int dpvsimpledecode_convertpixels(dpvsimpledecodestream_t *s, void *image unsigned short *outrow; for (y = 0;y < height;y++) { - outrow = (void *)((unsigned char *)imagedata + y * imagebytesperrow); + outrow = (unsigned short *)((unsigned char *)imagedata + y * imagebytesperrow); if (Rloss == 19 && Gloss == 10 && Bloss == 3 && Rshift == 11 && Gshift == 5 && Bshift == 0) { // optimized @@ -665,7 +640,7 @@ static int dpvsimpledecode_decompressimage(dpvsimpledecodestream_t *s) // decodes a video frame to the supplied output pixels int dpvsimpledecode_video(void *stream, void *imagedata, unsigned int Rmask, unsigned int Gmask, unsigned int Bmask, unsigned int bytesperpixel, int imagebytesperrow) { - dpvsimpledecodestream_t *s = stream; + dpvsimpledecodestream_t *s = (dpvsimpledecodestream_t *)stream; unsigned int framedatasize; char t[4]; s->error = DPVSIMPLEDECODEERROR_NONE; @@ -689,20 +664,3 @@ int dpvsimpledecode_video(void *stream, void *imagedata, unsigned int Rmask, uns dpvsimpledecode_convertpixels(s, imagedata, imagebytesperrow); return s->error; } - -// (note: sound is 16bit stereo native-endian, left channel first) -int dpvsimpledecode_audio(void *stream, short *soundbuffer, int requestedlength) -{ - int samples; - dpvsimpledecodestream_t *s = stream; - s->error = DPVSIMPLEDECODEERROR_NONE; - if (requestedlength) - { - samples = 0; - if (s->wavefile && requestedlength) - samples = waveread16stereo(s->wavefile, soundbuffer, requestedlength); - if (samples < requestedlength) - memset(soundbuffer + samples * 2, 0, (requestedlength - samples) * sizeof(short[2])); - } - return s->error; -}