summaryrefslogtreecommitdiff
path: root/src/bink.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bink.c')
-rw-r--r--src/bink.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/bink.c b/src/bink.c
index 6f357b6..2f54be0 100644
--- a/src/bink.c
+++ b/src/bink.c
@@ -280,13 +280,16 @@ static int DecodeAudioFrame(struct binkMovie* aMovie)
return 1;
}
+// Return 0 iff we have reached the end of file.
static int ReadPacket(struct binkMovie* aMovie)
{
// Read from file if no packet is buffered.
if (!aMovie->packet.buf && av_read_frame(aMovie->context, &aMovie->packet) < 0) {
// No more packets in file.
if (aMovie->looping) {
- av_seek_frame(aMovie->context, -1, 0, 0);
+ // This needs ffmpeg≄4.4 to work for smacker files.
+ if (avformat_seek_file(aMovie->context, -1, 0, 0, 0, 0) < 0)
+ return 0;
return ReadPacket(aMovie);
} else {
// Drain buffered frames.
@@ -299,7 +302,7 @@ static int ReadPacket(struct binkMovie* aMovie)
}
// Send the (possibly buffered) packet to decoder.
- int ret = AVERROR(EAGAIN);
+ int ret = 0;
if (aMovie->packet.stream_index == aMovie->videoStream)
ret = avcodec_send_packet(aMovie->videoContext, &aMovie->packet);
else if (aMovie->packet.stream_index == aMovie->audioStream)
@@ -349,7 +352,8 @@ static int BinkStartMovie(struct binkMovie* aMovie, const char* aFilename,
continue;
}
- if (aMovie->videoStream < 0 && context->codec_type == AVMEDIA_TYPE_VIDEO) {
+ // Music files may contain a video stream, we just ignore it.
+ if (!aMusicFlag && aMovie->videoStream < 0 && context->codec_type == AVMEDIA_TYPE_VIDEO) {
aMovie->videoContext = context;
aMovie->videoStream = i;
aMovie->videoFrame = av_frame_alloc();
@@ -478,18 +482,15 @@ int PlayMusicBink(int volume)
if (!musicMovie.context)
return 1;
- if (musicMovie.audioStream < 0 || !musicMovie.alInited)
+ if (musicMovie.audioStream < 0)
return 1;
alSourcef(musicMovie.alSource, AL_GAIN, PlatVolumeToGain(volume));
- for (int i = 0; i < musicMovie.context->nb_streams * AUDIO_FRAMES; i++) {
- int processedBuffers = 0;
- alGetSourcei(musicMovie.alSource, AL_BUFFERS_PROCESSED, &processedBuffers);
- if (processedBuffers + musicMovie.alNumFreeBuffers > 0)
- if (!ReadPacket(&musicMovie))
- return 0;
+ if (BinkUpdateMovie(&musicMovie) >= 0) {
+ ProcessAudio(&musicMovie);
+ return 1;
}
- return 1;
+ return 0;
}
void EndMusicBink()