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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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_H_
6 #define MEDIA_MOJO_SERVICES_MOJO_AUDIO_OUTPUT_H_
7
8 #include <memory>
9 #include <string>
10
11 // This class handles IPC for single stream by delegating method calls to its
12 // AudioOutputDelegate.
13
14 #include "base/threading/thread_checker.h"
15 #include "media/base/audio_output_delegate.h"
16 #include "media/mojo/interfaces/audio_output.mojom.h"
17 #include "media/mojo/services/media_mojo_export.h"
18 #include "mojo/public/cpp/bindings/binding.h"
19
20 namespace media {
21
22 class MEDIA_MOJO_EXPORT MojoAudioOutput
23 : public mojom::AudioOutput,
24 public AudioOutputDelegate::EventHandler {
25 public:
26 using CreateDelegateCallback =
27 base::OnceCallback<std::unique_ptr<AudioOutputDelegate>(
28 AudioOutputDelegate::EventHandler*,
29 const AudioParameters&)>;
30 using FinishedCallback = base::OnceCallback<void(mojom::AudioOutput*)>;
31
32 // |create_delegate_callback| is used to obtain an AudioOutputDelegate for the
33 // stream when it's initialized and |finished_callback| is called when this
34 // class
35 // should be removed (stream ended/error). |finished_callback| is required to
36 // destroy |this| synchronously.
37 MojoAudioOutput(mojom::AudioOutputRequest request,
38 CreateDelegateCallback create_delegate_callback,
39 FinishedCallback finished_callback);
40
41 ~MojoAudioOutput() override;
42
43 private:
44 // mojom::AudioOutput implementation.
45 void Initialize(const AudioParameters& params,
46 const InitializeCallback& callback) override;
47 void Play() override;
48 void Pause() override;
49 void SetVolume(double volume) override;
50
51 // AudioOutputDelegate::EventHandler implementation.
52 void OnStreamCreated(int stream_id,
53 base::SharedMemory* shared_memory,
54 base::CancelableSyncSocket* foreign_socket) override;
55 void OnStreamError(int stream_id) override;
56
57 // Closes connection to client and notifies owner.
58 void OnError();
59
60 // The callback for the Initialize() must be stored until the response is
61 // ready.
62 InitializeCallback initialize_callback_;
63
64 mojo::Binding<AudioOutput> binding_;
65 CreateDelegateCallback create_delegate_callback_;
66 FinishedCallback finished_callback_;
67 base::ThreadChecker thread_checker_;
68 std::unique_ptr<AudioOutputDelegate> delegate_;
69
70 DISALLOW_COPY_AND_ASSIGN(MojoAudioOutput);
71 };
72
73 } // namespace media
74
75 #endif // MEDIA_MOJO_SERVICES_MOJO_AUDIO_OUTPUT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698