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