added mutex for smush and cleanup
This commit is contained in:
parent
27c598a35b
commit
435cd288e3
2 changed files with 28 additions and 21 deletions
42
smush.cpp
42
smush.cpp
|
@ -23,10 +23,11 @@
|
||||||
#include "smush.h"
|
#include "smush.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "mixer/mixer.h"
|
#include "mixer/mixer.h"
|
||||||
#include "driver_gl.h"
|
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
|
||||||
|
#include "driver_gl.h"
|
||||||
|
|
||||||
Smush *g_smush;
|
Smush *g_smush;
|
||||||
extern SoundMixer *g_mixer;
|
extern SoundMixer *g_mixer;
|
||||||
|
|
||||||
|
@ -36,8 +37,10 @@ void Smush::timerCallback(void *refCon) {
|
||||||
|
|
||||||
Smush::Smush() {
|
Smush::Smush() {
|
||||||
g_smush = this;
|
g_smush = this;
|
||||||
|
_mutex = create_mutex();
|
||||||
_nbframes = 0;
|
_nbframes = 0;
|
||||||
_dst = NULL;
|
_internalBuffer = NULL;
|
||||||
|
_externalBuffer = NULL;
|
||||||
_width = 0;
|
_width = 0;
|
||||||
_height = 0;
|
_height = 0;
|
||||||
_speed = 0;
|
_speed = 0;
|
||||||
|
@ -48,19 +51,24 @@ Smush::Smush() {
|
||||||
_updateNeeded = false;
|
_updateNeeded = false;
|
||||||
_stream = NULL;
|
_stream = NULL;
|
||||||
_movieTime = 0;
|
_movieTime = 0;
|
||||||
_surface = NULL;
|
|
||||||
_bufSurface = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Smush::~Smush() {
|
Smush::~Smush() {
|
||||||
deinit();
|
deinit();
|
||||||
if (_surface)
|
if (_internalBuffer) {
|
||||||
SDL_FreeSurface(_surface);
|
free(_internalBuffer);
|
||||||
if (_bufSurface)
|
_internalBuffer = NULL;
|
||||||
SDL_FreeSurface(_bufSurface);
|
}
|
||||||
|
if (_externalBuffer) {
|
||||||
|
free(_externalBuffer);
|
||||||
|
_externalBuffer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete_mutex(_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Smush::init() {
|
void Smush::init() {
|
||||||
|
StackLock lock(_mutex);
|
||||||
_stream = NULL;
|
_stream = NULL;
|
||||||
_frame = 0;
|
_frame = 0;
|
||||||
_movieTime = 0;
|
_movieTime = 0;
|
||||||
|
@ -68,19 +76,18 @@ void Smush::init() {
|
||||||
_videoPause = false;
|
_videoPause = false;
|
||||||
_updateNeeded = false;
|
_updateNeeded = false;
|
||||||
|
|
||||||
if (!_surface) {
|
if (!_internalBuffer) {
|
||||||
_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, _width, _height, 16, 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000);
|
_internalBuffer = (byte *)malloc(_width * _height * 2);
|
||||||
_dst = (byte *)_surface->pixels;
|
|
||||||
}
|
}
|
||||||
if (!_bufSurface) {
|
if (!_externalBuffer) {
|
||||||
_bufSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, _width, _height, 16, 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000);
|
_externalBuffer = (byte *)malloc(_width * _height * 2);
|
||||||
_buf = (byte *)_bufSurface->pixels;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_timer->installTimerProc(&timerCallback, _speed, NULL);
|
g_timer->installTimerProc(&timerCallback, _speed, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Smush::deinit() {
|
void Smush::deinit() {
|
||||||
|
StackLock lock(_mutex);
|
||||||
g_timer->removeTimerProc(&timerCallback);
|
g_timer->removeTimerProc(&timerCallback);
|
||||||
|
|
||||||
_videoFinished = true;
|
_videoFinished = true;
|
||||||
|
@ -88,12 +95,13 @@ void Smush::deinit() {
|
||||||
if (_stream) {
|
if (_stream) {
|
||||||
_stream->finish();
|
_stream->finish();
|
||||||
_stream = NULL;
|
_stream = NULL;
|
||||||
|
g_mixer->stopHandle(_soundHandle);
|
||||||
}
|
}
|
||||||
_file.close();
|
_file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Smush::handleBlocky16(byte *src) {
|
void Smush::handleBlocky16(byte *src) {
|
||||||
_blocky16.decode(_dst, src);
|
_blocky16.decode(_internalBuffer, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16 destTable[5786];
|
static uint16 destTable[5786];
|
||||||
|
@ -112,7 +120,6 @@ void Smush::handleWave(const byte *src, uint32 size) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int flags = SoundMixer::FLAG_16BITS | SoundMixer::FLAG_AUTOFREE;
|
int flags = SoundMixer::FLAG_16BITS | SoundMixer::FLAG_AUTOFREE;
|
||||||
// int flags = SoundMixer::FLAG_16BITS | SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_LITTLE_ENDIAN;
|
|
||||||
if (_channels == 2)
|
if (_channels == 2)
|
||||||
flags |= SoundMixer::FLAG_STEREO;
|
flags |= SoundMixer::FLAG_STEREO;
|
||||||
|
|
||||||
|
@ -125,6 +132,7 @@ void Smush::handleWave(const byte *src, uint32 size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Smush::handleFrame() {
|
void Smush::handleFrame() {
|
||||||
|
StackLock lock(_mutex);
|
||||||
uint32 tag;
|
uint32 tag;
|
||||||
int32 size;
|
int32 size;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
@ -167,7 +175,7 @@ void Smush::handleFrame() {
|
||||||
} while (pos < size);
|
} while (pos < size);
|
||||||
free(frame);
|
free(frame);
|
||||||
|
|
||||||
memcpy(_buf, _dst, _width * _height * 2);
|
memcpy(_externalBuffer, _internalBuffer, _width * _height * 2);
|
||||||
_updateNeeded = true;
|
_updateNeeded = true;
|
||||||
|
|
||||||
_frame++;
|
_frame++;
|
||||||
|
|
7
smush.h
7
smush.h
|
@ -56,6 +56,7 @@ private:
|
||||||
zlibFile _file;
|
zlibFile _file;
|
||||||
PlayingSoundHandle _soundHandle;
|
PlayingSoundHandle _soundHandle;
|
||||||
AppendableAudioStream *_stream;
|
AppendableAudioStream *_stream;
|
||||||
|
MutexRef _mutex;
|
||||||
|
|
||||||
int32 _frame;
|
int32 _frame;
|
||||||
bool _updateNeeded;
|
bool _updateNeeded;
|
||||||
|
@ -67,9 +68,7 @@ private:
|
||||||
bool _videoPause;
|
bool _videoPause;
|
||||||
int _x, _y;
|
int _x, _y;
|
||||||
int _width, _height;
|
int _width, _height;
|
||||||
byte *_dst, *_buf;
|
byte *_internalBuffer, *_externalBuffer;
|
||||||
SDL_Surface* _surface;
|
|
||||||
SDL_Surface* _bufSurface;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Smush();
|
Smush();
|
||||||
|
@ -80,7 +79,7 @@ public:
|
||||||
void pause(bool pause) { _videoPause = pause; }
|
void pause(bool pause) { _videoPause = pause; }
|
||||||
bool isPlaying() { return !_videoFinished; }
|
bool isPlaying() { return !_videoFinished; }
|
||||||
bool isUpdateNeeded() { return _updateNeeded; }
|
bool isUpdateNeeded() { return _updateNeeded; }
|
||||||
byte *getDstPtr() { return _buf; }
|
byte *getDstPtr() { return _externalBuffer; }
|
||||||
int getX() { return _x; }
|
int getX() { return _x; }
|
||||||
int getY() { return _y; }
|
int getY() { return _y; }
|
||||||
int getWidth() {return _width; }
|
int getWidth() {return _width; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue