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

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

Issue 2443573003: Factor out AudioOutputDelegate from AudioRendererHost. (Closed)
Patch Set: Remove [&] from lambda. 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..e66f418677daa42e5144db3783eab08916f9b031
--- /dev/null
+++ b/content/browser/renderer_host/media/audio_output_delegate.h
@@ -0,0 +1,112 @@
+// 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:
+ // Only called when playing-state changes. At any one point, there will at
+ // most have been one more "playing" call than "not playing" call, and in
o1ka 2016/11/03 13:39:12 A little hard to parse sentence. Can we simplify i
Max Morin 2016/11/18 16:03:42 Done.
+ // total (when destroyed) there will have been an equal number of "playing"
o1ka 2016/11/03 13:39:12 can we avoid future perfect? :) we have enough of
Max Morin 2016/11/18 16:03:42 Done.
+ // and "not playing" calls.
+ virtual void OnStreamStateChanged(bool playing) = 0;
+ // Called when construction is finished and the stream is ready for
+ // 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>;
+
+ static UniquePtr Create(EventHandler* handler,
o1ka 2016/11/03 13:39:12 Add a description of what the guarantee is for cal
Max Morin 2016/11/18 16:03:42 Done.
+ 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,
+ media::AudioParameters params,
+ const std::string& output_device_id);
+ ~AudioOutputDelegate() override;
+
+ // TODO(maxmorin): Remove this when crbug.com/647185 is closed.
+ const scoped_refptr<media::AudioOutputController>& controller() const {
o1ka 2016/11/03 13:39:12 Please add a comment on who uses it and what happe
Max Morin 2016/11/18 16:03:42 Done.
+ 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,
+ media::AudioParameters params,
+ const std::string& output_device_id);
+ // AudioOutputController::EventHandler implementation.
o1ka 2016/11/03 13:39:12 nit: empty line before
Max Morin 2016/11/18 16:03:42 Done.
+ void OnControllerCreated() override;
+ void OnControllerPlaying() override;
+ void OnControllerPaused() override;
+ void OnControllerError() override;
+
+ void UpdatePlayingStateForHandler(bool playing);
+
+ // handler_ will be null we are in the process of destruction. In this case,
o1ka 2016/11/03 13:39:12 nits: |handler_|; "if we are"
Max Morin 2016/11/18 16:03:42 Done.
+ // we will not run any scheduled operations.
+ 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
+ // 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