OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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_RENDERER_MEDIA_MOJO_AUDIO_OUTPUT_IPC_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_MOJO_AUDIO_OUTPUT_IPC_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback_helpers.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/threading/thread_checker.h" |
| 14 #include "content/common/content_export.h" |
| 15 #include "content/common/media/renderer_audio_output_stream_factory.mojom.h" |
| 16 #include "media/audio/audio_output_ipc.h" |
| 17 |
| 18 namespace content { |
| 19 |
| 20 // MojoAudioOutputIPC is a renderer-side class for handling creation, |
| 21 // initialization and control of an output stream. May only be used on a single |
| 22 // thread. |
| 23 class CONTENT_EXPORT MojoAudioOutputIPC : public media::AudioOutputIPC { |
| 24 public: |
| 25 using FactoryAccessorCB = |
| 26 base::RepeatingCallback<mojom::RendererAudioOutputStreamFactory*()>; |
| 27 |
| 28 // |factory_accessor| is required to provide a |
| 29 // RendererAudioOutputStreamFactory* if IPC is possible. |
| 30 explicit MojoAudioOutputIPC(FactoryAccessorCB factory_accessor); |
| 31 |
| 32 ~MojoAudioOutputIPC() override; |
| 33 |
| 34 // AudioOutputIPC implementation. |
| 35 void RequestDeviceAuthorization(media::AudioOutputIPCDelegate* delegate, |
| 36 int session_id, |
| 37 const std::string& device_id, |
| 38 const url::Origin& security_origin) override; |
| 39 void CreateStream(media::AudioOutputIPCDelegate* delegate, |
| 40 const media::AudioParameters& params) override; |
| 41 void PlayStream() override; |
| 42 void PauseStream() override; |
| 43 void CloseStream() override; |
| 44 void SetVolume(double volume) override; |
| 45 |
| 46 private: |
| 47 using AuthorizationCB = mojom::RendererAudioOutputStreamFactory:: |
| 48 RequestDeviceAuthorizationCallback; |
| 49 |
| 50 bool AuthorizationRequested(); |
| 51 bool StreamCreationRequested(); |
| 52 media::mojom::AudioOutputStreamProviderRequest MakeProviderRequest(); |
| 53 |
| 54 // Tries to acquire a RendererAudioOutputStreamFactory, returns true on |
| 55 // success. On failure, |this| has been deleted, so returning immediately |
| 56 // is required. |
| 57 bool DoRequestDeviceAuthorization(int session_id, |
| 58 const std::string& device_id, |
| 59 AuthorizationCB callback); |
| 60 |
| 61 void ReceivedDeviceAuthorization(base::ScopedClosureRunner fallback_closure, |
| 62 media::OutputDeviceStatus status, |
| 63 const media::AudioParameters& params, |
| 64 const std::string& device_id) const; |
| 65 |
| 66 void StreamCreated(mojo::ScopedSharedBufferHandle shared_memory, |
| 67 mojo::ScopedHandle socket); |
| 68 |
| 69 const FactoryAccessorCB factory_accessor_; |
| 70 |
| 71 THREAD_CHECKER(thread_checker_); |
| 72 media::mojom::AudioOutputStreamProviderPtr stream_provider_; |
| 73 media::mojom::AudioOutputStreamPtr stream_; |
| 74 media::AudioOutputIPCDelegate* delegate_ = nullptr; |
| 75 |
| 76 // To make sure we don't send an "authorization completed" callback for a |
| 77 // stream after it's closed, we use this weak factory. |
| 78 base::WeakPtrFactory<MojoAudioOutputIPC> weak_factory_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(MojoAudioOutputIPC); |
| 81 }; |
| 82 |
| 83 } // namespace content |
| 84 |
| 85 #endif // CONTENT_RENDERER_MEDIA_MOJO_AUDIO_OUTPUT_IPC_H_ |
OLD | NEW |