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

Unified Diff: content/browser/renderer_host/media/audio_renderer_host.h

Issue 2443573003: Factor out AudioOutputDelegate from AudioRendererHost. (Closed)
Patch Set: Add AudioOutputDelegate::Deleter. Created 4 years, 2 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: content/browser/renderer_host/media/audio_renderer_host.h
diff --git a/content/browser/renderer_host/media/audio_renderer_host.h b/content/browser/renderer_host/media/audio_renderer_host.h
index afdb31b2b2ab6889a8200f562b056271e6af7ad3..18660fac967069b046e8f2434b3da2478743e6db 100644
--- a/content/browser/renderer_host/media/audio_renderer_host.h
+++ b/content/browser/renderer_host/media/audio_renderer_host.h
@@ -46,14 +46,18 @@
#include <memory>
#include <string>
#include <utility>
+#include <vector>
#include "base/atomic_ref_count.h"
#include "base/gtest_prod_util.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/shared_memory.h"
#include "base/process/process.h"
#include "base/sequenced_task_runner_helpers.h"
+#include "base/sync_socket.h"
+#include "content/browser/renderer_host/media/audio_output_delegate.h"
#include "content/browser/renderer_host/media/media_devices_manager.h"
#include "content/common/content_export.h"
#include "content/public/browser/browser_message_filter.h"
@@ -74,18 +78,19 @@ class AudioParameters;
namespace content {
class AudioMirroringManager;
-class MediaInternals;
class MediaStreamManager;
class MediaStreamUIProxy;
class ResourceContext;
-class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter {
+class CONTENT_EXPORT AudioRendererHost
+ : public BrowserMessageFilter,
+ private AudioOutputDelegate::EventHandler {
public:
// Called from UI thread from the owner of this object.
AudioRendererHost(int render_process_id,
media::AudioManager* audio_manager,
AudioMirroringManager* mirroring_manager,
- MediaInternals* media_internals,
+ media::AudioLogFactory* log_factory,
MediaStreamManager* media_stream_manager,
const std::string& salt);
@@ -112,13 +117,12 @@ class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter {
FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream);
FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation);
- class AudioEntry;
- typedef std::map<int, AudioEntry*> AudioEntryMap;
-
// Internal callback type for access requests to output devices.
// |have_access| is true only if there is permission to access the device.
typedef base::Callback<void(bool have_access)> OutputDeviceAccessCB;
+ using AudioOutputDelegateList = std::vector<AudioOutputDelegate::UniquePtr>;
+
// The type of a function that is run on the UI thread to check whether the
// routing IDs reference a valid RenderFrameHost. The function then runs
// |callback| on the IO thread with true/false if valid/invalid.
@@ -129,6 +133,13 @@ class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter {
~AudioRendererHost() override;
+ // AudioOutputDelegate::EventHandler implementation
+ void OnStreamCreated(int stream_id,
+ base::SharedMemory* shared_memory,
+ base::CancelableSyncSocket* foreign_socket) override;
+ void OnStreamError(int stream_id) override;
+ void OnStreamStateChanged(bool is_playing) override;
+
// Methods called on IO thread ----------------------------------------------
// Audio related IPC message handlers.
@@ -168,13 +179,8 @@ class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter {
// Helper methods.
- // Complete the process of creating an audio stream. This will set up the
- // shared memory or shared socket in low latency mode and send the
- // NotifyStreamCreated message to the peer.
- void DoCompleteCreation(int stream_id);
-
// Called after the |render_frame_id| provided to OnCreateStream() was
- // validated. When |is_valid| is false, this calls ReportErrorAndClose().
+ // validated. When |is_valid| is false, this calls OnStreamError().
void DidValidateRenderFrame(int stream_id, bool is_valid);
// Updates status of stream for AudioStreamMonitor and updates
@@ -186,20 +192,11 @@ class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter {
// Send an error message to the renderer.
void SendErrorMessage(int stream_id);
- // Delete an audio entry, notifying observers first. This is called by
- // AudioOutputController after it has closed.
- void DeleteEntry(std::unique_ptr<AudioEntry> entry);
-
- // Send an error message to the renderer, then close the stream.
- void ReportErrorAndClose(int stream_id);
-
- // A helper method to look up a AudioEntry identified by |stream_id|.
- // Returns NULL if not found.
- AudioEntry* LookupById(int stream_id);
-
- // A helper method to update the number of playing streams and alert the
- // ResourceScheduler when the renderer starts or stops playing an audiostream.
- void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing);
+ // Helper methods to look up a AudioOutputDelegate identified by |stream_id|.
+ // Returns delegates_.end() if not found.
+ AudioOutputDelegateList::iterator LookupIteratorById(int stream_id);
+ // Returns nullptr if not found.
+ AudioOutputDelegate* LookupById(int stream_id);
// Check if the renderer process has access to the requested output device.
void CheckOutputDeviceAccess(int render_frame_id,
@@ -251,13 +248,14 @@ class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter {
media::AudioManager* const audio_manager_;
AudioMirroringManager* const mirroring_manager_;
+ media::AudioLogFactory* log_factory_;
std::unique_ptr<media::AudioLog> audio_log_;
// Used to access to AudioInputDeviceManager.
MediaStreamManager* media_stream_manager_;
- // A map of stream IDs to audio sources.
- AudioEntryMap audio_entries_;
+ // A list of the current open streams.
+ AudioOutputDelegateList delegates_;
// The number of streams in the playing state. Atomic read safe from any
// thread, but should only be updated from the IO thread.

Powered by Google App Engine
This is Rietveld 408576698