summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/modules/audio_device/win/core_audio_output_win.h
blob: 5a547498a381917316f801e55246ebf8afb9dbe3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
 *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef MODULES_AUDIO_DEVICE_WIN_CORE_AUDIO_OUTPUT_WIN_H_
#define MODULES_AUDIO_DEVICE_WIN_CORE_AUDIO_OUTPUT_WIN_H_

#include <memory>
#include <string>

#include "modules/audio_device/win/audio_device_module_win.h"
#include "modules/audio_device/win/core_audio_base_win.h"

namespace webrtc {

class AudioDeviceBuffer;
class FineAudioBuffer;

namespace webrtc_win {

// Windows specific AudioOutput implementation using a CoreAudioBase class where
// an output direction is set at construction. Supports render device handling
// and streaming of decoded audio from a WebRTC client to the native audio
// layer.
class CoreAudioOutput final : public CoreAudioBase, public AudioOutput {
 public:
  CoreAudioOutput(bool automatic_restart);
  ~CoreAudioOutput() override;

  // AudioOutput implementation.
  int Init() override;
  int Terminate() override;
  int NumDevices() const override;
  int SetDevice(int index) override;
  int SetDevice(AudioDeviceModule::WindowsDeviceType device) override;
  int DeviceName(int index, std::string* name, std::string* guid) override;
  void AttachAudioBuffer(AudioDeviceBuffer* audio_buffer) override;
  bool PlayoutIsInitialized() const override;
  int InitPlayout() override;
  int StartPlayout() override;
  int StopPlayout() override;
  bool Playing() override;
  int VolumeIsAvailable(bool* available) override;
  int RestartPlayout() override;
  bool Restarting() const override;
  int SetSampleRate(uint32_t sample_rate) override;

  CoreAudioOutput(const CoreAudioOutput&) = delete;
  CoreAudioOutput& operator=(const CoreAudioOutput&) = delete;

 private:
  void ReleaseCOMObjects();
  bool OnDataCallback(uint64_t device_frequency);
  bool OnErrorCallback(ErrorType error);
  int EstimateOutputLatencyMillis(uint64_t device_frequency);
  bool HandleStreamDisconnected();

  std::unique_ptr<FineAudioBuffer> fine_audio_buffer_;
  Microsoft::WRL::ComPtr<IAudioRenderClient> audio_render_client_;
  uint64_t num_frames_written_ = 0;
};

}  // namespace webrtc_win
}  // namespace webrtc

#endif  // MODULES_AUDIO_DEVICE_WIN_CORE_AUDIO_OUTPUT_WIN_H_