// Copyright 2018 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 SERVICES_AUDIO_INPUT_STREAM_H_ #define SERVICES_AUDIO_INPUT_STREAM_H_ #include #include #include "base/memory/scoped_refptr.h" #include "base/sync_socket.h" #include "base/unguessable_token.h" #include "media/mojo/mojom/audio_data_pipe.mojom.h" #include "media/mojo/mojom/audio_input_stream.mojom.h" #include "media/mojo/mojom/audio_logging.mojom.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/shared_remote.h" #include "services/audio/input_controller.h" namespace media { class AudioManager; class AudioParameters; } // namespace media namespace audio { class InputSyncWriter; class UserInputMonitor; class InputStream final : public media::mojom::AudioInputStream, public InputController::EventHandler { public: using CreatedCallback = base::OnceCallback&)>; using DeleteCallback = base::OnceCallback; InputStream( CreatedCallback created_callback, DeleteCallback delete_callback, mojo::PendingReceiver receiver, mojo::PendingRemote client, mojo::PendingRemote observer, mojo::PendingRemote log, media::AudioManager* manager, std::unique_ptr user_input_monitor, const std::string& device_id, const media::AudioParameters& params, uint32_t shared_memory_count, bool enable_agc); ~InputStream() override; const base::UnguessableToken& id() const { return id_; } void SetOutputDeviceForAec(const std::string& output_device_id); // media::mojom::AudioInputStream implementation. void Record() override; void SetVolume(double volume) override; // InputController::EventHandler implementation. void OnCreated(bool initially_muted) override; void OnError(InputController::ErrorCode error_code) override; void OnLog(base::StringPiece) override; void OnMuted(bool is_muted) override; private: void OnStreamError(bool signalPlatformError); void CallDeleter(); void SendLogMessage(const char* format, ...) PRINTF_FORMAT(2, 3); const base::UnguessableToken id_; mojo::Receiver receiver_; mojo::Remote client_; mojo::Remote observer_; const mojo::SharedRemote log_; // Notify stream client on creation. CreatedCallback created_callback_; // Notify stream factory (audio service) on destruction. DeleteCallback delete_callback_; base::CancelableSyncSocket foreign_socket_; const std::unique_ptr writer_; std::unique_ptr controller_; const std::unique_ptr user_input_monitor_; SEQUENCE_CHECKER(owning_sequence_); base::WeakPtrFactory weak_factory_{this}; DISALLOW_COPY_AND_ASSIGN(InputStream); }; } // namespace audio #endif // SERVICES_AUDIO_INPUT_STREAM_H_