• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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 CEF_LIBCEF_BROWSER_AUDIO_LOOPBACK_STREAM_CREATOR_H_
6 #define CEF_LIBCEF_BROWSER_AUDIO_LOOPBACK_STREAM_CREATOR_H_
7 
8 #include "base/callback.h"
9 #include "content/browser/media/forwarding_audio_stream_factory.h"
10 #include "content/common/content_export.h"
11 #include "media/mojo/mojom/audio_data_pipe.mojom.h"
12 #include "media/mojo/mojom/audio_input_stream.mojom.h"
13 #include "mojo/public/cpp/bindings/pending_remote.h"
14 
15 namespace media {
16 class AudioParameters;
17 }
18 
19 // This class handles creating a loopback stream that either captures audio from
20 // a WebContents or the system-wide loopback through the Audio Service.
21 // This class is operated on the UI thread.
22 // Based on InProcessAudioLoopbackStreamCreator which was deleted in
23 // https://crrev.com/a5af2468cf.
24 class CefAudioLoopbackStreamCreator final {
25  public:
26   CefAudioLoopbackStreamCreator();
27 
28   CefAudioLoopbackStreamCreator(const CefAudioLoopbackStreamCreator&) = delete;
29   CefAudioLoopbackStreamCreator& operator=(
30       const CefAudioLoopbackStreamCreator&) = delete;
31 
32   ~CefAudioLoopbackStreamCreator();
33 
34   // The callback that is called when the requested stream is created.
35   using StreamCreatedCallback = base::RepeatingCallback<void(
36       mojo::PendingRemote<media::mojom::AudioInputStream> stream,
37       mojo::PendingReceiver<media::mojom::AudioInputStreamClient>
38           client_receiver,
39       media::mojom::ReadOnlyAudioDataPipePtr data_pipe)>;
40 
41   // Creates a loopback stream that captures the audio from |loopback_source|,
42   // or the default system playback if |loopback_source| is null. Local output
43   // of the source/system audio is muted during capturing.
44   void CreateLoopbackStream(content::WebContents* loopback_source,
45                             const media::AudioParameters& params,
46                             uint32_t total_segments,
47                             const StreamCreatedCallback& callback);
48 
49  private:
50   content::ForwardingAudioStreamFactory factory_;
51 };
52 
53 #endif  // CEF_LIBCEF_BROWSER_AUDIO_LOOPBACK_STREAM_CREATOR_H_
54