Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: media/mojo/services/mojo_audio_output.h

Issue 2697793002: Add mojo interface+impl for audio stream control. (Closed)
Patch Set: Dale's comments and add MEDIA_MOJO_EXPORT Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e3b6ef27a9441aa61d716d3fcd5d8bfeb6f711dd
--- /dev/null
+++ b/media/mojo/services/mojo_audio_output.h
@@ -0,0 +1,75 @@
+// 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
+// AudioOutputDelegate.
+
+#include "base/threading/thread_checker.h"
+#include "media/base/audio_output_delegate.h"
+#include "media/mojo/interfaces/audio_output.mojom.h"
+#include "media/mojo/services/media_mojo_export.h"
+#include "mojo/public/cpp/bindings/binding.h"
+
+namespace media {
+
+class MEDIA_MOJO_EXPORT 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 initialized and |finished_callback| is called when this
+ // class
+ // should be removed (stream ended/error). |finished_callback| is required to
+ // destroy |this| synchronously.
+ MojoAudioOutput(mojom::AudioOutputRequest request,
+ CreateDelegateCallback create_delegate_callback,
+ FinishedCallback finished_callback);
+
+ ~MojoAudioOutput() override;
+
+ private:
+ // mojom::AudioOutput implementation.
+ void Initialize(const AudioParameters& params,
+ const InitializeCallback& 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 Initialize() must be stored until the response is
+ // ready.
+ InitializeCallback initialize_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_

Powered by Google App Engine
This is Rietveld 408576698