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

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

Issue 2443573003: Factor out AudioOutputDelegate from AudioRendererHost. (Closed)
Patch Set: Rebase. Comments. Created 4 years, 1 month 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_output_delegate.h
diff --git a/content/browser/renderer_host/media/audio_output_delegate.h b/content/browser/renderer_host/media/audio_output_delegate.h
new file mode 100644
index 0000000000000000000000000000000000000000..71ff2581a5d36a891aa5345755d88abe54f84477
--- /dev/null
+++ b/content/browser/renderer_host/media/audio_output_delegate.h
@@ -0,0 +1,118 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_
+#define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_
+
+#include <memory>
+#include <string>
+
+#include "base/macros.h"
+#include "base/memory/shared_memory.h"
+#include "base/memory/weak_ptr.h"
+#include "base/sync_socket.h"
+#include "content/browser/media/capture/audio_mirroring_manager.h"
+#include "content/browser/renderer_host/media/audio_sync_reader.h"
+#include "content/public/browser/media_observer.h"
+#include "media/audio/audio_logging.h"
+#include "media/audio/audio_output_controller.h"
+#include "media/base/audio_parameters.h"
+
+namespace content {
+
+// This class is operated on the IO thread.
+class CONTENT_EXPORT AudioOutputDelegate
+ : private media::AudioOutputController::EventHandler {
+ public:
+ class EventHandler {
+ public:
+ // Suitable for tracking the number of active streams.
o1ka 2016/11/22 13:24:03 This comment is not clear. Just explain when it is
Max Morin 2016/11/22 16:04:29 Done.
+ virtual void OnStreamStateChanged(bool playing) = 0;
+ // Called when construction is finished and the stream is ready for
o1ka 2016/11/22 13:24:03 nit: everywhere: add a blank line between a method
Max Morin 2016/11/22 16:04:29 Done.
+ // playout.
+ virtual void OnStreamCreated(int stream_id,
+ base::SharedMemory* shared_memory,
+ base::CancelableSyncSocket* socket) = 0;
+ // Called if stream encounters an error and has become unusable.
+ virtual void OnStreamError(int stream_id) = 0;
+ };
+
+ struct Deleter {
+ void operator()(AudioOutputDelegate* delegate);
+ };
+
+ using UniquePtr = std::unique_ptr<AudioOutputDelegate, Deleter>;
+
+ // |handler| must be valid until the moment that the UniquePtr destructor
+ // finishes.
+ static UniquePtr Create(EventHandler* handler,
+ media::AudioManager* audio_manager,
+ std::unique_ptr<media::AudioLog> audio_log,
+ AudioMirroringManager* mirroring_manager,
+ MediaObserver* media_observer,
+ int stream_id,
+ int render_frame_id,
+ int render_process_id,
+ const media::AudioParameters& params,
+ const std::string& output_device_id);
+ ~AudioOutputDelegate() override;
+
+ // TODO(maxmorin): Remove this when crbug.com/647185 is closed.
+ // This function is used to provide control of the audio stream to
o1ka 2016/11/22 13:24:03 I'm not sure if this is true. As far as I remember
Max Morin 2016/11/22 16:04:29 See https://cs.chromium.org/chromium/src/chrome/br
o1ka 2016/11/22 21:48:16 Acknowledged.
+ // WebrtcAudioPrivateGetActiveSinkFunction and others in the webrtc extension
+ // API. Since the controller is shared, this means that it might outlive the
+ // AudioOutputDelegate. In this case, it is still safe to call functions on
+ // the controller, but it will not do anything. The controller is also shared
+ // with AudioStreamMonitor.
+ const scoped_refptr<media::AudioOutputController>& controller() const {
+ return controller_;
+ }
+
+ int stream_id() const { return stream_id_; }
+
+ // Stream control:
+ void OnPlayStream();
+ void OnPauseStream();
+ void OnSetVolume(double volume);
+
+ private:
+ AudioOutputDelegate(EventHandler* handler,
+ media::AudioManager* audio_manager,
+ std::unique_ptr<media::AudioLog> audio_log,
+ AudioMirroringManager* mirroring_manager,
+ MediaObserver* media_observer,
+ int stream_id,
+ int render_frame_id,
+ int render_process_id,
+ const media::AudioParameters& params,
+ const std::string& output_device_id);
+
+ // AudioOutputController::EventHandler implementation.
+ void OnControllerCreated() override;
+ void OnControllerPlaying() override;
+ void OnControllerPaused() override;
+ void OnControllerError() override;
+
+ void UpdatePlayingState(bool playing);
+
+ // |handler_| is null if we are in the process of destruction. In this
+ // case, we will not run any scheduled operations.
o1ka 2016/11/22 13:24:03 Comment is not quite clear: scheduled where/for wh
Max Morin 2016/11/22 16:04:29 Done.
+ EventHandler* handler_;
+ std::unique_ptr<media::AudioLog> const audio_log_;
+ AudioMirroringManager* const mirroring_manager_;
+ std::unique_ptr<AudioSyncReader> reader_;
+ scoped_refptr<media::AudioOutputController> controller_;
+ const int stream_id_;
+ const int render_frame_id_;
+ const int render_process_id_;
+ // This flag ensures that we only send OnStreamStateChanged notifications
o1ka 2016/11/22 13:24:03 not: add an empty line before (and in other simila
Max Morin 2016/11/22 16:04:29 Done.
+ // and (de)register with the stream monitor when the state actually changes.
+ bool playing_ = false;
+ base::WeakPtrFactory<AudioOutputDelegate> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(AudioOutputDelegate);
+};
+} // namespace content
+
+#endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_

Powered by Google App Engine
This is Rietveld 408576698