Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_ | |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/shared_memory.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/sync_socket.h" | |
|
DaleCurtis
2016/11/29 20:31:23
Forward declare. This and almost all the others.
h
| |
| 15 #include "content/browser/media/capture/audio_mirroring_manager.h" | |
| 16 #include "content/browser/renderer_host/media/audio_sync_reader.h" | |
| 17 #include "content/public/browser/media_observer.h" | |
| 18 #include "media/audio/audio_logging.h" | |
| 19 #include "media/audio/audio_output_controller.h" | |
| 20 #include "media/base/audio_parameters.h" | |
| 21 | |
| 22 namespace content { | |
| 23 | |
| 24 // This class is operated on the IO thread. | |
| 25 class CONTENT_EXPORT AudioOutputDelegate | |
| 26 : private media::AudioOutputController::EventHandler { | |
|
DaleCurtis
2016/11/29 20:31:23
Google C++ only allows public inheritance:
https:/
| |
| 27 public: | |
| 28 class EventHandler { | |
|
DaleCurtis
2016/11/29 20:31:23
This must have a virtual destructor:
https://googl
| |
| 29 public: | |
| 30 // All these methods are called on the IO thread. | |
| 31 | |
| 32 // Called when the state changes between playing and not playing. | |
| 33 virtual void OnStreamStateChanged(bool playing) = 0; | |
| 34 | |
| 35 // Called when construction is finished and the stream is ready for | |
| 36 // playout. | |
| 37 virtual void OnStreamCreated(int stream_id, | |
| 38 base::SharedMemory* shared_memory, | |
| 39 base::CancelableSyncSocket* socket) = 0; | |
| 40 | |
| 41 // Called if stream encounters an error and has become unusable. | |
| 42 virtual void OnStreamError(int stream_id) = 0; | |
| 43 }; | |
| 44 | |
| 45 class Deleter { | |
| 46 public: | |
| 47 Deleter() = default; | |
| 48 explicit Deleter(AudioMirroringManager* mirroring_manager) | |
| 49 : mirroring_manager_(mirroring_manager) {} | |
| 50 void operator()(AudioOutputDelegate* delegate); | |
| 51 | |
| 52 private: | |
| 53 AudioMirroringManager* mirroring_manager_; | |
| 54 }; | |
| 55 | |
| 56 using UniquePtr = std::unique_ptr<AudioOutputDelegate, Deleter>; | |
|
DaleCurtis
2016/11/29 20:31:23
Needs a more "unique" name, though since this is o
Max Morin
2016/12/01 16:08:37
How about AudioOutputDelegate::ScopedPointer, simi
DaleCurtis
2016/12/01 19:33:06
Hmm, Scoped shouldn't be used anymore for this. I
| |
| 57 | |
| 58 // |handler| must be valid until the moment that the UniquePtr destructor | |
|
DaleCurtis
2016/11/29 20:31:23
Needs more comments.
| |
| 59 // finishes. | |
| 60 static UniquePtr Create(EventHandler* handler, | |
|
DaleCurtis
2016/11/29 20:31:23
It's sad there are so many parameters here. I don'
| |
| 61 media::AudioManager* audio_manager, | |
| 62 std::unique_ptr<media::AudioLog> audio_log, | |
| 63 AudioMirroringManager* mirroring_manager, | |
| 64 MediaObserver* media_observer, | |
| 65 int stream_id, | |
| 66 int render_frame_id, | |
| 67 int render_process_id, | |
| 68 const media::AudioParameters& params, | |
| 69 const std::string& output_device_id); | |
| 70 ~AudioOutputDelegate() override; | |
| 71 | |
| 72 // TODO(maxmorin): Remove this when crbug.com/647185 is closed. | |
| 73 // This function is used to provide control of the audio stream to | |
| 74 // WebrtcAudioPrivateGetActiveSinkFunction and others in the webrtc extension | |
| 75 // API. Since the controller is shared, this means that it might outlive the | |
| 76 // AudioOutputDelegate. In this case, it is still safe to call functions on | |
| 77 // the controller, but it will not do anything. The controller is also shared | |
| 78 // with AudioStreamMonitor. | |
| 79 const scoped_refptr<media::AudioOutputController>& controller() const { | |
|
DaleCurtis
2016/11/29 20:31:23
Shouldn't this be returned by value? or a raw ptr
miu
2016/11/29 21:36:27
Hmm...I don't like the shared-ownership model here
Max Morin
2016/12/01 16:08:37
Right, no const and no & (not changing to raw poin
| |
| 80 return controller_; | |
| 81 } | |
| 82 | |
| 83 int stream_id() const { return stream_id_; } | |
| 84 | |
| 85 // Stream control: | |
| 86 void OnPlayStream(); | |
| 87 void OnPauseStream(); | |
| 88 void OnSetVolume(double volume); | |
| 89 | |
| 90 private: | |
| 91 AudioOutputDelegate(EventHandler* handler, | |
| 92 media::AudioManager* audio_manager, | |
| 93 std::unique_ptr<media::AudioLog> audio_log, | |
| 94 int stream_id, | |
| 95 int render_frame_id, | |
| 96 int render_process_id, | |
| 97 const media::AudioParameters& params, | |
| 98 const std::string& output_device_id); | |
| 99 | |
| 100 // AudioOutputController::EventHandler implementation. | |
| 101 void OnControllerCreated() override; | |
| 102 void OnControllerPlaying() override; | |
| 103 void OnControllerPaused() override; | |
| 104 void OnControllerError() override; | |
| 105 | |
| 106 void UpdatePlayingState(bool playing); | |
| 107 | |
| 108 // |handler_| is null if we are in the process of destruction. In this case, | |
| 109 // we will ignore events from |controller_|. | |
| 110 EventHandler* handler_; | |
| 111 std::unique_ptr<media::AudioLog> const audio_log_; | |
| 112 std::unique_ptr<AudioSyncReader> reader_; | |
| 113 scoped_refptr<media::AudioOutputController> controller_; | |
| 114 const int stream_id_; | |
| 115 const int render_frame_id_; | |
| 116 const int render_process_id_; | |
| 117 | |
| 118 // This flag ensures that we only send OnStreamStateChanged notifications | |
| 119 // and (de)register with the stream monitor when the state actually changes. | |
| 120 bool playing_ = false; | |
| 121 base::WeakPtrFactory<AudioOutputDelegate> weak_factory_; | |
| 122 | |
| 123 DISALLOW_COPY_AND_ASSIGN(AudioOutputDelegate); | |
| 124 }; | |
| 125 } // namespace content | |
|
DaleCurtis
2016/11/29 20:31:23
Add line above.
| |
| 126 | |
| 127 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_ | |
| OLD | NEW |