int apeg_play_mpg_ex(void *ptr, BITMAP *bmp, int loop, int (*callback)(BITMAP*)) { int ret; Initialize_Decoder(); apeg_stream = apeg_open_stream_ex(ptr); if(!apeg_stream) return APEG_ERROR; if(bmp) clear_to_color(bmp, makecol(0, 0, 0)); if(callback) callback_proc = callback; else callback_proc = default_callback; restart_loop: ret = decode_stream((APEG_LAYER*)apeg_stream, bmp); if(loop && ret == APEG_OK) { apeg_reset_stream(apeg_stream); goto restart_loop; } apeg_close_stream(apeg_stream); apeg_stream = NULL; return ret; }
int apeg_play_apeg_stream(APEG_STREAM *stream_to_play, BITMAP *bmp, int loop, int (*callback)(BITMAP*tempBuffer)) { int ret = APEG_OK; apeg_stream = stream_to_play; Initialize_Decoder(); if(bmp) clear_to_color(bmp, makecol(0, 0, 0)); // Install the callback function if(callback) callback_proc = callback; else callback_proc = default_callback; restart_loop: ret = decode_stream((APEG_LAYER*)apeg_stream, bmp); if(loop && ret == APEG_OK) { apeg_reset_stream(apeg_stream); goto restart_loop; } apeg_stream = NULL; return ret; }
void VideoManager::unloadVideo() { if ( cmov != NULL ) { apeg_reset_stream(cmov); apeg_close_stream(cmov); } if ( videoBuffer != NULL ) { free(videoBuffer); } videoBuffer = NULL; cmov = NULL; }
int apeg_advance_stream(APEG_STREAM *stream, int loop) { APEG_LAYER *layer = (APEG_LAYER*)stream; int ret; // Set the jump buffer if((ret = setjmp(jmp_buffer)) != 0) return ret; layer->stream.frame_updated = -1; layer->stream.audio.flushed = FALSE; ret = APEG_OK; if((layer->stream.flags&APEG_HAS_AUDIO) && layer->multiple > 0.0) { ret = _apeg_audio_poll(layer); if((layer->stream.flags&APEG_HAS_VIDEO)) { int t = _apeg_audio_get_position(layer); if(t >= 0) layer->stream.timer = (double)t*stream->frame_rate/ (double)stream->audio.freq - stream->frame; } } if((layer->stream.flags&APEG_HAS_VIDEO)) { if(!layer->picture) { if((layer->stream.flags&APEG_MPG_VIDEO)) { // Get the next MPEG header if(apeg_get_header(layer) == 1) { // Decode the next picture if(layer->picture_type != B_TYPE || !framedrop || layer->stream.timer <= 1) layer->picture = apeg_get_frame(layer); } // If end of stream, display the last frame else if((!framedrop || layer->stream.timer <= 1) && !layer->got_last) { layer->got_last = TRUE; layer->picture = layer->backward_frame; } } else layer->picture = altheora_get_frame(layer); if(pack_feof(layer->pf) && (!(layer->stream.flags&APEG_HAS_AUDIO)|| layer->multiple==0.0 || ret!=APEG_OK)) ret = APEG_EOF; } if(layer->stream.timer > 0) { // Update frame and timer count ++(layer->stream.frame); --(layer->stream.timer); // If we're not behind, update the display frame layer->stream.frame_updated = 0; if(layer->picture && (!framedrop || layer->stream.timer == 0)) apeg_display_frame(layer, layer->picture); layer->picture = NULL; } if(layer->stream.frame_updated == 1 || layer->picture) ret = APEG_OK; } if(ret == APEG_EOF && loop) ret = apeg_reset_stream((APEG_STREAM*)layer); return ret; }