diff options
| author | Timotej Lazar <timotej.lazar@araneo.si> | 2020-11-08 20:03:53 +0100 |
|---|---|---|
| committer | Timotej Lazar <timotej.lazar@araneo.si> | 2020-11-14 17:14:18 +0100 |
| commit | 0fd40ff481bdc82b5d221075127367895c59d5ce (patch) | |
| tree | db4607a578532eca260b06b94248d7a233627f78 /src/bink.c | |
| parent | 5b9a0e939cef04ee3307cb1bd0796cb4a1b344ed (diff) | |
Implement music in menus
Diffstat (limited to 'src/bink.c')
| -rw-r--r-- | src/bink.c | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -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() |
