audio_input_ipc.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright (c) 2012 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. #ifndef MEDIA_AUDIO_AUDIO_INPUT_IPC_H_
  5. #define MEDIA_AUDIO_AUDIO_INPUT_IPC_H_
  6. #include <stdint.h>
  7. #include "base/memory/read_only_shared_memory_region.h"
  8. #include "base/sync_socket.h"
  9. #include "media/base/audio_capturer_source.h"
  10. #include "media/base/audio_parameters.h"
  11. #include "media/base/media_export.h"
  12. namespace media {
  13. class AudioProcessorControls;
  14. // Contains IPC notifications for the state of the server side
  15. // (AudioInputController) audio state changes and when an AudioInputController
  16. // has been created. Implemented by AudioInputDevice.
  17. class MEDIA_EXPORT AudioInputIPCDelegate {
  18. public:
  19. // Called when an AudioInputController has been created.
  20. // See media/mojo/mojom/audio_data_pipe.mojom for documentation of
  21. // |handle| and |socket_handle|.
  22. virtual void OnStreamCreated(
  23. base::ReadOnlySharedMemoryRegion shared_memory_region,
  24. base::SyncSocket::ScopedHandle socket_handle,
  25. bool initially_muted) = 0;
  26. // Called when state of an audio stream has changed.
  27. virtual void OnError(AudioCapturerSource::ErrorCode code) = 0;
  28. // Called when an audio stream is muted or unmuted.
  29. virtual void OnMuted(bool is_muted) = 0;
  30. // Called when the AudioInputIPC object is going away and/or when the
  31. // IPC channel has been closed and no more IPC requests can be made.
  32. // Implementations should delete their owned AudioInputIPC instance
  33. // immediately.
  34. virtual void OnIPCClosed() = 0;
  35. protected:
  36. virtual ~AudioInputIPCDelegate();
  37. };
  38. // Provides IPC functionality for an AudioInputIPCDelegate (e.g., an
  39. // AudioInputDevice). The implementation should asynchronously deliver the
  40. // messages to an AudioInputController object (or create one in the case of
  41. // CreateStream()), that may live in a separate process.
  42. class MEDIA_EXPORT AudioInputIPC {
  43. public:
  44. virtual ~AudioInputIPC();
  45. // Sends a request to create an AudioInputController object in the peer
  46. // process, and configures it to use the specified audio |params|. The
  47. // |total_segments| indidates number of equal-lengthed segments in the shared
  48. // memory buffer. Once the stream has been created, the implementation will
  49. // notify |delegate| by calling OnStreamCreated().
  50. virtual void CreateStream(AudioInputIPCDelegate* delegate,
  51. const AudioParameters& params,
  52. bool automatic_gain_control,
  53. uint32_t total_segments) = 0;
  54. // Corresponds to a call to AudioInputController::Record() on the server side.
  55. virtual void RecordStream() = 0;
  56. // Sets the volume of the audio stream.
  57. virtual void SetVolume(double volume) = 0;
  58. // Sets the output device from which to cancel echo, if supported. The
  59. // |output_device_id| can be gotten from a device enumeration. Must not be
  60. // called before the stream has been successfully created.
  61. virtual void SetOutputDeviceForAec(const std::string& output_device_id) = 0;
  62. // If the input has built-in processing, returns a pointer to processing
  63. // controls. Valid after the stream has been created.
  64. virtual AudioProcessorControls* GetProcessorControls();
  65. // Closes the audio stream, which should shut down the corresponding
  66. // AudioInputController in the peer process.
  67. virtual void CloseStream() = 0;
  68. };
  69. } // namespace media
  70. #endif // MEDIA_AUDIO_AUDIO_INPUT_IPC_H_