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 MEDIA_MOJO_SERVICES_MOJO_AUDIO_OUTPUT_STREAM_H_ |
| 6 #define MEDIA_MOJO_SERVICES_MOJO_AUDIO_OUTPUT_STREAM_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 |
| 11 #include "base/threading/thread_checker.h" |
| 12 #include "media/audio/audio_output_delegate.h" |
| 13 #include "media/mojo/interfaces/audio_output_stream.mojom.h" |
| 14 #include "media/mojo/services/media_mojo_export.h" |
| 15 #include "mojo/public/cpp/bindings/binding.h" |
| 16 |
| 17 namespace media { |
| 18 |
| 19 // This class handles IPC for single audio output stream by delegating method |
| 20 // calls to its AudioOutputDelegate. |
| 21 class MEDIA_MOJO_EXPORT MojoAudioOutputStream |
| 22 : NON_EXPORTED_BASE(public mojom::AudioOutputStream), |
| 23 NON_EXPORTED_BASE(public AudioOutputDelegate::EventHandler) { |
| 24 public: |
| 25 using StreamCreatedCallback = |
| 26 mojom::AudioOutputStreamProvider::AcquireCallback; |
| 27 using CreateDelegateCallback = |
| 28 base::OnceCallback<std::unique_ptr<AudioOutputDelegate>( |
| 29 AudioOutputDelegate::EventHandler*)>; |
| 30 |
| 31 // |create_delegate_callback| is used to obtain an AudioOutputDelegate for the |
| 32 // stream in the constructor. |stream_created_callback| is called when the |
| 33 // stream has been initialized. |deleter_callback| is called when this class |
| 34 // should be removed (stream ended/error). |deleter_callback| is required to |
| 35 // destroy |this| synchronously. |
| 36 MojoAudioOutputStream(mojom::AudioOutputStreamRequest request, |
| 37 CreateDelegateCallback create_delegate_callback, |
| 38 StreamCreatedCallback stream_created_callback, |
| 39 base::OnceClosure deleter_callback); |
| 40 |
| 41 ~MojoAudioOutputStream() override; |
| 42 |
| 43 private: |
| 44 // mojom::AudioOutputStream implementation. |
| 45 void Play() override; |
| 46 void Pause() override; |
| 47 void SetVolume(double volume) override; |
| 48 |
| 49 // AudioOutputDelegate::EventHandler implementation. |
| 50 void OnStreamCreated(int stream_id, |
| 51 base::SharedMemory* shared_memory, |
| 52 base::CancelableSyncSocket* foreign_socket) override; |
| 53 void OnStreamError(int stream_id) override; |
| 54 |
| 55 // Closes connection to client and notifies owner. |
| 56 void OnError(); |
| 57 |
| 58 StreamCreatedCallback stream_created_callback_; |
| 59 base::OnceClosure deleter_callback_; |
| 60 mojo::Binding<AudioOutputStream> binding_; |
| 61 base::ThreadChecker thread_checker_; |
| 62 std::unique_ptr<AudioOutputDelegate> delegate_; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(MojoAudioOutputStream); |
| 65 }; |
| 66 |
| 67 } // namespace media |
| 68 |
| 69 #endif // MEDIA_MOJO_SERVICES_MOJO_AUDIO_OUTPUT_STREAM_H_ |
OLD | NEW |