Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Core/GameEngine/Include/GameClient/VideoPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ class VideoPlayerInterface : public SubsystemInterface
virtual const FieldParse *getFieldParse() const = 0; ///< Return the field parse info

virtual void notifyVideoPlayerOfNewProvider( Bool nowHasValid ) = 0; ///< Notify the video player that they can now ask for an audio handle, or they need to give theirs up.

virtual void setVolume( Real volume ) = 0; ///< Push a new speech volume to the video player's audio output
};


Expand Down Expand Up @@ -294,6 +296,8 @@ class VideoPlayer : public VideoPlayerInterface

virtual void notifyVideoPlayerOfNewProvider( Bool nowHasValid ) override { }

virtual void setVolume( Real volume ) override { }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FFmpegVideoPlayer derives from VideoPlayer, so it picks up this no-op and the volume plumbing is Bink-only. Override it there too?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FFmpegVideoPlayer now overrides setVolume and pushes the speech volume to the OpenAL movie stream. Initial volume is also applied when the stream starts, since that backend is already live by then.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait do we have OpenAL in upstream yet? This might not work until we get that landed :(

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, OpenAL is not in this repo yet. The FFmpeg override is behind RTS_USE_OPENAL so Miles/Bink builds keep a no-op, and the OpenAL gain path is just plumbing until that backend lands.


// Implementation specific
void remove( VideoStream *stream ); ///< remove stream from active list

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ class BinkVideoStream : public VideoStream

class BinkVideoPlayer : public VideoPlayer
{
private:

static Int calculateMovieAudioVolume( Real volume );
Bool m_volumeApplied;

protected:

Expand All @@ -127,6 +131,7 @@ class BinkVideoPlayer : public VideoPlayer
virtual VideoStreamInterface* load( AsciiString movieTitle ) override; ///< Load video file in to memory for playback

virtual void notifyVideoPlayerOfNewProvider( Bool nowHasValid ) override;
virtual void setVolume( Real volume ) override;
virtual void initializeBinkWithMiles();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class FFmpegVideoPlayer : public VideoPlayer
virtual VideoStreamInterface* load( AsciiString movieTitle ); ///< Load video file in to memory for playback

virtual void notifyVideoPlayerOfNewProvider( Bool nowHasValid );
virtual void setVolume( Real volume );
virtual void initializeBinkWithMiles();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,11 @@ void MilesAudioManager::processPlayingList()

if (m_volumeHasChanged) {
m_volumeHasChanged = false;

// Push speech volume changes because Bink movie audio bypasses the Miles mixer.
if (TheVideoPlayer) {
TheVideoPlayer->setVolume(getVolume(AudioAffect_Speech));
}
}
}

Expand Down
41 changes: 33 additions & 8 deletions Core/GameEngineDevice/Source/VideoDevice/Bink/BinkVideoPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
//============================================================================

BinkVideoPlayer::BinkVideoPlayer()
: m_volumeApplied(FALSE)
{

}
Expand Down Expand Up @@ -160,6 +161,12 @@ void BinkVideoPlayer::update()
{
VideoPlayer::update();

Comment thread
xezon marked this conversation as resolved.
// createStream() is too early; apply once a live stream exists.
if ( !m_volumeApplied && firstStream() != nullptr )
{
setVolume( TheAudio->getVolume(AudioAffect_Speech) );
m_volumeApplied = TRUE;
}
}

//============================================================================
Expand Down Expand Up @@ -201,19 +208,37 @@ VideoStreamInterface* BinkVideoPlayer::createStream( HBINK handle )
stream->m_next = m_firstStream;
stream->m_player = this;
m_firstStream = stream;

// never let volume go to 0, as Bink will interpret that as "play at full volume".
Int mod = (Int) ((TheAudio->getVolume(AudioAffect_Speech) * 0.8f) * 100) + 1;
Int volume = (32768*mod)/100;
DEBUG_LOG(("BinkVideoPlayer::createStream() - About to set volume (%g -> %d -> %d",
TheAudio->getVolume(AudioAffect_Speech), mod, volume));
BinkSetVolume( stream->m_handle,0, volume);
DEBUG_LOG(("BinkVideoPlayer::createStream() - set volume"));
m_volumeApplied = FALSE;
}

return stream;
}

//============================================================================
// BinkVideoPlayer::calculateMovieAudioVolume
//============================================================================

Int BinkVideoPlayer::calculateMovieAudioVolume( Real volume )
{
// Never let volume go to 0, as Bink will interpret that as "play at full volume".
Int mod = (Int) ((volume * 0.8f) * 100) + 1;
return (32768*mod)/100;
}

//============================================================================
// BinkVideoPlayer::setVolume
//============================================================================

void BinkVideoPlayer::setVolume( Real volume )
{
// Push the new volume to every open stream's audio output.
Int binkVolume = calculateMovieAudioVolume( volume );
for ( VideoStreamInterface* stream = firstStream(); stream != nullptr; stream = stream->next() )
{
BinkSetVolume( static_cast<BinkVideoStream*>( stream )->m_handle, 0, binkVolume );
}
}

//============================================================================
// BinkVideoPlayer::open
//============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,7 @@ VideoStreamInterface* FFmpegVideoPlayer::createStream( File* file )
stream->m_player = this;
m_firstStream = stream;

// never let volume go to 0, as Bink will interpret that as "play at full volume".
Int mod = (Int) ((TheAudio->getVolume(AudioAffect_Speech) * 0.8f) * 100) + 1;
[[maybe_unused]] Int volume = (32768 * mod) / 100;
DEBUG_LOG(("FFmpegVideoPlayer::createStream() - About to set volume (%g -> %d -> %d",
TheAudio->getVolume(AudioAffect_Speech), mod, volume));
//BinkSetVolume( stream->m_handle,0, volume);
DEBUG_LOG(("FFmpegVideoPlayer::createStream() - set volume"));
setVolume( TheAudio->getVolume(AudioAffect_Speech) );
}

return stream;
Expand Down Expand Up @@ -272,6 +266,26 @@ VideoStreamInterface* FFmpegVideoPlayer::load( AsciiString movieTitle )
return open(movieTitle); // load() used to have the same body as open(), so I'm combining them. Munkee.
}

//============================================================================
// FFmpegVideoPlayer::setVolume
//============================================================================

void FFmpegVideoPlayer::setVolume( [[maybe_unused]] Real volume )
{
#ifdef RTS_USE_OPENAL
if ( firstStream() == nullptr )
{
return;
}

OpenALAudioStream* audioStream = (OpenALAudioStream*)TheAudio->getHandleForBink();
if ( audioStream )
{
audioStream->setVolume( volume );
}
#endif
}

//============================================================================
//============================================================================
void FFmpegVideoPlayer::notifyVideoPlayerOfNewProvider( Bool nowHasValid )
Expand Down Expand Up @@ -315,6 +329,7 @@ FFmpegVideoStream::FFmpegVideoStream(FFmpegFile* file)
// Release the audio handle if it's already in use
OpenALAudioStream* audioStream = (OpenALAudioStream*)TheAudio->getHandleForBink();
audioStream->reset();
audioStream->setVolume(TheAudio->getVolume(AudioAffect_Speech));
#endif

// Decode until we have our first video frame
Expand Down
Loading