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 // Suitable for tracking the number of active streams. | |
o1ka
2016/11/22 13:24:03
This comment is not clear. Just explain when it is
Max Morin
2016/11/22 16:04:29
Done.
| |
31 virtual void OnStreamStateChanged(bool playing) = 0; | |
32 // Called when construction is finished and the stream is ready for | |
o1ka
2016/11/22 13:24:03
nit: everywhere: add a blank line between a method
Max Morin
2016/11/22 16:04:29
Done.
| |
33 // playout. | |
34 virtual void OnStreamCreated(int stream_id, | |
35 base::SharedMemory* shared_memory, | |
36 base::CancelableSyncSocket* socket) = 0; | |
37 // Called if stream encounters an error and has become unusable. | |
38 virtual void OnStreamError(int stream_id) = 0; | |
39 }; | |
40 | |
41 struct Deleter { | |
42 void operator()(AudioOutputDelegate* delegate); | |
43 }; | |
44 | |
45 using UniquePtr = std::unique_ptr<AudioOutputDelegate, Deleter>; | |
46 | |
47 // |handler| must be valid until the moment that the UniquePtr destructor | |
48 // finishes. | |
49 static UniquePtr Create(EventHandler* handler, | |
50 media::AudioManager* audio_manager, | |
51 std::unique_ptr<media::AudioLog> audio_log, | |
52 AudioMirroringManager* mirroring_manager, | |
53 MediaObserver* media_observer, | |
54 int stream_id, | |
55 int render_frame_id, | |
56 int render_process_id, | |
57 const media::AudioParameters& params, | |
58 const std::string& output_device_id); | |
59 ~AudioOutputDelegate() override; | |
60 | |
61 // TODO(maxmorin): Remove this when crbug.com/647185 is closed. | |
62 // This function is used to provide control of the audio stream to | |
o1ka
2016/11/22 13:24:03
I'm not sure if this is true. As far as I remember
Max Morin
2016/11/22 16:04:29
See https://cs.chromium.org/chromium/src/chrome/br
o1ka
2016/11/22 21:48:16
Acknowledged.
| |
63 // WebrtcAudioPrivateGetActiveSinkFunction and others in the webrtc extension | |
64 // API. Since the controller is shared, this means that it might outlive the | |
65 // AudioOutputDelegate. In this case, it is still safe to call functions on | |
66 // the controller, but it will not do anything. The controller is also shared | |
67 // with AudioStreamMonitor. | |
68 const scoped_refptr<media::AudioOutputController>& controller() const { | |
69 return controller_; | |
70 } | |
71 | |
72 int stream_id() const { return stream_id_; } | |
73 | |
74 // Stream control: | |
75 void OnPlayStream(); | |
76 void OnPauseStream(); | |
77 void OnSetVolume(double volume); | |
78 | |
79 private: | |
80 AudioOutputDelegate(EventHandler* handler, | |
81 media::AudioManager* audio_manager, | |
82 std::unique_ptr<media::AudioLog> audio_log, | |
83 AudioMirroringManager* mirroring_manager, | |
84 MediaObserver* media_observer, | |
85 int stream_id, | |
86 int render_frame_id, | |
87 int render_process_id, | |
88 const media::AudioParameters& params, | |
89 const std::string& output_device_id); | |
90 | |
91 // AudioOutputController::EventHandler implementation. | |
92 void OnControllerCreated() override; | |
93 void OnControllerPlaying() override; | |
94 void OnControllerPaused() override; | |
95 void OnControllerError() override; | |
96 | |
97 void UpdatePlayingState(bool playing); | |
98 | |
99 // |handler_| is null if we are in the process of destruction. In this | |
100 // case, we will not run any scheduled operations. | |
o1ka
2016/11/22 13:24:03
Comment is not quite clear: scheduled where/for wh
Max Morin
2016/11/22 16:04:29
Done.
| |
101 EventHandler* handler_; | |
102 std::unique_ptr<media::AudioLog> const audio_log_; | |
103 AudioMirroringManager* const mirroring_manager_; | |
104 std::unique_ptr<AudioSyncReader> reader_; | |
105 scoped_refptr<media::AudioOutputController> controller_; | |
106 const int stream_id_; | |
107 const int render_frame_id_; | |
108 const int render_process_id_; | |
109 // This flag ensures that we only send OnStreamStateChanged notifications | |
o1ka
2016/11/22 13:24:03
not: add an empty line before (and in other simila
Max Morin
2016/11/22 16:04:29
Done.
| |
110 // and (de)register with the stream monitor when the state actually changes. | |
111 bool playing_ = false; | |
112 base::WeakPtrFactory<AudioOutputDelegate> weak_factory_; | |
113 | |
114 DISALLOW_COPY_AND_ASSIGN(AudioOutputDelegate); | |
115 }; | |
116 } // namespace content | |
117 | |
118 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_ | |
OLD | NEW |