diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/layer.cpp | 21 | ||||
-rw-r--r-- | src/layer.h | 38 | ||||
-rw-r--r-- | src/layer_video.cpp | 15 | ||||
-rw-r--r-- | src/layer_video.h | 7 | ||||
-rw-r--r-- | src/osc_graphics.h | 23 | ||||
-rw-r--r-- | src/recorder.cpp | 1 | ||||
-rw-r--r-- | src/recorder.h | 18 |
7 files changed, 53 insertions, 70 deletions
diff --git a/src/layer.cpp b/src/layer.cpp index f1db856..d213d7c 100644 --- a/src/layer.cpp +++ b/src/layer.cpp @@ -11,12 +11,20 @@ #include "osc_server.h" #include "layer.h" -Layer::Layer(const char *_name) : mutex(SDL_CreateMutex()), name(strdup(_name)) +Layer::Layer(const char *_name) : Mutex(), name(strdup(_name)) { geo_osc_id = register_method("geo", GEO_TYPES, geo_osc); alpha_osc_id = register_method("alpha", "f", alpha_osc); } +Layer::~Layer() +{ + unregister_method(alpha_osc_id); + unregister_method(geo_osc_id); + + free(name); +} + void LayerList::insert(int pos, Layer *layer) { @@ -66,11 +74,12 @@ LayerList::render(SDL_Surface *target) unlock(); } -Layer::~Layer() +LayerList::~LayerList() { - unregister_method(alpha_osc_id); - unregister_method(geo_osc_id); + while (LIST_FIRST(&head)) { + Layer *layer = LIST_FIRST(&head); - free(name); - SDL_DestroyMutex(mutex); + LIST_REMOVE(layer, layers); + delete layer; + } } diff --git a/src/layer.h b/src/layer.h index 21fab50..378acbd 100644 --- a/src/layer.h +++ b/src/layer.h @@ -5,7 +5,6 @@ #include <bsd/sys/queue.h> #include <SDL.h> -#include <SDL_thread.h> #include <lo/lo.h> @@ -14,9 +13,7 @@ extern OSCServer osc_server; -class Layer { - SDL_mutex *mutex; - +class Layer : public Mutex { public: /* * Every derived class must have a static CtorInfo struct "ctor_info" @@ -34,17 +31,6 @@ public: Layer(const char *name); virtual ~Layer(); - inline void - lock() - { - SDL_LockMutex(mutex); - } - inline void - unlock() - { - SDL_UnlockMutex(mutex); - } - /* * Frame render method */ @@ -91,31 +77,15 @@ private: } }; -class LayerList { +class LayerList : Mutex { LIST_HEAD(layers_head, Layer) head; - SDL_mutex *mutex; - - inline void - lock() - { - SDL_LockMutex(mutex); - } - inline void - unlock() - { - SDL_UnlockMutex(mutex); - } - public: - LayerList() : mutex(SDL_CreateMutex()) + LayerList() : Mutex() { LIST_INIT(&head); } - ~LayerList() - { - SDL_DestroyMutex(mutex); - } + ~LayerList(); void insert(int pos, Layer *layer); void delete_layer(Layer *layer); diff --git a/src/layer_video.cpp b/src/layer_video.cpp index 1734d9e..859455f 100644 --- a/src/layer_video.cpp +++ b/src/layer_video.cpp @@ -6,7 +6,6 @@ #include <math.h> #include <SDL.h> -#include <SDL_thread.h> #include <SDL_rotozoom.h> /* HACK: older SDL_gfx versions define GFX_ALPHA_ADJUST in the header */ @@ -37,9 +36,8 @@ static void display_cb(void *data, void *id); } LayerVideo::LayerVideo(const char *name, SDL_Rect geo, float opacity, - const char *url) : - Layer(name), mp(NULL), surf(NULL), - mutex(SDL_CreateMutex()) + const char *url) + : Layer(name), mp(NULL), surf(NULL) { /* static initialization */ if (!vlcinst) { @@ -243,12 +241,12 @@ LayerVideo::frame(SDL_Surface *target) if (surf->w != geov.w || surf->h != geov.h) { SDL_Surface *surf_scaled; - SDL_LockMutex(mutex); + mutex.lock(); surf_scaled = zoomSurface(surf, (double)geov.w/surf->w, (double)geov.h/surf->h, SMOOTHING_ON); - SDL_UnlockMutex(mutex); + mutex.unlock(); if (alpha < SDL_ALPHA_OPAQUE) { if (surf_scaled->format->Amask) @@ -267,9 +265,9 @@ LayerVideo::frame(SDL_Surface *target) else SDL_SetAlpha(surf, SDL_SRCALPHA | SDL_RLEACCEL, alpha); - SDL_LockMutex(mutex); + mutex.lock(); SDL_BlitSurface(surf, NULL, target, &geov); - SDL_UnlockMutex(mutex); + mutex.unlock(); } } @@ -283,7 +281,6 @@ LayerVideo::~LayerVideo() if (mp) libvlc_media_player_release(mp); libvlc_release(vlcinst); - SDL_DestroyMutex(mutex); if (surf) SDL_FreeSurface(surf); } diff --git a/src/layer_video.h b/src/layer_video.h index c3a4806..1ae3e18 100644 --- a/src/layer_video.h +++ b/src/layer_video.h @@ -2,7 +2,6 @@ #define __LAYER_VIDEO_H #include <SDL.h> -#include <SDL_thread.h> #include <lo/lo.h> @@ -16,7 +15,7 @@ class LayerVideo : public Layer { libvlc_media_player_t *mp; SDL_Surface *surf; - SDL_mutex *mutex; + Mutex mutex; SDL_Rect geov; float alphav; @@ -42,7 +41,7 @@ public: inline void * lock_surf() { - SDL_LockMutex(mutex); + mutex.lock(); SDL_MAYBE_LOCK(surf); return surf->pixels; } @@ -50,7 +49,7 @@ public: unlock_surf() { SDL_MAYBE_UNLOCK(surf); - SDL_UnlockMutex(mutex); + mutex.unlock(); } void frame(SDL_Surface *target); diff --git a/src/osc_graphics.h b/src/osc_graphics.h index c36ef54..47afa7d 100644 --- a/src/osc_graphics.h +++ b/src/osc_graphics.h @@ -4,6 +4,29 @@ #include <stdio.h> #include <SDL.h> +#include <SDL_thread.h> + +class Mutex { + SDL_mutex *mutex; + +public: + Mutex() : mutex(SDL_CreateMutex()) {} + virtual ~Mutex() + { + SDL_DestroyMutex(mutex); + } + + inline void + lock() + { + SDL_LockMutex(mutex); + } + inline void + unlock() + { + SDL_UnlockMutex(mutex); + } +}; #include "osc_server.h" #include "layer.h" diff --git a/src/recorder.cpp b/src/recorder.cpp index 6859f1b..0bd7b23 100644 --- a/src/recorder.cpp +++ b/src/recorder.cpp @@ -126,5 +126,4 @@ Recorder::~Recorder() osc_server.del_method("", "/recorder/stop"); SDL_FFMPEGFREE_SAFE(file); - SDL_DestroyMutex(mutex); } diff --git a/src/recorder.h b/src/recorder.h index b2ee5e6..591312e 100644 --- a/src/recorder.h +++ b/src/recorder.h @@ -2,29 +2,15 @@ #define __RECORDER_H #include <SDL.h> -#include <SDL_thread.h> #include <SDL/SDL_ffmpeg.h> #include "osc_graphics.h" -class Recorder { +class Recorder : Mutex { SDL_ffmpegFile *file; - SDL_mutex *mutex; - - inline void - lock() - { - SDL_LockMutex(mutex); - } - inline void - unlock() - { - SDL_UnlockMutex(mutex); - } - public: - Recorder() : file(NULL), mutex(SDL_CreateMutex()) {} + Recorder() : Mutex(), file(NULL) {} ~Recorder(); void register_methods(); |