Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Side by Side Diff: content/browser/renderer_host/media/audio_output_delegate.h

Issue 2578983003: Add AudioStreamRegistry. Move stream counting logic (Closed)
Patch Set: Add missing EXPECT_TRUE. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "content/browser/renderer_host/media/audio_stream_registry.h"
13 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
14 #include "media/audio/audio_output_controller.h" 15 #include "media/audio/audio_output_controller.h"
15 16
16 namespace base { 17 namespace base {
17 class SharedMemory; 18 class SharedMemory;
18 class CancelableSyncSocket; 19 class CancelableSyncSocket;
19 } 20 }
20 21
21 namespace content { 22 namespace content {
22 class AudioMirroringManager; 23 class AudioMirroringManager;
23 class AudioSyncReader; 24 class AudioSyncReader;
24 class MediaObserver; 25 class MediaObserver;
25 } 26 }
26 27
27 namespace media { 28 namespace media {
28 class AudioLog; 29 class AudioLog;
29 class AudioParameters; 30 class AudioParameters;
30 } 31 }
31 32
32 namespace content { 33 namespace content {
33 34
34 // This class, except for the AudioOutputDelegate::EventHandler implementation, 35 // This class, except for the AudioOutputDelegate::EventHandler implementation,
35 // is operated on the IO thread. 36 // is operated on the IO thread.
36 class CONTENT_EXPORT AudioOutputDelegate 37 class CONTENT_EXPORT AudioOutputDelegate
37 : public media::AudioOutputController::EventHandler { 38 : public media::AudioOutputController::EventHandler,
39 public AudioStreamRegistry::Stream {
38 public: 40 public:
39 class CONTENT_EXPORT EventHandler { 41 class CONTENT_EXPORT EventHandler {
40 public: 42 public:
41 virtual ~EventHandler() {} 43 virtual ~EventHandler() {}
42 44
43 // All these methods are called on the IO thread. 45 // All these methods are called on the IO thread.
44 46
45 // Called when the state changes between playing and not playing.
46 virtual void OnStreamStateChanged(bool playing) = 0;
47
48 // Called when construction is finished and the stream is ready for 47 // Called when construction is finished and the stream is ready for
49 // playout. 48 // playout.
50 virtual void OnStreamCreated(int stream_id, 49 virtual void OnStreamCreated(int stream_id,
51 base::SharedMemory* shared_memory, 50 base::SharedMemory* shared_memory,
52 base::CancelableSyncSocket* socket) = 0; 51 base::CancelableSyncSocket* socket) = 0;
53 52
54 // Called if stream encounters an error and has become unusable. 53 // Called if stream encounters an error and has become unusable.
55 virtual void OnStreamError(int stream_id) = 0; 54 virtual void OnStreamError(int stream_id) = 0;
56 }; 55 };
57 56
58 class CONTENT_EXPORT Deleter { 57 class CONTENT_EXPORT Deleter {
59 public: 58 public:
60 Deleter() = default; 59 Deleter() = default;
61 explicit Deleter(AudioMirroringManager* mirroring_manager) 60 explicit Deleter(AudioMirroringManager* mirroring_manager)
62 : mirroring_manager_(mirroring_manager) {} 61 : mirroring_manager_(mirroring_manager) {}
63 void operator()(AudioOutputDelegate* delegate); 62 void operator()(AudioOutputDelegate* delegate);
64 63
65 private: 64 private:
66 AudioMirroringManager* mirroring_manager_; 65 AudioMirroringManager* mirroring_manager_;
67 }; 66 };
68 67
69 using UniquePtr = std::unique_ptr<AudioOutputDelegate, Deleter>; 68 using UniquePtr = std::unique_ptr<AudioOutputDelegate, Deleter>;
70 69
71 // The AudioOutputDelegate might issue callbacks until the UniquePtr 70 // The AudioOutputDelegate might issue callbacks until the UniquePtr
72 // destructor finishes, so calling |handler| must be valid until then. 71 // destructor finishes, so calling |handler| must be valid until then.
73 static UniquePtr Create(EventHandler* handler, 72 static UniquePtr Create(EventHandler* handler,
73 AudioStreamRegistry* stream_registry,
74 media::AudioManager* audio_manager, 74 media::AudioManager* audio_manager,
75 std::unique_ptr<media::AudioLog> audio_log, 75 std::unique_ptr<media::AudioLog> audio_log,
76 AudioMirroringManager* mirroring_manager, 76 AudioMirroringManager* mirroring_manager,
77 MediaObserver* media_observer, 77 MediaObserver* media_observer,
78 int stream_id, 78 int stream_id,
79 int render_frame_id, 79 int render_frame_id,
80 int render_process_id, 80 int render_process_id,
81 const media::AudioParameters& params, 81 const media::AudioParameters& params,
82 const std::string& output_device_id); 82 const std::string& output_device_id);
83
83 ~AudioOutputDelegate() override; 84 ~AudioOutputDelegate() override;
84 85
85 // TODO(maxmorin): Remove this when crbug.com/647185 is closed. 86 // TODO(maxmorin): Remove this when crbug.com/647185 is closed.
86 // This function is used to provide control of the audio stream to 87 // This function is used to provide control of the audio stream to
87 // WebrtcAudioPrivateGetActiveSinkFunction and others in the webrtc extension 88 // WebrtcAudioPrivateGetActiveSinkFunction and others in the webrtc extension
88 // API. Since the controller is shared, this means that it might outlive the 89 // API. Since the controller is shared, this means that it might outlive the
89 // AudioOutputDelegate. In this case, it is still safe to call functions on 90 // AudioOutputDelegate. In this case, it is still safe to call functions on
90 // the controller, but it will not do anything. The controller is also shared 91 // the controller, but it will not do anything. The controller is also shared
91 // with AudioStreamMonitor. 92 // with AudioStreamMonitor.
92 scoped_refptr<media::AudioOutputController> controller() const { 93 scoped_refptr<media::AudioOutputController> controller() const {
93 return controller_; 94 return controller_;
94 } 95 }
95 96
96 int stream_id() const { return stream_id_; } 97 int stream_id() const { return stream_id_; }
97 98
99 #if BUILDFLAG(ENABLE_WEBRTC)
100 void EnableDebugRecording(const base::FilePath& base_file_name) override;
o1ka 2016/12/22 10:46:51 Oh, I just realized. AusioStreamRegistry will live
Max Morin 2017/01/09 15:34:23 I think AudioStreamRegistry will live in the brows
o1ka 2017/01/10 11:47:40 Ah ok, sounds good. Stream interfaces need to be f
101 void DisableDebugRecording() override;
102 #endif // BUILDFLAG(ENABLE_WEBRTC)
103
98 // Stream control: 104 // Stream control:
99 void OnPlayStream(); 105 void OnPlayStream();
100 void OnPauseStream(); 106 void OnPauseStream();
101 void OnSetVolume(double volume); 107 void OnSetVolume(double volume);
102 108
103 // AudioOutputController::EventHandler implementation. These methods may 109 // AudioOutputController::EventHandler implementation. These methods may
104 // be called on any thead. 110 // be called on any thead.
105 void OnControllerCreated() override; 111 void OnControllerCreated() override;
106 void OnControllerPlaying() override; 112 void OnControllerPlaying() override;
107 void OnControllerPaused() override; 113 void OnControllerPaused() override;
108 void OnControllerError() override; 114 void OnControllerError() override;
109 115
110 private: 116 private:
111 AudioOutputDelegate(EventHandler* handler, 117 AudioOutputDelegate(EventHandler* handler,
118 AudioStreamRegistry* stream_registry,
112 media::AudioManager* audio_manager, 119 media::AudioManager* audio_manager,
113 std::unique_ptr<media::AudioLog> audio_log, 120 std::unique_ptr<media::AudioLog> audio_log,
114 int stream_id, 121 int stream_id,
115 int render_frame_id, 122 int render_frame_id,
116 int render_process_id, 123 int render_process_id,
117 const media::AudioParameters& params, 124 const media::AudioParameters& params,
118 const std::string& output_device_id); 125 const std::string& output_device_id);
119 126
120 void SendCreatedNotification(); 127 void SendCreatedNotification();
121 void OnError(); 128 void OnError();
122 void UpdatePlayingState(bool playing); 129 void UpdatePlayingState(bool playing);
123 130
124 // |handler_| is null if we are in the process of destruction. In this case, 131 // |handler_| is null if we are in the process of destruction. In this case,
125 // we will ignore events from |controller_|. 132 // we will ignore events from |controller_|.
126 EventHandler* handler_; 133 EventHandler* handler_;
134 AudioStreamRegistry* const stream_registry_;
127 std::unique_ptr<media::AudioLog> const audio_log_; 135 std::unique_ptr<media::AudioLog> const audio_log_;
128 std::unique_ptr<AudioSyncReader> reader_; 136 std::unique_ptr<AudioSyncReader> reader_;
129 scoped_refptr<media::AudioOutputController> controller_; 137 scoped_refptr<media::AudioOutputController> controller_;
130 const int stream_id_; 138 const int stream_id_;
131 const int render_frame_id_; 139 const int render_frame_id_;
132 const int render_process_id_; 140 const int render_process_id_;
133 141
134 // This flag ensures that we only send OnStreamStateChanged notifications 142 // This flag ensures that we only send OnStreamStateChanged notifications
135 // and (de)register with the stream monitor when the state actually changes. 143 // and (de)register with the stream monitor when the state actually changes.
136 bool playing_ = false; 144 bool playing_ = false;
137 base::WeakPtr<AudioOutputDelegate> weak_this_; 145 base::WeakPtr<AudioOutputDelegate> weak_this_;
138 base::WeakPtrFactory<AudioOutputDelegate> weak_factory_; 146 base::WeakPtrFactory<AudioOutputDelegate> weak_factory_;
139 147
140 DISALLOW_COPY_AND_ASSIGN(AudioOutputDelegate); 148 DISALLOW_COPY_AND_ASSIGN(AudioOutputDelegate);
141 }; 149 };
142 150
143 } // namespace content 151 } // namespace content
144 152
145 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_ 153 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698