15 #include "../include/tscope5/video.h"
16 #include "../include/tscope5/video_internal.h"
17 #include "../include/tscope5/system_internal.h"
40 ts5_log(TS5_LOGLEVEL_2,
"ts5_read_video(%s)\n", file);
42 TS5_VIDEO *video = NULL;
43 video = (TS5_VIDEO *)al_malloc(
sizeof(TS5_VIDEO));
46 ts5_fatal(
"ts5_read_video: could not allocate video\n");
52 video->video = al_open_video(file);
55 ts5_fatal(
"ts5_read_video: could not read video\n");
59 video->mixer = al_create_mixer(_ts5_status.audio.samplerate,
60 ALLEGRO_AUDIO_DEPTH_FLOAT32,
61 al_get_voice_channels(_ts5_data.audio.voice));
64 ts5_fatal(
"ts5_read_video: could not create mixer\n");
67 if (!al_attach_mixer_to_mixer(video->mixer,
68 _ts5_data.audio.mixer)) {
69 ts5_fatal(
"ts5_read_video: could not attach mixer to voice\n");
72 double w = al_get_video_width(video->video);
73 double h = al_get_video_height(video->video);
76 video->buffer = al_malloc(video->nbuffers *
sizeof(ALLEGRO_BITMAP *));
78 ts5_fatal(
"ts5_read_video: could not create video buffer\n");
82 for(i=0; i<video->nbuffers; i++) {
83 video->buffer[i] = al_create_bitmap(w, h);
84 if (!video->buffer[i]) {
85 ts5_fatal(
"ts5_read_video: could not create video buffer\n");
104 ts5_log(TS5_LOGLEVEL_2,
"ts5_free_video(%p)\n", video->video);
107 for(i=0; i<video->nbuffers; i++) {
108 al_destroy_bitmap(video->buffer[i]);
110 al_free(video->buffer);
116 al_close_video(video->video);
155 ts5_log(TS5_LOGLEVEL_5,
"ts5_play_video(%p)\n", video);
158 ts5_fatal(
"ts5_play_video: video pointer is null\n");
161 if(!video->ispaused) {
162 al_start_video(video->video, video->mixer);
163 video->isplaying = 1;
166 al_pause_video(video->video, 0);
180 ts5_log(TS5_LOGLEVEL_5,
"ts5_pause_video(%p)\n", video);
183 ts5_fatal(
"ts5_pause_video: video pointer is null\n");
186 if (video->isplaying) {
187 al_pause_video(video->video, 1);
201 ts5_log(TS5_LOGLEVEL_5,
"ts5_stop_video(%p)\n", video);
204 ts5_fatal(
"ts5_stop_video: video pointer is null\n");
207 if (video->isplaying) {
208 al_pause_video(video->video, 1);
210 video->isplaying = 0;
223 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_frame(%p)\n", video);
226 ts5_fatal(
"ts5_get_video_frame: video pointer is null\n");
230 static long int num_frames_processed=0;
231 int inbuf = (num_frames_processed + video->nbuffers - 1) % video->nbuffers;
232 int outbuf = num_frames_processed % video->nbuffers;
234 ALLEGRO_BITMAP *frame = al_get_video_frame(video->video);
237 ALLEGRO_BITMAP *screen = al_get_target_bitmap();
238 al_set_target_bitmap(video->buffer[inbuf]);
239 al_draw_bitmap(frame, 0.0, 0.0, 0);
240 al_set_target_bitmap(screen);
241 num_frames_processed++;
244 return video->buffer[outbuf];
275 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_status(%p)\n", video);
278 ts5_fatal(
"ts5_get_video_status: video pointer is null\n");
281 return (video->isplaying && !video->ispaused);
295 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_status(%p)\n", video);
298 ts5_fatal(
"ts5_get_video_status: video pointer is null\n");
301 return al_get_video_aspect_ratio(video->video);
315 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_width(%p)\n", video);
318 ts5_fatal(
"ts5_get_video_width: video pointer is null\n");
321 return al_get_video_width(video->video);
335 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_height(%p)\n", video);
338 ts5_fatal(
"ts5_get_video_height: video pointer is null\n");
341 return al_get_video_height(video->video);
355 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_samplerate(%p)\n", video);
358 ts5_fatal(
"ts5_get_video_samplerate: video pointer is null\n");
361 return al_get_video_audio_rate(video->video);
375 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_framerate(%p)\n", video);
378 ts5_fatal(
"ts5_get_video_framerate: video pointer is null\n");
381 return al_get_video_fps(video->video);
396 ts5_log(TS5_LOGLEVEL_5,
"ts5_set_video_position(%p,%f)\n", video, position);
399 ts5_fatal(
"ts5_set_video_position: video pointer is null\n");
402 double retval = al_get_video_position(video->video, 0);
404 al_seek_video(video->video, position);
420 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_position(%p)\n", video);
423 ts5_fatal(
"ts5_get_video_position: video pointer is null\n");
426 return al_get_video_position(video->video, 0);
441 ts5_log(TS5_LOGLEVEL_5,
"ts5_set_video_gain(%p,%f)\n", video, gain);
444 ts5_fatal(
"ts5_set_video_gain: video pointer is null\n");
447 double retval = al_get_mixer_gain(video->mixer);
448 al_set_mixer_gain(video->mixer, gain);
464 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_gain(%p)\n", video);
467 ts5_fatal(
"ts5_get_video_gain: video pointer is null\n");
470 return al_get_mixer_gain(video->mixer);;
void ts5_play_video(TS5_VIDEO *video)
Start playing a video.
void ts5_free_video(TS5_VIDEO *video)
Free the memory used by a video.
double ts5_get_video_position(TS5_VIDEO *video)
Get the playback position of a video.
TS5_VIDEO * ts5_read_video(const char *file)
Open a video from a file.
double ts5_get_video_framerate(TS5_VIDEO *video)
Get the framerate of a video.
double ts5_get_video_height(TS5_VIDEO *video)
Get the height of a video.
void ts5_pause_video(TS5_VIDEO *video)
Pause playing a video.
double ts5_set_video_position(TS5_VIDEO *video, double position)
Set the playback position of a video.
double ts5_set_video_gain(TS5_VIDEO *video, double gain)
Set the playback gain of a video.
void ts5_check_video(char *calling_function)
Do some checks at the start of each video function.
TS5_BITMAP * ts5_get_video_frame(TS5_VIDEO *video)
Get the next frame of a video.
double ts5_get_video_aspect_ratio(TS5_VIDEO *video)
Get the aspect ratio of a video.
double ts5_get_video_width(TS5_VIDEO *video)
Get the width of a video.
void ts5_stop_video(TS5_VIDEO *video)
Stop playing a video.
void ts5_log(const unsigned int level, const char *format,...)
Send info to a logging window.
double ts5_get_video_gain(TS5_VIDEO *video)
Get the playback gain of a video.
void ts5_fatal(const char *format,...)
Exit safely with an error message.
double ts5_get_video_samplerate(TS5_VIDEO *video)
Get the audio samplerate of a video.
int ts5_get_video_status(TS5_VIDEO *video)
Query whether a video is playing.