Added guards for non-audio streams

This commit is contained in:
2025-10-06 08:39:33 +03:00
parent 2dc7aa9b00
commit 45ea75c3af

View File

@@ -122,6 +122,9 @@ void Video::Play() {
return; return;
} }
ID = Time::hookVideo(std::bind(&Video::continueVideo, this)); ID = Time::hookVideo(std::bind(&Video::continueVideo, this));
if (audioStreamNum != -1) {
bufferedAudio->Play();
}
isVideoPaused = false; isVideoPaused = false;
isVideoOver = false; isVideoOver = false;
} }
@@ -131,6 +134,9 @@ void Video::Pause() {
return; return;
} }
Time::unhookVideo(ID); Time::unhookVideo(ID);
if (audioStreamNum != -1) {
bufferedAudio->Pause();
}
ID = 0; ID = 0;
isVideoPaused = true; isVideoPaused = true;
} }
@@ -140,7 +146,6 @@ void Video::Restart() {
Play(); Play();
} }
restartVideo(); restartVideo();
dumpAndRefillBuffer();
} }
void Video::StopLooping() { isVideoLooping = false; } void Video::StopLooping() { isVideoLooping = false; }
@@ -181,7 +186,8 @@ void Video::continueVideo() {
loadImage(std::move(frameData.second))); loadImage(std::move(frameData.second)));
} }
if (bufferedAudio->GetState() != ChargeAudio::Sound::SoundState::Playing) if (audioStreamNum != -1 &&
bufferedAudio->GetState() != ChargeAudio::Sound::SoundState::Playing)
bufferedAudio->Play(); bufferedAudio->Play();
} }
@@ -351,14 +357,19 @@ void Video::frameSetScaleSAR(AVFrame *frame) {
void Video::restartVideo() { void Video::restartVideo() {
av_seek_frame(ctx, videoStreamNum, 0, AVSEEK_FLAG_BACKWARD); av_seek_frame(ctx, videoStreamNum, 0, AVSEEK_FLAG_BACKWARD);
avcodec_flush_buffers(vCodecCtx); avcodec_flush_buffers(vCodecCtx);
if (audioStreamNum != -1) {
avcodec_flush_buffers(aCodecCtx); avcodec_flush_buffers(aCodecCtx);
}
currentFrameNumber = 0; currentFrameNumber = 0;
clock = 0;
dumpAndRefillBuffer(); dumpAndRefillBuffer();
} }
void Video::dumpAndRefillBuffer() { void Video::dumpAndRefillBuffer() {
std::map<double, Image2D>().swap(frameBuffer); std::map<double, Image2D>().swap(frameBuffer);
if (audioStreamNum != -1) {
bufferedAudio.release(); bufferedAudio.release();
bufferedAudio = audioEngine->CreateSound(10); bufferedAudio = audioEngine->CreateSound(10);
}
loadTexture(loadNextFrame().second); loadTexture(loadNextFrame().second);
} }