OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_MOJO_SERVICES_MOJO_AUDIO_OUTPUT_STREAM_PROVIDER_H_ | 5 #ifndef MEDIA_MOJO_SERVICES_MOJO_AUDIO_OUTPUT_STREAM_PROVIDER_H_ |
6 #define MEDIA_MOJO_SERVICES_MOJO_AUDIO_OUTPUT_STREAM_PROVIDER_H_ | 6 #define MEDIA_MOJO_SERVICES_MOJO_AUDIO_OUTPUT_STREAM_PROVIDER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
12 #include "media/audio/audio_output_delegate.h" | 12 #include "media/audio/audio_output_delegate.h" |
13 #include "media/mojo/interfaces/audio_output_stream.mojom.h" | 13 #include "media/mojo/interfaces/audio_output_stream.mojom.h" |
14 #include "media/mojo/services/media_mojo_export.h" | 14 #include "media/mojo/services/media_mojo_export.h" |
15 #include "media/mojo/services/mojo_audio_output_stream.h" | 15 #include "media/mojo/services/mojo_audio_output_stream.h" |
16 #include "mojo/public/cpp/bindings/binding.h" | 16 #include "mojo/public/cpp/bindings/binding.h" |
17 | 17 |
18 namespace media { | 18 namespace media { |
19 | 19 |
20 // Provides a single AudioOutput, given the audio parameters to use. | 20 // Provides a single AudioOutput, given the audio parameters to use. |
21 class MEDIA_MOJO_EXPORT MojoAudioOutputStreamProvider | 21 class MEDIA_MOJO_EXPORT MojoAudioOutputStreamProvider |
22 : NON_EXPORTED_BASE(public mojom::AudioOutputStreamProvider) { | 22 : NON_EXPORTED_BASE(public mojom::AudioOutputStreamProvider) { |
23 public: | 23 public: |
24 using CreateDelegateCallback = | 24 using CreateDelegateCallback = |
25 base::OnceCallback<std::unique_ptr<AudioOutputDelegate>( | 25 base::OnceCallback<std::unique_ptr<AudioOutputDelegate>( |
26 const AudioParameters& params, | 26 const AudioParameters& params, |
27 AudioOutputDelegate::EventHandler*)>; | 27 AudioOutputDelegate::EventHandler*)>; |
28 using DeleterCallback = base::Callback<void(AudioOutputStreamProvider*)>; | 28 using DeleterCallback = base::OnceCallback<void(AudioOutputStreamProvider*)>; |
29 | 29 |
30 // |create_delegate_callback| is used to obtain an AudioOutputDelegate for the | 30 // |create_delegate_callback| is used to obtain an AudioOutputDelegate for the |
31 // AudioOutput when it's initialized and |deleter_callback| is called when | 31 // AudioOutput when it's initialized and |deleter_callback| is called when |
32 // this class should be removed (stream ended/error). |deleter_callback| is | 32 // this class should be removed (stream ended/error). |deleter_callback| is |
33 // required to destroy |this| synchronously. | 33 // required to destroy |this| synchronously. |
34 MojoAudioOutputStreamProvider(mojom::AudioOutputStreamProviderRequest request, | 34 MojoAudioOutputStreamProvider(mojom::AudioOutputStreamProviderRequest request, |
35 CreateDelegateCallback create_delegate_callback, | 35 CreateDelegateCallback create_delegate_callback, |
36 DeleterCallback deleter_callback); | 36 DeleterCallback deleter_callback); |
37 | 37 |
38 ~MojoAudioOutputStreamProvider() override; | 38 ~MojoAudioOutputStreamProvider() override; |
39 | 39 |
40 private: | 40 private: |
41 // mojom::AudioOutputStreamProvider implementation. | 41 // mojom::AudioOutputStreamProvider implementation. |
42 void Acquire(mojom::AudioOutputStreamRequest stream_request, | 42 void Acquire(mojom::AudioOutputStreamRequest stream_request, |
43 const AudioParameters& params, | 43 const AudioParameters& params, |
44 const AcquireCallback& acquire_callback) override; | 44 const AcquireCallback& acquire_callback) override; |
45 | 45 |
| 46 // Called when |audio_output_| had an error. |
| 47 void OnError(); |
| 48 |
46 // The callback for the Acquire() must be stored until the response is ready. | 49 // The callback for the Acquire() must be stored until the response is ready. |
47 AcquireCallback acquire_callback_; | 50 AcquireCallback acquire_callback_; |
48 | 51 |
49 base::Optional<MojoAudioOutputStream> audio_output_; | 52 base::Optional<MojoAudioOutputStream> audio_output_; |
50 mojo::Binding<AudioOutputStreamProvider> binding_; | 53 mojo::Binding<AudioOutputStreamProvider> binding_; |
51 CreateDelegateCallback create_delegate_callback_; | 54 CreateDelegateCallback create_delegate_callback_; |
52 base::Closure deleter_callback_; | 55 DeleterCallback deleter_callback_; |
53 base::ThreadChecker thread_checker_; | 56 base::ThreadChecker thread_checker_; |
54 | 57 |
55 DISALLOW_COPY_AND_ASSIGN(MojoAudioOutputStreamProvider); | 58 DISALLOW_COPY_AND_ASSIGN(MojoAudioOutputStreamProvider); |
56 }; | 59 }; |
57 | 60 |
58 } // namespace media | 61 } // namespace media |
59 | 62 |
60 #endif // MEDIA_MOJO_SERVICES_MOJO_AUDIO_OUTPUT_STREAM_PROVIDER_H_ | 63 #endif // MEDIA_MOJO_SERVICES_MOJO_AUDIO_OUTPUT_STREAM_PROVIDER_H_ |
OLD | NEW |