Set safe values to prevent possible sigsegv while using AudioTransport, add doc
Bug: webrtc:8946
Change-Id: Ica066a05905894fba6ba24e45af46b0d5951b5d5
Reviewed-on: https://webrtc-review.googlesource.com/65040
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22652}
diff --git a/modules/audio_device/audio_device_data_observer.cc b/modules/audio_device/audio_device_data_observer.cc
index 5f7259d..bcec3d5 100644
--- a/modules/audio_device/audio_device_data_observer.cc
+++ b/modules/audio_device/audio_device_data_observer.cc
@@ -71,6 +71,11 @@
int64_t* elapsed_time_ms,
int64_t* ntp_time_ms) override {
int32_t res = 0;
+ // Set out parameters to safe values to be sure not to return corrupted
+ // data.
+ nSamplesOut = 0;
+ *elapsed_time_ms = -1;
+ *ntp_time_ms = -1;
// Request data from audio transport.
if (audio_transport_) {
res = audio_transport_->NeedMorePlayData(
diff --git a/modules/audio_device/include/audio_device_defines.h b/modules/audio_device/include/audio_device_defines.h
index bb9a0db..0495442 100644
--- a/modules/audio_device/include/audio_device_defines.h
+++ b/modules/audio_device/include/audio_device_defines.h
@@ -45,6 +45,7 @@
const bool keyPressed,
uint32_t& newMicLevel) = 0; // NOLINT
+ // Implementation has to setup safe values for all specified out parameters.
virtual int32_t NeedMorePlayData(const size_t nSamples,
const size_t nBytesPerSample,
const size_t nChannels,
diff --git a/modules/audio_device/include/test_audio_device.cc b/modules/audio_device/include/test_audio_device.cc
index b674822..8ee2160 100644
--- a/modules/audio_device/include/test_audio_device.cc
+++ b/modules/audio_device/include/test_audio_device.cc
@@ -174,8 +174,8 @@
}
if (rendering_) {
size_t samples_out = 0;
- int64_t elapsed_time_ms = 0;
- int64_t ntp_time_ms = 0;
+ int64_t elapsed_time_ms = -1;
+ int64_t ntp_time_ms = -1;
const int sampling_frequency = renderer_->SamplingFrequency();
audio_callback_->NeedMorePlayData(
SamplesPerFrame(sampling_frequency), 2, renderer_->NumChannels(),