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_IMPL_H_ | |
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_IMPL_H_ | |
7 | |
8 #include <memory> | |
9 #include <string> | |
10 | |
11 #include "base/single_thread_task_runner.h" | |
12 #include "content/browser/renderer_host/media/audio_sync_reader.h" | |
13 #include "content/common/content_export.h" | |
14 #include "media/audio/audio_output_controller.h" | |
15 #include "media/base/audio_parameters.h" | |
16 #include "media/mojo/interfaces/audio_output.mojom.h" | |
17 #include "mojo/public/cpp/bindings/binding.h" | |
18 | |
19 namespace content { | |
20 | |
21 class CONTENT_EXPORT AudioOutputImpl | |
22 : public media::mojom::AudioOutput, | |
23 public media::AudioOutputController::EventHandler { | |
24 public: | |
25 // Class containing the AudioOutputImpl. | |
26 class Host { | |
27 public: | |
28 // Called when the AudioOutputImpl has been successfully created. | |
29 virtual void NotifyStreamCreated(int32_t id, | |
30 media::AudioOutputController* controller, | |
31 int render_frame_id) = 0; | |
32 // Called on play or pause. | |
33 virtual void NotifyStreamStateChanged(int32_t id, bool is_playing) = 0; | |
34 // Called when the stream is finished and should be cleaned up. | |
35 // NotifySteamClosed is only called if NotifyStreamCreated was called. | |
36 virtual void NotifyStreamClosed(int32_t id) = 0; | |
37 virtual void Remove(int32_t id) = 0; | |
38 }; | |
39 | |
40 class Deleter { | |
41 public: | |
42 void operator()(AudioOutputImpl* output); | |
43 }; | |
44 | |
45 using UniquePtr = std::unique_ptr<AudioOutputImpl, Deleter>; | |
46 | |
47 ~AudioOutputImpl() override; | |
48 | |
49 // All methods of host must be safe to call from the thread of task_runner. | |
50 // The only safe way to delete this is by calling Close or when the | |
51 // controller calls OnError. Create, Bind, controller and Close are | |
52 // only safe to call from task_runner. | |
53 static UniquePtr Create(base::SingleThreadTaskRunner* task_runner, | |
54 Host* host, | |
55 int32_t id, | |
56 int render_frame_id, | |
57 int render_process_id, | |
58 const std::string& output_device_id); | |
59 | |
60 void Bind(media::mojom::AudioOutputRequest request); | |
61 scoped_refptr<media::AudioOutputController> controller() { | |
62 return controller_; | |
63 } | |
64 | |
65 // Close will call Host::Remove when done. | |
66 void Close(); | |
67 | |
68 // AudioOutput implementation. These methods should never be called without | |
69 // going through mojo. | |
70 void Start(const media::AudioParameters& params, | |
71 const StartCallback& callback) override; | |
72 void Play() override; | |
73 void Pause() override; | |
74 void SetVolume(double volume) override; | |
75 | |
76 // media::AudioOutputController::EventHandler implementation. | |
77 void OnCreated() override; | |
78 void OnPlaying() override; | |
79 void OnPaused() override; | |
80 void OnError() override; | |
81 | |
82 private: | |
83 AudioOutputImpl(base::SingleThreadTaskRunner* task_runner, | |
84 Host* host, | |
85 int32_t id, | |
86 int render_frame_id, | |
87 int render_process_id, | |
88 const std::string& output_device_id); | |
89 | |
90 void DoCompleteCreation(); | |
91 | |
92 void Init(const media::AudioParameters& params); | |
93 bool IsStarted() const; | |
94 | |
95 static void DeleteAndUnregister(AudioOutputImpl* output); | |
96 | |
97 base::SingleThreadTaskRunner* const task_runner_; | |
o1ka
2016/09/28 10:24:07
I guess we need scoped_refptr here, because we don
| |
98 | |
99 // host will be a valid pointer since it's the owner of | |
100 // this object. | |
101 Host* const host_; | |
o1ka
2016/09/28 10:24:07
const
| |
102 | |
103 const int32_t id_; | |
o1ka
2016/09/28 10:24:07
Why do we need id? I think id is a host-side prope
Max Morin
2016/09/28 12:47:33
Agree.
| |
104 const int render_frame_id_; | |
105 const int render_process_id_; | |
106 const std::string output_device_id_; | |
107 mojo::Binding<AudioOutput> binding_; | |
108 | |
109 std::unique_ptr<AudioSyncReader> reader_; | |
110 scoped_refptr<media::AudioOutputController> controller_; | |
o1ka
2016/09/28 10:24:07
Should it be scoped? If yes, we need a comment on
| |
111 | |
112 StartCallback start_callback_; | |
o1ka
2016/09/28 15:17:19
BTW it's "render" callback - the one which will be
Max Morin
2016/09/28 16:13:18
This is the callback for the response to the mojo
| |
113 | |
114 bool is_closing; | |
115 | |
116 DISALLOW_COPY_AND_ASSIGN(AudioOutputImpl); | |
117 }; | |
118 | |
119 } // namespace content | |
120 | |
121 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_IMPL_H_ | |
OLD | NEW |