aboutsummaryrefslogtreecommitdiff
path: root/video/video_decoder.cpp
diff options
context:
space:
mode:
authorMatthew Hoops2014-01-09 21:27:22 -0500
committerMatthew Hoops2014-01-11 18:43:41 -0500
commitda604b530b37ad1908644e97b816ae34118bd7c1 (patch)
treea7b025c71a36890c38ee213c3ed3334abf24d31b /video/video_decoder.cpp
parent592526dc5d66b4249f8acd1d4b3ad3d7fa1854bf (diff)
downloadscummvm-rg350-da604b530b37ad1908644e97b816ae34118bd7c1.tar.gz
scummvm-rg350-da604b530b37ad1908644e97b816ae34118bd7c1.tar.bz2
scummvm-rg350-da604b530b37ad1908644e97b816ae34118bd7c1.zip
VIDEO: Allow for audio track selection in video types that support it
Diffstat (limited to 'video/video_decoder.cpp')
-rw-r--r--video/video_decoder.cpp60
1 files changed, 57 insertions, 3 deletions
diff --git a/video/video_decoder.cpp b/video/video_decoder.cpp
index 0ab1478727..931bde20d0 100644
--- a/video/video_decoder.cpp
+++ b/video/video_decoder.cpp
@@ -46,6 +46,7 @@ VideoDecoder::VideoDecoder() {
_endTime = 0;
_endTimeSet = false;
_nextVideoTrack = 0;
+ _mainAudioTrack = 0;
// Find the best format for output
_defaultHighColorFormat = g_system->getScreenFormat();
@@ -75,6 +76,7 @@ void VideoDecoder::close() {
_endTime = 0;
_endTimeSet = false;
_nextVideoTrack = 0;
+ _mainAudioTrack = 0;
}
bool VideoDecoder::loadFile(const Common::String &filename) {
@@ -553,6 +555,9 @@ Audio::Timestamp VideoDecoder::FixedRateVideoTrack::getDuration() const {
return getFrameTime(getFrameCount());
}
+VideoDecoder::AudioTrack::AudioTrack() : _volume(Audio::Mixer::kMaxChannelVolume), _balance(0), _muted(false) {
+}
+
bool VideoDecoder::AudioTrack::endOfTrack() const {
Audio::AudioStream *stream = getAudioStream();
return !stream || !g_system->getMixer()->isSoundHandleActive(_handle) || stream->endOfData();
@@ -562,7 +567,7 @@ void VideoDecoder::AudioTrack::setVolume(byte volume) {
_volume = volume;
if (g_system->getMixer()->isSoundHandleActive(_handle))
- g_system->getMixer()->setChannelVolume(_handle, _volume);
+ g_system->getMixer()->setChannelVolume(_handle, _muted ? 0 : _volume);
}
void VideoDecoder::AudioTrack::setBalance(int8 balance) {
@@ -578,7 +583,7 @@ void VideoDecoder::AudioTrack::start() {
Audio::AudioStream *stream = getAudioStream();
assert(stream);
- g_system->getMixer()->playStream(getSoundType(), &_handle, stream, -1, getVolume(), getBalance(), DisposeAfterUse::NO);
+ g_system->getMixer()->playStream(getSoundType(), &_handle, stream, -1, _muted ? 0 : getVolume(), getBalance(), DisposeAfterUse::NO);
// Pause the audio again if we're still paused
if (isPaused())
@@ -597,7 +602,7 @@ void VideoDecoder::AudioTrack::start(const Audio::Timestamp &limit) {
stream = Audio::makeLimitingAudioStream(stream, limit, DisposeAfterUse::NO);
- g_system->getMixer()->playStream(getSoundType(), &_handle, stream, -1, getVolume(), getBalance(), DisposeAfterUse::YES);
+ g_system->getMixer()->playStream(getSoundType(), &_handle, stream, -1, _muted ? 0 : getVolume(), getBalance(), DisposeAfterUse::YES);
// Pause the audio again if we're still paused
if (isPaused())
@@ -611,6 +616,16 @@ uint32 VideoDecoder::AudioTrack::getRunningTime() const {
return 0;
}
+void VideoDecoder::AudioTrack::setMute(bool mute) {
+ // Update the mute settings, if required
+ if (_muted != mute) {
+ _muted = mute;
+
+ if (g_system->getMixer()->isSoundHandleActive(_handle))
+ g_system->getMixer()->setChannelVolume(_handle, mute ? 0 : _volume);
+ }
+}
+
void VideoDecoder::AudioTrack::pauseIntern(bool shouldPause) {
if (g_system->getMixer()->isSoundHandleActive(_handle))
g_system->getMixer()->pauseHandle(_handle, shouldPause);
@@ -669,6 +684,17 @@ void VideoDecoder::addTrack(Track *track, bool isExternal) {
// Update volume settings if it's an audio track
((AudioTrack *)track)->setVolume(_audioVolume);
((AudioTrack *)track)->setBalance(_audioBalance);
+
+ if (!isExternal && supportsAudioTrackSwitching()) {
+ if (_mainAudioTrack) {
+ // The main audio track has already been found
+ ((AudioTrack *)track)->setMute(true);
+ } else {
+ // First audio track found -> now the main one
+ _mainAudioTrack = (AudioTrack *)track;
+ _mainAudioTrack->setMute(false);
+ }
+ }
} else if (track->getTrackType() == Track::kTrackTypeVideo) {
// If this track has a better time, update _nextVideoTrack
if (!_nextVideoTrack || ((VideoTrack *)track)->getNextFrameStartTime() < _nextVideoTrack->getNextFrameStartTime())
@@ -701,6 +727,34 @@ bool VideoDecoder::addStreamFileTrack(const Common::String &baseName) {
return result;
}
+bool VideoDecoder::setAudioTrack(int index) {
+ if (!supportsAudioTrackSwitching())
+ return false;
+
+ AudioTrack *audioTrack = getAudioTrack(index);
+
+ if (!audioTrack)
+ return false;
+
+ if (_mainAudioTrack == audioTrack)
+ return true;
+
+ _mainAudioTrack->setMute(true);
+ audioTrack->setMute(false);
+ _mainAudioTrack = audioTrack;
+ return true;
+}
+
+uint VideoDecoder::getAudioTrackCount() const {
+ uint count = 0;
+
+ for (TrackList::const_iterator it = _internalTracks.begin(); it != _internalTracks.end(); it++)
+ if ((*it)->getTrackType() == Track::kTrackTypeAudio)
+ count++;
+
+ return count;
+}
+
void VideoDecoder::setEndTime(const Audio::Timestamp &endTime) {
Audio::Timestamp startTime = 0;