Index: media/mojo/services/mojo_audio_output.h |
diff --git a/media/mojo/services/mojo_audio_output.h b/media/mojo/services/mojo_audio_output.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5b89c728008fc0efa8ed9b359d122ba34a16ca09 |
--- /dev/null |
+++ b/media/mojo/services/mojo_audio_output.h |
@@ -0,0 +1,70 @@ |
+// 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 MEDIA_MOJO_SERVICES_MOJO_AUDIO_OUTPUT_H_ |
+#define MEDIA_MOJO_SERVICES_MOJO_AUDIO_OUTPUT_H_ |
+ |
+#include <memory> |
+#include <string> |
+ |
+// This class handles IPC for single stream by delegating method calls to its |
o1ka
2017/02/22 13:26:30
nit "audio output stream"
Max Morin
2017/03/02 23:11:32
Done.
|
+// AudioOutputDelegate. |
+ |
+#include "base/threading/thread_checker.h" |
+#include "media/base/audio_output_delegate.h" |
+#include "media/mojo/interfaces/audio_output.mojom.h" |
+#include "mojo/public/cpp/bindings/binding.h" |
+ |
+namespace media { |
+ |
+class MojoAudioOutput : public mojom::AudioOutput, |
+ public AudioOutputDelegate::EventHandler { |
+ public: |
+ using CreateDelegateCallback = |
+ base::OnceCallback<std::unique_ptr<AudioOutputDelegate>( |
+ AudioOutputDelegate::EventHandler*, |
+ const AudioParameters&)>; |
+ using FinishedCallback = base::OnceCallback<void(mojom::AudioOutput*)>; |
+ |
+ // |create_delegate_callback| is used to obtain an AudioOutputDelegate for the |
+ // stream when it's started and |finished_callback| is called when this class |
+ // should be removed (stream ended/error). |
+ MojoAudioOutput(mojom::AudioOutputRequest request, |
+ CreateDelegateCallback create_delegate_callback, |
+ FinishedCallback finished_callback); |
+ |
+ ~MojoAudioOutput() override; |
+ |
+ private: |
+ // mojom::AudioOutput implementation. |
+ void Start(const AudioParameters& params, |
+ const StartCallback& callback) override; |
+ void Play() override; |
+ void Pause() override; |
+ void SetVolume(double volume) override; |
+ |
+ // AudioOutputDelegate::EventHandler implementation. |
+ void OnStreamCreated(int stream_id, |
+ base::SharedMemory* shared_memory, |
+ base::CancelableSyncSocket* foreign_socket) override; |
+ void OnStreamError(int stream_id) override; |
+ |
+ // Closes connection to client and notifies owner. |
+ void OnError(); |
+ |
+ // The callback for the Start() must be stored until the response is ready. |
+ StartCallback start_callback_; |
+ |
+ mojo::Binding<AudioOutput> binding_; |
+ CreateDelegateCallback create_delegate_callback_; |
+ FinishedCallback finished_callback_; |
+ base::ThreadChecker thread_checker_; |
+ std::unique_ptr<AudioOutputDelegate> delegate_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MojoAudioOutput); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_MOJO_SERVICES_MOJO_AUDIO_OUTPUT_H_ |