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");
75 #if ALLEGRO_WIP_VERSION <= 11
76 w = al_get_video_width(video->video);
77 h = al_get_video_height(video->video);
80 w = al_get_video_scaled_width(video->video);
81 h = al_get_video_scaled_height(video->video);
87 video->buffer = al_malloc(video->nbuffers *
sizeof(ALLEGRO_BITMAP *));
89 ts5_fatal(
"ts5_read_video: could not create video buffer\n");
93 for(i=0; i<video->nbuffers; i++) {
94 video->buffer[i] = al_create_bitmap(w, h);
95 if (!video->buffer[i]) {
96 ts5_fatal(
"ts5_read_video: could not create video buffer\n");
115 ts5_log(TS5_LOGLEVEL_2,
"ts5_free_video(%p)\n", video->video);
118 for(i=0; i<video->nbuffers; i++) {
119 al_destroy_bitmap(video->buffer[i]);
121 al_free(video->buffer);
127 al_close_video(video->video);
167 ts5_log(TS5_LOGLEVEL_5,
"ts5_play_video(%p)\n", video);
170 ts5_fatal(
"ts5_play_video: video pointer is null\n");
173 if(!video->ispaused) {
174 al_start_video(video->video, video->mixer);
175 video->isplaying = 1;
179 #if ALLEGRO_WIP_VERSION <= 11
180 al_pause_video(video->video, 0);
183 al_set_video_playing(video->video, 1);
200 ts5_log(TS5_LOGLEVEL_5,
"ts5_pause_video(%p)\n", video);
203 ts5_fatal(
"ts5_pause_video: video pointer is null\n");
206 if (video->isplaying) {
208 #if ALLEGRO_WIP_VERSION <= 11
209 al_pause_video(video->video, 1);
212 al_set_video_playing(video->video, 0);
229 ts5_log(TS5_LOGLEVEL_5,
"ts5_stop_video(%p)\n", video);
232 ts5_fatal(
"ts5_stop_video: video pointer is null\n");
235 if (video->isplaying) {
237 #if ALLEGRO_WIP_VERSION <= 11
238 al_pause_video(video->video, 1);
241 al_set_video_playing(video->video, 0);
246 video->isplaying = 0;
259 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_frame(%p)\n", video);
262 ts5_fatal(
"ts5_get_video_frame: video pointer is null\n");
266 static long int num_frames_processed=0;
267 int inbuf = (num_frames_processed + video->nbuffers - 1) % video->nbuffers;
268 int outbuf = num_frames_processed % video->nbuffers;
270 ALLEGRO_BITMAP *frame = al_get_video_frame(video->video);
273 ALLEGRO_BITMAP *screen = al_get_target_bitmap();
274 al_set_target_bitmap(video->buffer[inbuf]);
275 al_draw_bitmap(frame, 0.0, 0.0, 0);
276 al_set_target_bitmap(screen);
277 num_frames_processed++;
280 return video->buffer[outbuf];
311 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_status(%p)\n", video);
314 ts5_fatal(
"ts5_get_video_status: video pointer is null\n");
317 return (video->isplaying && !video->ispaused);
331 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_status(%p)\n", video);
334 ts5_fatal(
"ts5_get_video_status: video pointer is null\n");
339 #if ALLEGRO_WIP_VERSION <= 11
340 ratio = al_get_video_aspect_ratio(video->video);
361 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_width(%p)\n", video);
364 ts5_fatal(
"ts5_get_video_width: video pointer is null\n");
369 #if ALLEGRO_WIP_VERSION <= 11
370 w = al_get_video_width(video->video);
373 w = al_get_video_scaled_width(video->video);
391 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_height(%p)\n", video);
394 ts5_fatal(
"ts5_get_video_height: video pointer is null\n");
399 #if ALLEGRO_WIP_VERSION <= 11
400 h = al_get_video_height(video->video);
403 h = al_get_video_scaled_height(video->video);
422 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_samplerate(%p)\n", video);
425 ts5_fatal(
"ts5_get_video_samplerate: video pointer is null\n");
428 return al_get_video_audio_rate(video->video);
442 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_framerate(%p)\n", video);
445 ts5_fatal(
"ts5_get_video_framerate: video pointer is null\n");
448 return al_get_video_fps(video->video);
463 ts5_log(TS5_LOGLEVEL_5,
"ts5_set_video_position(%p,%f)\n", video, position);
466 ts5_fatal(
"ts5_set_video_position: video pointer is null\n");
469 double retval = al_get_video_position(video->video, 0);
471 al_seek_video(video->video, position);
487 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_position(%p)\n", video);
490 ts5_fatal(
"ts5_get_video_position: video pointer is null\n");
493 return al_get_video_position(video->video, 0);
508 ts5_log(TS5_LOGLEVEL_5,
"ts5_set_video_gain(%p,%f)\n", video, gain);
511 ts5_fatal(
"ts5_set_video_gain: video pointer is null\n");
514 double retval = al_get_mixer_gain(video->mixer);
515 al_set_mixer_gain(video->mixer, gain);
531 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_video_gain(%p)\n", video);
534 ts5_fatal(
"ts5_get_video_gain: video pointer is null\n");
537 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.