Skip to content

Commit

Permalink
Make videos automatically destruct like other Allegro objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
SiegeLordEx authored and SiegeLord committed Nov 22, 2024
1 parent b2f5887 commit 83318d7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
20 changes: 10 additions & 10 deletions addons/audio/allegro5/internal/aintern_audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */
};
Expand Down Expand Up @@ -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 *);

Expand Down Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion addons/video/allegro5/internal/aintern_video.h
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -10,7 +14,7 @@ typedef struct ALLEGRO_VIDEO_INTERFACE {

struct ALLEGRO_VIDEO {
ALLEGRO_VIDEO_INTERFACE *vtable;

/* video */
ALLEGRO_BITMAP *current_frame;
double video_position;
Expand All @@ -32,6 +36,8 @@ struct ALLEGRO_VIDEO {
bool playing;
double position;

_AL_LIST_ITEM *dtor_item;

/* implementation specific */
void *data;
};
Expand All @@ -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
9 changes: 6 additions & 3 deletions addons/video/ogv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand All @@ -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");

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1240,7 +1244,6 @@ static bool ogv_close_video(ALLEGRO_VIDEO *video)

al_free(ogv);
}

video->data = NULL;

return true;
Expand Down
9 changes: 8 additions & 1 deletion addons/video/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
}
Expand All @@ -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
Expand Down

0 comments on commit 83318d7

Please sign in to comment.