Chromium Code Reviews| Index: content/browser/renderer_host/media/audio_output_impl.h |
| diff --git a/content/browser/renderer_host/media/audio_output_impl.h b/content/browser/renderer_host/media/audio_output_impl.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3c4c6cf8ae21af33e73a9fa4e259b96e64b096a6 |
| --- /dev/null |
| +++ b/content/browser/renderer_host/media/audio_output_impl.h |
| @@ -0,0 +1,121 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_IMPL_H_ |
| +#define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_IMPL_H_ |
| + |
| +#include <memory> |
| +#include <string> |
| + |
| +#include "base/single_thread_task_runner.h" |
| +#include "content/browser/renderer_host/media/audio_sync_reader.h" |
| +#include "content/common/content_export.h" |
| +#include "media/audio/audio_output_controller.h" |
| +#include "media/base/audio_parameters.h" |
| +#include "media/mojo/interfaces/audio_output.mojom.h" |
| +#include "mojo/public/cpp/bindings/binding.h" |
| + |
| +namespace content { |
| + |
| +class CONTENT_EXPORT AudioOutputImpl |
| + : public media::mojom::AudioOutput, |
| + public media::AudioOutputController::EventHandler { |
| + public: |
| + // Class containing the AudioOutputImpl. |
| + class Host { |
| + public: |
| + // Called when the AudioOutputImpl has been successfully created. |
| + virtual void NotifyStreamCreated(int32_t id, |
| + media::AudioOutputController* controller, |
| + int render_frame_id) = 0; |
| + // Called on play or pause. |
| + virtual void NotifyStreamStateChanged(int32_t id, bool is_playing) = 0; |
| + // Called when the stream is finished and should be cleaned up. |
| + // NotifySteamClosed is only called if NotifyStreamCreated was called. |
| + virtual void NotifyStreamClosed(int32_t id) = 0; |
| + virtual void Remove(int32_t id) = 0; |
| + }; |
| + |
| + class Deleter { |
| + public: |
| + void operator()(AudioOutputImpl* output); |
| + }; |
| + |
| + using UniquePtr = std::unique_ptr<AudioOutputImpl, Deleter>; |
| + |
| + ~AudioOutputImpl() override; |
| + |
| + // All methods of host must be safe to call from the thread of task_runner. |
| + // The only safe way to delete this is by calling Close or when the |
| + // controller calls OnError. Create, Bind, controller and Close are |
| + // only safe to call from task_runner. |
| + static UniquePtr Create(base::SingleThreadTaskRunner* task_runner, |
| + Host* host, |
| + int32_t id, |
| + int render_frame_id, |
| + int render_process_id, |
| + const std::string& output_device_id); |
| + |
| + void Bind(media::mojom::AudioOutputRequest request); |
| + scoped_refptr<media::AudioOutputController> controller() { |
| + return controller_; |
| + } |
| + |
| + // Close will call Host::Remove when done. |
| + void Close(); |
| + |
| + // AudioOutput implementation. These methods should never be called without |
| + // going through mojo. |
| + void Start(const media::AudioParameters& params, |
| + const StartCallback& callback) override; |
| + void Play() override; |
| + void Pause() override; |
| + void SetVolume(double volume) override; |
| + |
| + // media::AudioOutputController::EventHandler implementation. |
| + void OnCreated() override; |
| + void OnPlaying() override; |
| + void OnPaused() override; |
| + void OnError() override; |
| + |
| + private: |
| + AudioOutputImpl(base::SingleThreadTaskRunner* task_runner, |
| + Host* host, |
| + int32_t id, |
| + int render_frame_id, |
| + int render_process_id, |
| + const std::string& output_device_id); |
| + |
| + void DoCompleteCreation(); |
| + |
| + void Init(const media::AudioParameters& params); |
| + bool IsStarted() const; |
| + |
| + static void DeleteAndUnregister(AudioOutputImpl* output); |
| + |
| + base::SingleThreadTaskRunner* const task_runner_; |
|
o1ka
2016/09/28 10:24:07
I guess we need scoped_refptr here, because we don
|
| + |
| + // host will be a valid pointer since it's the owner of |
| + // this object. |
| + Host* const host_; |
|
o1ka
2016/09/28 10:24:07
const
|
| + |
| + 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.
|
| + const int render_frame_id_; |
| + const int render_process_id_; |
| + const std::string output_device_id_; |
| + mojo::Binding<AudioOutput> binding_; |
| + |
| + std::unique_ptr<AudioSyncReader> reader_; |
| + scoped_refptr<media::AudioOutputController> controller_; |
|
o1ka
2016/09/28 10:24:07
Should it be scoped? If yes, we need a comment on
|
| + |
| + 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
|
| + |
| + bool is_closing; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AudioOutputImpl); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_IMPL_H_ |