summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-11-02 20:46:38 +0100
committerGitHub <noreply@github.com>2018-11-02 20:46:38 +0100
commitf84893f70901dfca356d949ea1585a56154cb59f (patch)
treedc01cc1ada8dba06994e21cf23345cc60631809f /scene/gui
parent414097ebd954c2f05e1b57a6fab2bbdd195feb3d (diff)
parentea43218bcae434899bb4fe2bc741ba828479b8bd (diff)
Merge pull request #23457 from marcelofg55/crashfix_vp
Fix possible crash with VideoPlayer _mix_audio function
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/video_player.cpp57
1 files changed, 18 insertions, 39 deletions
diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp
index 39e7c73390..812ca0042b 100644
--- a/scene/gui/video_player.cpp
+++ b/scene/gui/video_player.cpp
@@ -90,53 +90,32 @@ void VideoPlayer::_mix_audio() {
AudioFrame vol = AudioFrame(volume, volume);
- // Copy to server's audio buffer
- switch (AudioServer::get_singleton()->get_speaker_mode()) {
+ int cc = AudioServer::get_singleton()->get_channel_count();
- case AudioServer::SPEAKER_MODE_STEREO: {
- AudioFrame *target = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 0);
+ if (cc == 1) {
+ AudioFrame *target = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 0);
+ ERR_FAIL_COND(!target);
- for (int j = 0; j < buffer_size; j++) {
+ for (int j = 0; j < buffer_size; j++) {
- target[j] += buffer[j] * vol;
- }
-
- } break;
- case AudioServer::SPEAKER_SURROUND_31: {
-
- // FIXME: Implement
- } break;
- case AudioServer::SPEAKER_SURROUND_51: {
-
- AudioFrame *targets[2] = {
- AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 1),
- AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 2),
- };
-
- for (int j = 0; j < buffer_size; j++) {
+ target[j] += buffer[j] * vol;
+ }
- AudioFrame frame = buffer[j] * vol;
- targets[0][j] = frame;
- targets[1][j] = frame;
- }
- } break;
- case AudioServer::SPEAKER_SURROUND_71: {
+ } else {
+ AudioFrame *targets[4];
- AudioFrame *targets[3] = {
- AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 1),
- AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 2),
- AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 3)
- };
+ for (int k = 0; k < cc; k++) {
+ targets[k] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, k);
+ ERR_FAIL_COND(!targets[k]);
+ }
- for (int j = 0; j < buffer_size; j++) {
+ for (int j = 0; j < buffer_size; j++) {
- AudioFrame frame = buffer[j] * vol;
- targets[0][j] += frame;
- targets[1][j] += frame;
- targets[2][j] += frame;
+ AudioFrame frame = buffer[j] * vol;
+ for (int k = 0; k < cc; k++) {
+ targets[k][j] += frame;
}
-
- } break;
+ }
}
}