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 class Deleter { | |
o1ka
2016/10/27 09:52:38
nit: can be a struct
Max Morin
2016/10/27 15:04:38
Done.
| |
41 public: | |
42 void operator()(AudioOutputDelegate* delegate); | |
43 }; | |
44 | |
45 using UniquePtr = std::unique_ptr<AudioOutputDelegate, Deleter>; | |
46 | |
47 static UniquePtr Create(EventHandler* handler, | |
48 std::unique_ptr<media::AudioLog> audio_log, | |
49 AudioMirroringManager* mirroring_manager, | |
50 MediaObserver* media_observer, | |
51 int stream_id, | |
52 int render_frame_id, | |
53 int render_process_id, | |
54 media::AudioParameters params, | |
55 const std::string& output_device_id); | |
56 ~AudioOutputDelegate() override; | |
57 | |
58 // TODO(maxmorin): Remove this when crbug.com/647185 is closed. | |
59 const scoped_refptr<media::AudioOutputController>& controller() const { | |
60 return controller_; | |
61 } | |
62 | |
63 int stream_id() const { return stream_id_; } | |
64 | |
65 // Stream control: | |
66 void OnPlayStream(); | |
67 void OnPauseStream(); | |
68 void OnSetVolume(double volume); | |
69 | |
70 private: | |
71 friend class Deleter; | |
72 | |
73 AudioOutputDelegate(EventHandler* handler, | |
74 std::unique_ptr<media::AudioLog> audio_log, | |
75 AudioMirroringManager* mirroring_manager, | |
76 MediaObserver* media_observer, | |
77 int stream_id, | |
78 int render_frame_id, | |
79 int render_process_id, | |
80 media::AudioParameters params, | |
81 const std::string& output_device_id); | |
82 // AudioOutputController::EventHandler implementation. | |
83 void OnControllerCreated() override; | |
84 void OnControllerPlaying() override; | |
85 void OnControllerPaused() override; | |
86 void OnControllerError() override; | |
87 | |
88 void UpdatePlayingStateForHandler(bool playing); | |
89 | |
90 EventHandler* handler_; | |
91 std::unique_ptr<media::AudioLog> const audio_log_; | |
92 AudioMirroringManager* const mirroring_manager_; | |
93 std::unique_ptr<AudioSyncReader> reader_; | |
94 scoped_refptr<media::AudioOutputController> controller_; | |
95 const int stream_id_; | |
96 const int render_frame_id_; | |
97 const int render_process_id_; | |
98 // This flag ensures that we only send OnStreamStateChanged notifications | |
99 // when the state actually changes. | |
100 bool playing_ = false; | |
101 base::WeakPtrFactory<AudioOutputDelegate> weak_factory_; | |
102 | |
103 DISALLOW_COPY_AND_ASSIGN(AudioOutputDelegate); | |
104 }; | |
105 } // namespace content | |
106 | |
107 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_ | |
OLD | NEW |