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" | |
| 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 { | |
| 27 public: | |
| 28 class EventHandler { | |
| 29 public: | |
| 30 // Only called when playing-state changes. At any one point, there will at | |
| 31 // 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.
| |
| 32 // 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.
| |
| 33 // and "not playing" calls. | |
| 34 virtual void OnStreamStateChanged(bool playing) = 0; | |
| 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 // Called if stream encounters an error and has become unusable. | |
| 41 virtual void OnStreamError(int stream_id) = 0; | |
| 42 }; | |
| 43 | |
| 44 struct Deleter { | |
| 45 void operator()(AudioOutputDelegate* delegate); | |
| 46 }; | |
| 47 | |
| 48 using UniquePtr = std::unique_ptr<AudioOutputDelegate, Deleter>; | |
| 49 | |
| 50 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.
| |
| 51 media::AudioManager* audio_manager, | |
| 52 std::unique_ptr<media::AudioLog> audio_log, | |
| 53 AudioMirroringManager* mirroring_manager, | |
| 54 MediaObserver* media_observer, | |
| 55 int stream_id, | |
| 56 int render_frame_id, | |
| 57 int render_process_id, | |
| 58 media::AudioParameters params, | |
| 59 const std::string& output_device_id); | |
| 60 ~AudioOutputDelegate() override; | |
| 61 | |
| 62 // TODO(maxmorin): Remove this when crbug.com/647185 is closed. | |
| 63 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.
| |
| 64 return controller_; | |
| 65 } | |
| 66 | |
| 67 int stream_id() const { return stream_id_; } | |
| 68 | |
| 69 // Stream control: | |
| 70 void OnPlayStream(); | |
| 71 void OnPauseStream(); | |
| 72 void OnSetVolume(double volume); | |
| 73 | |
| 74 private: | |
| 75 AudioOutputDelegate(EventHandler* handler, | |
| 76 media::AudioManager* audio_manager, | |
| 77 std::unique_ptr<media::AudioLog> audio_log, | |
| 78 AudioMirroringManager* mirroring_manager, | |
| 79 MediaObserver* media_observer, | |
| 80 int stream_id, | |
| 81 int render_frame_id, | |
| 82 int render_process_id, | |
| 83 media::AudioParameters params, | |
| 84 const std::string& output_device_id); | |
| 85 // AudioOutputController::EventHandler implementation. | |
|
o1ka
2016/11/03 13:39:12
nit: empty line before
Max Morin
2016/11/18 16:03:42
Done.
| |
| 86 void OnControllerCreated() override; | |
| 87 void OnControllerPlaying() override; | |
| 88 void OnControllerPaused() override; | |
| 89 void OnControllerError() override; | |
| 90 | |
| 91 void UpdatePlayingStateForHandler(bool playing); | |
| 92 | |
| 93 // 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.
| |
| 94 // we will not run any scheduled operations. | |
| 95 EventHandler* handler_; | |
| 96 std::unique_ptr<media::AudioLog> const audio_log_; | |
| 97 AudioMirroringManager* const mirroring_manager_; | |
| 98 std::unique_ptr<AudioSyncReader> reader_; | |
| 99 scoped_refptr<media::AudioOutputController> controller_; | |
| 100 const int stream_id_; | |
| 101 const int render_frame_id_; | |
| 102 const int render_process_id_; | |
| 103 // This flag ensures that we only send OnStreamStateChanged notifications | |
| 104 // when the state actually changes. | |
| 105 bool playing_ = false; | |
| 106 base::WeakPtrFactory<AudioOutputDelegate> weak_factory_; | |
| 107 | |
| 108 DISALLOW_COPY_AND_ASSIGN(AudioOutputDelegate); | |
| 109 }; | |
| 110 } // namespace content | |
| 111 | |
| 112 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_ | |
| OLD | NEW |