[M120 Migration][MM][CAPI] Fix the logic for media using capi player.
[platform/framework/web/chromium-efl.git] / media / mojo / services / mojo_audio_input_stream.h
1 // Copyright 2017 The Chromium Authors
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_INPUT_STREAM_H_
6 #define MEDIA_MOJO_SERVICES_MOJO_AUDIO_INPUT_STREAM_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/sequence_checker.h"
12 #include "media/audio/audio_input_delegate.h"
13 #include "media/mojo/mojom/audio_data_pipe.mojom.h"
14 #include "media/mojo/mojom/audio_input_stream.mojom.h"
15 #include "media/mojo/services/media_mojo_export.h"
16 #include "mojo/public/cpp/bindings/pending_receiver.h"
17 #include "mojo/public/cpp/bindings/pending_remote.h"
18 #include "mojo/public/cpp/bindings/receiver.h"
19 #include "mojo/public/cpp/bindings/remote.h"
20
21 namespace media {
22
23 // This class handles IPC for single audio input stream by delegating method
24 // calls to its AudioInputDelegate.
25 class MEDIA_MOJO_EXPORT MojoAudioInputStream
26     : public mojom::AudioInputStream,
27       public AudioInputDelegate::EventHandler {
28  public:
29   using StreamCreatedCallback =
30       base::OnceCallback<void(mojom::ReadOnlyAudioDataPipePtr, bool)>;
31   using CreateDelegateCallback =
32       base::OnceCallback<std::unique_ptr<AudioInputDelegate>(
33           AudioInputDelegate::EventHandler*)>;
34
35   // |create_delegate_callback| is used to obtain an AudioInputDelegate for the
36   // stream in the constructor. |stream_created_callback| is called when the
37   // stream has been initialized. |deleter_callback| is called when this class
38   // should be removed (stream ended/error). |deleter_callback| is required to
39   // destroy |this| synchronously.
40   MojoAudioInputStream(
41       mojo::PendingReceiver<mojom::AudioInputStream> receiver,
42       mojo::PendingRemote<mojom::AudioInputStreamClient> client,
43       CreateDelegateCallback create_delegate_callback,
44       StreamCreatedCallback stream_created_callback,
45       base::OnceClosure deleter_callback);
46
47   MojoAudioInputStream(const MojoAudioInputStream&) = delete;
48   MojoAudioInputStream& operator=(const MojoAudioInputStream&) = delete;
49
50   ~MojoAudioInputStream() override;
51
52   void SetOutputDeviceForAec(const std::string& raw_output_device_id);
53
54  private:
55   // mojom::AudioInputStream implementation.
56   void Record() override;
57   void SetVolume(double volume) override;
58
59   // AudioInputDelegate::EventHandler implementation.
60   void OnStreamCreated(
61       int stream_id,
62       base::ReadOnlySharedMemoryRegion shared_memory_region,
63       std::unique_ptr<base::CancelableSyncSocket> foreign_socket,
64       bool initially_muted) override;
65   void OnStreamError(int stream_id) override;
66
67   // Closes connection to client and notifies owner.
68   void OnError();
69
70   SEQUENCE_CHECKER(sequence_checker_);
71
72   StreamCreatedCallback stream_created_callback_;
73   base::OnceClosure deleter_callback_;
74   mojo::Receiver<AudioInputStream> receiver_;
75   mojo::Remote<mojom::AudioInputStreamClient> client_;
76   std::unique_ptr<AudioInputDelegate> delegate_;
77   base::WeakPtrFactory<MojoAudioInputStream> weak_factory_{this};
78 };
79
80 }  // namespace media
81
82 #endif  // MEDIA_MOJO_SERVICES_MOJO_AUDIO_INPUT_STREAM_H_