diff --git a/addons/audio/allegro5/internal/aintern_audio.h b/addons/audio/allegro5/internal/aintern_audio.h index b7fe5f4617..9e7930cc26 100644 --- a/addons/audio/allegro5/internal/aintern_audio.h +++ b/addons/audio/allegro5/internal/aintern_audio.h @@ -12,13 +12,13 @@ struct ALLEGRO_AUDIO_RECORDER { ALLEGRO_EVENT_SOURCE source; - + ALLEGRO_THREAD *thread; ALLEGRO_MUTEX *mutex; ALLEGRO_COND *cond; /* recording is done in its own thread as implemented by the driver */ - + ALLEGRO_AUDIO_DEPTH depth; ALLEGRO_CHANNEL_CONF chan_conf; unsigned int frequency; @@ -31,17 +31,17 @@ struct ALLEGRO_AUDIO_RECORDER { unsigned int samples; /* the number of samples returned at every FRAGMENT event */ - + size_t fragment_size; /* size in bytes of each fragument */ unsigned int sample_size; /* the size in bytes of each sample */ - - volatile bool is_recording; + + volatile bool is_recording; /* true if the driver should actively be updating the buffer */ - + void *extra; /* custom data for the driver to use as needed */ }; @@ -80,8 +80,8 @@ struct ALLEGRO_AUDIO_DRIVER { unsigned int (*get_voice_position)(const ALLEGRO_VOICE*); int (*set_voice_position)(ALLEGRO_VOICE*, unsigned int); - - + + int (*allocate_recorder)(struct ALLEGRO_AUDIO_RECORDER *); void (*deallocate_recorder)(struct ALLEGRO_AUDIO_RECORDER *); @@ -213,8 +213,8 @@ struct ALLEGRO_SAMPLE_INSTANCE { int step; int step_denom; - /* The numerator and denominator of the step are - * stored separately. The actual step is obtained by + /* The numerator and denominator of the step are + * stored separately. The actual step is obtained by * dividing step by step_denom */ float *matrix; diff --git a/addons/video/allegro5/internal/aintern_video.h b/addons/video/allegro5/internal/aintern_video.h index 3f8d24bc45..634d38236d 100644 --- a/addons/video/allegro5/internal/aintern_video.h +++ b/addons/video/allegro5/internal/aintern_video.h @@ -1,3 +1,7 @@ +#ifndef __al_included_allegro_aintern_video_h +#define __al_included_allegro_aintern_video_h + +#include "allegro5/internal/aintern_list.h" typedef struct ALLEGRO_VIDEO_INTERFACE { bool (*open_video)(ALLEGRO_VIDEO *video); @@ -10,7 +14,7 @@ typedef struct ALLEGRO_VIDEO_INTERFACE { struct ALLEGRO_VIDEO { ALLEGRO_VIDEO_INTERFACE *vtable; - + /* video */ ALLEGRO_BITMAP *current_frame; double video_position; @@ -32,6 +36,8 @@ struct ALLEGRO_VIDEO { bool playing; double position; + _AL_LIST_ITEM *dtor_item; + /* implementation specific */ void *data; }; @@ -42,3 +48,5 @@ void _al_compute_scaled_dimensions(int frame_w, int frame_h, float aspect_ratio, ALLEGRO_VIDEO_INTERFACE *_al_video_ogv_vtable(void); bool _al_video_identify_ogv(ALLEGRO_FILE *f); + +#endif diff --git a/addons/video/ogv.c b/addons/video/ogv.c index 66021cf37a..9c4b2bfc93 100644 --- a/addons/video/ogv.c +++ b/addons/video/ogv.c @@ -17,6 +17,7 @@ #include "allegro5/allegro5.h" #include "allegro5/allegro_audio.h" #include "allegro5/allegro_video.h" +#include "allegro5/internal/aintern_dtor.h" #include "allegro5/internal/aintern_vector.h" #include "allegro5/internal/aintern_video.h" @@ -999,6 +1000,8 @@ static void *decode_thread_func(ALLEGRO_THREAD *thread, void *_video) ALLEGRO_DEBUG("Thread started.\n"); + /* Destruction is handled by al_close_video. */ + _al_push_destructor_owner(); tstream_outer = ogv->selected_video_stream; if (tstream_outer) { ASSERT(tstream_outer->stream_type == STREAM_TYPE_THEORA); @@ -1022,6 +1025,7 @@ static void *decode_thread_func(ALLEGRO_THREAD *thread, void *_video) if (!tstream_outer && !vstream_outer) { ALLEGRO_WARN("No audio or video stream found.\n"); + _al_pop_destructor_owner(); return NULL; } @@ -1037,8 +1041,9 @@ static void *decode_thread_func(ALLEGRO_THREAD *thread, void *_video) if (video->audio) { al_register_event_source(ogv->queue, - al_get_audio_stream_event_source(video->audio)); + al_get_audio_stream_event_source(video->audio)); } + _al_pop_destructor_owner(); ALLEGRO_DEBUG("Begin decode loop.\n"); @@ -1207,7 +1212,6 @@ static bool ogv_open_video(ALLEGRO_VIDEO *video) video->data = ogv; return true; } - static bool ogv_close_video(ALLEGRO_VIDEO *video) { OGG_VIDEO *ogv; @@ -1240,7 +1244,6 @@ static bool ogv_close_video(ALLEGRO_VIDEO *video) al_free(ogv); } - video->data = NULL; return true; diff --git a/addons/video/video.c b/addons/video/video.c index fc1957dd38..9c688fe0a7 100644 --- a/addons/video/video.c +++ b/addons/video/video.c @@ -41,9 +41,11 @@ #include "allegro5/allegro5.h" #include "allegro5/allegro_video.h" #include "allegro5/internal/aintern.h" +#include "allegro5/internal/aintern_dtor.h" +#include "allegro5/internal/aintern_exitfunc.h" +#include "allegro5/internal/aintern_system.h" #include "allegro5/internal/aintern_video.h" #include "allegro5/internal/aintern_video_cfg.h" -#include "allegro5/internal/aintern_exitfunc.h" #include "allegro5/internal/aintern_vector.h" ALLEGRO_DEBUG_CHANNEL("video") @@ -129,6 +131,7 @@ ALLEGRO_VIDEO *al_open_video(char const *filename) al_init_user_event_source(&video->es); video->es_inited = true; + video->dtor_item = _al_register_destructor(_al_dtor_list, "video", video, (void (*)(void *)) al_close_video); return video; } @@ -143,6 +146,7 @@ void al_close_video(ALLEGRO_VIDEO *video) al_destroy_user_event_source(&video->es); } al_destroy_path(video->filename); + _al_unregister_destructor(_al_dtor_list, video->dtor_item); al_free(video); } } @@ -164,7 +168,10 @@ void al_start_video(ALLEGRO_VIDEO *video, ALLEGRO_MIXER *mixer) /* XXX why is this not just a parameter? */ video->mixer = mixer; video->playing = true; + /* Destruction is handled by al_close_video. */ + _al_push_destructor_owner(); video->vtable->start_video(video); + _al_pop_destructor_owner(); } /* Function: al_start_video_with_voice