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

Unified Diff: media/audio/mac/audio_manager_mac.h

Issue 1973503003: (Relanding) Restores larger output buffer size when output stream requiring smaller size is closed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improved comments Created 4 years, 7 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/mac/audio_manager_mac.h
diff --git a/media/audio/mac/audio_manager_mac.h b/media/audio/mac/audio_manager_mac.h
index f5159e956cc44a249af38a698cf4e3399969f6b5..123d33782e2806b20e6f31616e9f306086f9a3ae 100644
--- a/media/audio/mac/audio_manager_mac.h
+++ b/media/audio/mac/audio_manager_mac.h
@@ -10,6 +10,7 @@
#include <stddef.h>
#include <list>
+#include <map>
#include <memory>
#include <string>
@@ -104,6 +105,12 @@ class MEDIA_EXPORT AudioManagerMac : public AudioManagerBase {
bool* size_was_changed,
size_t* io_buffer_frame_size);
+ // Called by AUHALStream::Close() before releasing the stream.
+ // This method is a special contract between the real stream and the audio
+ // manager and it ensures that we only try to increase the IO buffer size
+ // for real streams and not for fake or mocked streams.
+ void PrepareForAttemptToIncreaseIOBufferSize(AudioDeviceID device_id);
+
// Number of constructed output and input streams.
size_t output_streams() const { return output_streams_.size(); }
size_t low_latency_input_streams() const {
@@ -127,6 +134,24 @@ class MEDIA_EXPORT AudioManagerMac : public AudioManagerBase {
// sample rate has changed, otherwise does nothing.
void HandleDeviceChanges();
+ // Returns true if any active input stream is using the specified |device_id|.
+ bool AudioDeviceIsUsedForInput(AudioDeviceID device_id);
+
+ // This method is called when an output stream has been released and it takes
+ // the given |device_id| and scans all active output streams that are
+ // using this id. The goal is to find a new (larger) I/O buffer size which
+ // can be applied to all active output streams since doing so will save
+ // system resources.
+ // Note that, it is only called if no input stream is also using the device.
+ // Example: two active output streams where #1 wants 1024 as buffer size but
+ // is using 256 since stream #2 wants it. Now, if stream #2 is closed down,
+ // the native I/O buffer size will be increased to 1024 instead of 256.
+ // Returns true if it was possible to increase the I/O buffer size and
+ // false otherwise.
+ // TODO(henrika): possibly extend the scheme to also take input streams into
+ // account.
+ bool IncreaseIOBufferSizeIfPossible(AudioDeviceID device_id);
+
std::unique_ptr<AudioDeviceListenerMac> output_device_listener_;
// Track the output sample-rate and the default output device
@@ -149,6 +174,20 @@ class MEDIA_EXPORT AudioManagerMac : public AudioManagerBase {
std::list<AUAudioInputStream*> low_latency_input_streams_;
std::list<AUHALStream*> output_streams_;
+ // Maps device IDs and their corresponding actual (I/O) buffer sizes for
+ // all output streams using the specific device.
+ std::map<AudioDeviceID, size_t> output_io_buffer_size_map_;
+
+ // Device ID set bu the PrepareForAttemptToIncreaseIOBufferSize() method.
+ // Only modified by real audio output stream implementations, i.e., not
+ // fake audio output streams.
+ AudioDeviceID device_id_used_by_closing_output_stream_;
+
+ // Set to true in PrepareForAttemptToIncreaseIOBufferSize() to prepare for
+ // a possible modification of the native I/O buffer size. Set to false after
+ // an attempt to increase the I/O buffer size has finalized.
+ bool try_to_increase_io_buffer_size_;
+
DISALLOW_COPY_AND_ASSIGN(AudioManagerMac);
};

Powered by Google App Engine
This is Rietveld 408576698