Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(785)

Unified Diff: media/audio/audio_output_resampler.cc

Issue 2582703003: Audio output debug recording. (Closed)
Patch Set: Using callbacks instead. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/audio/audio_output_resampler.cc
diff --git a/media/audio/audio_output_resampler.cc b/media/audio/audio_output_resampler.cc
index 9439a634fcdb45a6e38d32768662c8310a5c888e..19d231f936d919b272b432eeae00db1e53bad7cd 100644
--- a/media/audio/audio_output_resampler.cc
+++ b/media/audio/audio_output_resampler.cc
@@ -28,6 +28,11 @@
namespace media {
+namespace {
+// Global running id for OnMoreDataConverters. Used for debug recording.
+int g_next_stream_id = 1;
+} // namespace
+
class OnMoreDataConverter
: public AudioOutputStream::AudioSourceCallback,
public AudioConverter::InputCallback {
@@ -50,10 +55,20 @@ class OnMoreDataConverter
// Clears |source_callback_| and flushes the resampler.
void Stop();
+ // Sets the debug recording callback which is used to pass data after
+ // resampling/buffering. Must be called before Start().
+ void SetDebugRecordingCallback(
+ const AudioOutputResampler::DebugRecordingCallback&
+ debug_recording_callback);
+
bool started() const { return source_callback_ != nullptr; }
bool error_occurred() const { return error_occurred_; }
+ int id() const { return id_; }
+
+ const AudioParameters& output_params() const { return output_params_; }
+
private:
// AudioConverter::InputCallback implementation.
double ProvideInput(AudioBus* audio_bus, uint32_t frames_delayed) override;
@@ -80,9 +95,16 @@ class OnMoreDataConverter
// stream has been stopped.
bool error_occurred_;
- // Information about input and output buffer sizes to be traced.
+ // Information about input buffer sizes to be traced.
const int input_buffer_size_;
- const int output_buffer_size_;
+
+ // Output parameters used for buffer size tracing and for users to get.
+ const AudioParameters output_params_;
+
+ // Used for audio debug recordings. See comment on SetDebugRecordingCallback()
+ // above. |id_| is a unique running id used in the callback.
+ AudioOutputResampler::DebugRecordingCallback debug_recording_callback_;
+ const int id_;
DISALLOW_COPY_AND_ASSIGN(OnMoreDataConverter);
};
@@ -344,6 +366,10 @@ bool AudioOutputResampler::StartStream(
resampler_callback = new OnMoreDataConverter(params_, output_params_);
callbacks_[stream_proxy] =
base::WrapUnique<OnMoreDataConverter>(resampler_callback);
+ if (register_debug_recording_source_callback_)
+ register_debug_recording_source_callback_.Run(resampler_callback->id(),
+ output_params_);
+ resampler_callback->SetDebugRecordingCallback(debug_recording_callback_);
o1ka 2017/01/25 17:47:00 Sorry I can't process it :) Why can't you still ca
Henrik Grunell 2017/01/26 10:25:09 This only sets the callback to forward the data. T
} else {
resampler_callback = it->second.get();
}
@@ -387,6 +413,27 @@ void AudioOutputResampler::CloseStream(AudioOutputProxy* stream_proxy) {
}
}
+void AudioOutputResampler::SetDebugRecordingCallbacks(
+ const RegisterDebugRecordingSourceCallback&
+ register_debug_recording_source_callback,
+ const UnregisterDebugRecordingSourceCallback&
+ unregister_debug_recording_source_callback,
+ const DebugRecordingCallback& debug_recording_callback) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ register_debug_recording_source_callback_ =
+ register_debug_recording_source_callback;
+ unregister_debug_recording_source_callback_ =
+ unregister_debug_recording_source_callback;
+ debug_recording_callback_ = debug_recording_callback;
+
+ for (const auto& it : callbacks_) {
+ register_debug_recording_source_callback.Run(it.second->id(),
o1ka 2017/01/25 17:47:00 Way too many callbacks :( the code is unreadable.
Henrik Grunell 2017/01/26 10:25:09 Yes, exactly what I thought myself later yesterday
+ it.second->output_params());
+ it.second->SetDebugRecordingCallback(debug_recording_callback);
+ }
+}
+
void AudioOutputResampler::StopStreamInternal(
const CallbackMap::value_type& item) {
AudioOutputProxy* stream_proxy = item.first;
@@ -406,6 +453,9 @@ void AudioOutputResampler::StopStreamInternal(
// call above.
if (callback->error_occurred())
dispatcher_->CloseAllIdleStreams();
+
+ if (unregister_debug_recording_source_callback_)
+ unregister_debug_recording_source_callback_.Run(callback->id());
}
OnMoreDataConverter::OnMoreDataConverter(const AudioParameters& input_params,
@@ -417,7 +467,8 @@ OnMoreDataConverter::OnMoreDataConverter(const AudioParameters& input_params,
audio_converter_(input_params, output_params, false),
error_occurred_(false),
input_buffer_size_(input_params.frames_per_buffer()),
- output_buffer_size_(output_params.frames_per_buffer()) {
+ output_params_(output_params),
+ id_(g_next_stream_id++) {
RecordRebufferingStats(input_params, output_params);
}
@@ -449,11 +500,15 @@ int OnMoreDataConverter::OnMoreData(base::TimeDelta delay,
int /* prior_frames_skipped */,
AudioBus* dest) {
TRACE_EVENT2("audio", "OnMoreDataConverter::OnMoreData", "input buffer size",
- input_buffer_size_, "output buffer size", output_buffer_size_);
+ input_buffer_size_, "output buffer size",
+ output_params_.frames_per_buffer());
current_delay_ = delay;
current_delay_timestamp_ = delay_timestamp;
audio_converter_.Convert(dest);
+ if (debug_recording_callback_)
+ debug_recording_callback_.Run(id_, dest);
+
// Always return the full number of frames requested, ProvideInput()
// will pad with silence if it wasn't able to acquire enough data.
return dest->frames();
@@ -480,4 +535,11 @@ void OnMoreDataConverter::OnError(AudioOutputStream* stream) {
source_callback_->OnError(stream);
}
+void OnMoreDataConverter::SetDebugRecordingCallback(
+ const AudioOutputResampler::DebugRecordingCallback&
+ debug_recording_callback) {
+ CHECK(!source_callback_);
+ debug_recording_callback_ = debug_recording_callback;
+}
+
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698