Chromium Code Reviews| Index: content/browser/renderer_host/media/audio_output_delegate.h |
| diff --git a/content/browser/renderer_host/media/audio_output_delegate.h b/content/browser/renderer_host/media/audio_output_delegate.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..417d6198a2e2a55c4cef2c2d9a5619ccd33dfcff |
| --- /dev/null |
| +++ b/content/browser/renderer_host/media/audio_output_delegate.h |
| @@ -0,0 +1,96 @@ |
| +// 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_DELEGATE_H_ |
| +#define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_ |
| + |
| +#include <memory> |
| +#include <string> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/shared_memory.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/sync_socket.h" |
| +#include "content/browser/media/capture/audio_mirroring_manager.h" |
| +#include "content/browser/renderer_host/media/audio_sync_reader.h" |
| +#include "content/public/browser/media_observer.h" |
| +#include "media/audio/audio_logging.h" |
| +#include "media/audio/audio_output_controller.h" |
| +#include "media/base/audio_parameters.h" |
| + |
| +namespace content { |
| + |
| +// This class is operated on the IO thread. |
| +class AudioOutputDelegate : private media::AudioOutputController::EventHandler { |
| + public: |
| + class EventHandler { |
| + public: |
| + // Only called when playing-state changes. |
| + virtual void OnStreamStateChanged(bool playing) = 0; |
| + // Called when construction is finished and the stream is ready for |
| + // playout. |
| + virtual void OnStreamCreated(int stream_id, |
| + base::SharedMemory* shared_memory, |
| + base::CancelableSyncSocket* socket) = 0; |
| + // Called if stream encounters an error and has become unusable. |
| + virtual void OnStreamError(int stream_id) = 0; |
| + }; |
| + |
| + AudioOutputDelegate(EventHandler* handler, |
| + std::unique_ptr<media::AudioLog> audio_log, |
| + AudioMirroringManager* mirroring_manager, |
| + MediaObserver* media_observer, |
| + int stream_id, |
| + int render_frame_id, |
| + int render_process_id, |
| + media::AudioParameters params, |
| + const std::string& output_device_id); |
| + ~AudioOutputDelegate() override; |
| + |
| + const scoped_refptr<media::AudioOutputController>& controller() const { |
|
o1ka
2016/10/26 13:11:48
add a comment that this method is to be removed up
|
| + return controller_; |
| + } |
| + |
| + int stream_id() const { return stream_id_; } |
| + |
| + // Stream control: |
| + void OnPlayStream(); |
| + void OnPauseStream(); |
| + // The ownership of this object is passed into the method. |
| + // It will delete itself when ready. After this has been called, |
| + // the AudioOutputDelegate will no longer call any methods on the event |
| + // handler. |
| + void OnCloseStream(std::unique_ptr<AudioOutputDelegate> owned_this); |
| + void OnSetVolume(double volume); |
| + |
| + private: |
| + // AudioOutputController::EventHandler implementation. |
| + void OnControllerCreated() override; |
| + void OnControllerPlaying() override; |
| + void OnControllerPaused() override; |
| + void OnControllerError() override; |
| + |
| + void FinishClosing(); |
| + void UpdatePlayingStateForHandler(bool playing); |
| + |
| + EventHandler* const handler_; |
| + std::unique_ptr<media::AudioLog> const audio_log_; |
| + AudioMirroringManager* const mirroring_manager_; |
| + std::unique_ptr<AudioSyncReader> reader_; |
| + scoped_refptr<media::AudioOutputController> controller_; |
| + const int stream_id_; |
| + const int render_frame_id_; |
| + const int render_process_id_; |
| + // This flag ensures that we only send OnStreamStateChanged notifications |
| + // when the state actually changes. |
| + bool playing_ = false; |
| + // This flag ensures we don't send events to handler_ after OnStreamClosed. |
| + bool closed_ = false; |
| + base::WeakPtrFactory<AudioOutputDelegate> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AudioOutputDelegate); |
| +}; |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DELEGATE_H_ |