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 AudioOutputDelegate : private media::AudioOutputController::EventHandler { | |
| 26 public: | |
| 27 class EventHandler { | |
| 28 public: | |
| 29 // Only called when playing-state changes. | |
| 30 virtual void OnStreamStateChanged(bool playing) = 0; | |
| 31 // Called when construction is finished and the stream is ready for | |
| 32 // playout. | |
| 33 virtual void OnStreamCreated(int stream_id, | |
| 34 base::SharedMemory* shared_memory, | |
| 35 base::CancelableSyncSocket* socket) = 0; | |
| 36 // Called if stream encounters an error and has become unusable. | |
| 37 virtual void OnStreamError(int stream_id) = 0; | |
| 38 }; | |
| 39 | |
| 40 AudioOutputDelegate(EventHandler* handler, | |
| 41 std::unique_ptr<media::AudioLog> audio_log, | |
| 42 AudioMirroringManager* mirroring_manager, | |
| 43 MediaObserver* media_observer, | |
| 44 int stream_id, | |
| 45 int render_frame_id, | |
| 46 int render_process_id, | |
| 47 media::AudioParameters params, | |
| 48 const std::string& output_device_id); | |
| 49 ~AudioOutputDelegate() override; | |
| 50 | |
| 51 const scoped_refptr<media::AudioOutputController>& controller() const { | |
| 52 return controller_; | |
| 53 } | |
| 54 | |
| 55 int stream_id() const { return stream_id_; } | |
| 56 | |
| 57 // Stream control: | |
| 58 void OnPlayStream(); | |
| 59 void OnPauseStream(); | |
| 60 // The ownership of this object is passed into the method. | |
| 61 // It will delete itself when ready. After this has been called, | |
|
o1ka
2016/10/26 13:11:48
I would remove "when ready" sentence: it's a bit c
| |
| 62 // the AudioOutputDelegate will no longer call any methods on the event | |
| 63 // handler. | |
| 64 void OnCloseStream(std::unique_ptr<AudioOutputDelegate> owned_this); | |
|
o1ka
2016/10/26 13:11:48
Probably implement this as a deleter? It's deleter
| |
| 65 void OnSetVolume(double volume); | |
| 66 | |
| 67 private: | |
| 68 // AudioOutputController::EventHandler implementation. | |
| 69 void OnControllerCreated() override; | |
| 70 void OnControllerPlaying() override; | |
| 71 void OnControllerPaused() override; | |
| 72 void OnControllerError() override; | |
| 73 | |
| 74 void FinishClosing(); | |
|
o1ka
2016/10/26 13:11:48
I do not quite like this name, but I'm bad in nami
| |
| 75 void UpdatePlayingStateForHandler(bool playing); | |
| 76 | |
| 77 EventHandler* const handler_; | |
| 78 std::unique_ptr<media::AudioLog> const audio_log_; | |
| 79 AudioMirroringManager* const mirroring_manager_; | |
| 80 std::unique_ptr<AudioSyncReader> reader_; | |
| 81 scoped_refptr<media::AudioOutputController> controller_; | |
| 82 const int stream_id_; | |
| 83 const int render_frame_id_; | |
| 84 const int render_process_id_; | |
| 85 // This flag ensures that we only send OnStreamStateChanged notifications | |
| 86 // when the state actually changes. | |
| 87 bool playing_ = false; | |
| 88 // This flag ensures we don't send events to handler_ after OnStreamClosed. | |
| 89 bool closed_ = false; | |
|
o1ka
2016/10/26 13:11:48
Looks like there is no need for the flag: we can j
| |
| 90 base::WeakPtrFactory<AudioOutputDelegate> weak_factory_; | |
| 91 | |
| 92 DISALLOW_COPY_AND_ASSIGN(AudioOutputDelegate); | |
| 93 }; | |
| 94 } // namespace content | |
| 95 | |
| 96 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_ | |
| OLD | NEW |