Fixed looping and pauses

This commit is contained in:
2025-10-06 08:14:03 +03:00
parent 7d2dad09ad
commit 2dc7aa9b00
3 changed files with 8 additions and 7 deletions

View File

@@ -89,10 +89,10 @@ private:
_ffmpeg::AVStream *videoStream, *audioStream; _ffmpeg::AVStream *videoStream, *audioStream;
struct _ffmpeg::SwsContext *swsCtx = NULL; // Visual struct _ffmpeg::SwsContext *swsCtx = NULL; // Visual
struct _ffmpeg::SwrContext *swrCtx = NULL; // Audio struct _ffmpeg::SwrContext *swrCtx = NULL; // Audio
int8_t videoStreamNum = -1, audioStreamNum = -1;
uint16_t ID = 0; uint16_t ID = 0;
// Time specific // Time specific
int8_t videoStreamNum = -1, audioStreamNum = -1;
uint32_t currentFrameNumber = 0; uint32_t currentFrameNumber = 0;
double timeBase = 0, clock = 0; double timeBase = 0, clock = 0;
@@ -100,11 +100,11 @@ private:
ChargeAudio::Engine *audioEngine; ChargeAudio::Engine *audioEngine;
ChargeAudio::SoundContainer bufferedAudio; ChargeAudio::SoundContainer bufferedAudio;
// Channel data // Audio Channel data
_ffmpeg::AVChannelLayout outLayout; _ffmpeg::AVChannelLayout outLayout;
_ffmpeg::AVSampleFormat sampleFormat = _ffmpeg::AV_SAMPLE_FMT_FLT; _ffmpeg::AVSampleFormat sampleFormat = _ffmpeg::AV_SAMPLE_FMT_FLT;
// Buffering // Image Buffering
std::map<double, Image2D> frameBuffer; std::map<double, Image2D> frameBuffer;
uint32_t bufferMaxFrames = 0; uint32_t bufferMaxFrames = 0;

View File

@@ -17,8 +17,6 @@ void Time::AdvanceTime() {
if (time.currentFrameTime() == 0.0f) { if (time.currentFrameTime() == 0.0f) {
time.start(); time.start();
} }
// We are giving average delta for frame timing stablisation
DeltaTime = time.currentFrameDuration(); DeltaTime = time.currentFrameDuration();
for (auto processVideo : videoPlayMethods) { for (auto processVideo : videoPlayMethods) {

View File

@@ -92,6 +92,7 @@ Video::Video(std::string path, ChargeAudio::Engine *engine,
} else { } else {
outLayout = AV_CHANNEL_LAYOUT_MONO; outLayout = AV_CHANNEL_LAYOUT_MONO;
} }
swr_alloc_set_opts2(&swrCtx, &outLayout, sampleFormat, swr_alloc_set_opts2(&swrCtx, &outLayout, sampleFormat,
audioEngine->GetSampleRate(), &aCodecCtx->ch_layout, audioEngine->GetSampleRate(), &aCodecCtx->ch_layout,
aCodecCtx->sample_fmt, aCodecCtx->sample_rate, 0, NULL); aCodecCtx->sample_fmt, aCodecCtx->sample_rate, 0, NULL);
@@ -149,7 +150,6 @@ void Video::StartLooping() { isVideoLooping = true; }
// ================== Private Video Controls ================== // ================== Private Video Controls ==================
void Video::continueVideo() { void Video::continueVideo() {
// Looping handling // Looping handling
/* Shelved for now
if (currentFrameNumber >= videoStream->nb_frames - 2) { if (currentFrameNumber >= videoStream->nb_frames - 2) {
if (!isVideoLooping) { if (!isVideoLooping) {
isVideoOver = true; isVideoOver = true;
@@ -157,7 +157,7 @@ void Video::continueVideo() {
return; // We remove what we are returning TO return; // We remove what we are returning TO
} }
restartVideo(); restartVideo();
}*/ }
// Timing // Timing
// Audio Synced // Audio Synced
@@ -353,9 +353,12 @@ void Video::restartVideo() {
avcodec_flush_buffers(vCodecCtx); avcodec_flush_buffers(vCodecCtx);
avcodec_flush_buffers(aCodecCtx); avcodec_flush_buffers(aCodecCtx);
currentFrameNumber = 0; currentFrameNumber = 0;
dumpAndRefillBuffer();
} }
void Video::dumpAndRefillBuffer() { void Video::dumpAndRefillBuffer() {
std::map<double, Image2D>().swap(frameBuffer); std::map<double, Image2D>().swap(frameBuffer);
bufferedAudio.release();
bufferedAudio = audioEngine->CreateSound(10);
loadTexture(loadNextFrame().second); loadTexture(loadNextFrame().second);
} }