blob: 24b09d2140a2546c793ed425fb8abaedf331047a [file] [log] [blame]
Fredrik Solenberg2a877972017-12-15 15:42:151/*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef AUDIO_AUDIO_TRANSPORT_IMPL_H_
12#define AUDIO_AUDIO_TRANSPORT_IMPL_H_
13
Olga Sharonova09ceed22020-09-30 16:27:3914#include <memory>
Fredrik Solenberg2a877972017-12-15 15:42:1515#include <vector>
16
17#include "api/audio/audio_mixer.h"
Mirko Bonadeid9708072019-01-25 19:26:4818#include "api/scoped_refptr.h"
Fredrik Solenberg2a877972017-12-15 15:42:1519#include "common_audio/resampler/include/push_resampler.h"
Olga Sharonova09ceed22020-09-30 16:27:3920#include "modules/async_audio_processing/async_audio_processing.h"
Fredrik Solenberg2a877972017-12-15 15:42:1521#include "modules/audio_device/include/audio_device.h"
22#include "modules/audio_processing/include/audio_processing.h"
Markus Handell62872802020-07-06 13:15:0723#include "rtc_base/synchronization/mutex.h"
Fredrik Solenberg2a877972017-12-15 15:42:1524#include "rtc_base/thread_annotations.h"
Fredrik Solenberg2a877972017-12-15 15:42:1525
26namespace webrtc {
27
Tim Nab8c775a2020-01-10 18:33:0528class AudioSender;
Fredrik Solenberg2a877972017-12-15 15:42:1529
30class AudioTransportImpl : public AudioTransport {
31 public:
Olga Sharonova09ceed22020-09-30 16:27:3932 AudioTransportImpl(
33 AudioMixer* mixer,
34 AudioProcessing* audio_processing,
35 AsyncAudioProcessing::Factory* async_audio_processing_factory);
Niels Möllerde953292020-09-29 07:46:2136
37 AudioTransportImpl() = delete;
38 AudioTransportImpl(const AudioTransportImpl&) = delete;
39 AudioTransportImpl& operator=(const AudioTransportImpl&) = delete;
40
Fredrik Solenberg2a877972017-12-15 15:42:1541 ~AudioTransportImpl() override;
42
Olov Brändströmb732bd52022-01-28 14:07:3943 // TODO(bugs.webrtc.org/13620) Deprecate this function
Fredrik Solenberg2a877972017-12-15 15:42:1544 int32_t RecordedDataIsAvailable(const void* audioSamples,
Ali Tofigh62238092022-01-25 12:27:1945 size_t nSamples,
46 size_t nBytesPerSample,
47 size_t nChannels,
48 uint32_t samplesPerSec,
49 uint32_t totalDelayMS,
50 int32_t clockDrift,
51 uint32_t currentMicLevel,
52 bool keyPressed,
Fredrik Solenberg2a877972017-12-15 15:42:1553 uint32_t& newMicLevel) override;
54
Jakob Ivarsson22821de2023-01-20 21:09:2955 int32_t RecordedDataIsAvailable(
56 const void* audioSamples,
57 size_t nSamples,
58 size_t nBytesPerSample,
59 size_t nChannels,
60 uint32_t samplesPerSec,
61 uint32_t totalDelayMS,
62 int32_t clockDrift,
63 uint32_t currentMicLevel,
64 bool keyPressed,
65 uint32_t& newMicLevel,
66 absl::optional<int64_t> estimated_capture_time_ns) override;
Olov Brändströmb732bd52022-01-28 14:07:3967
Ali Tofigh62238092022-01-25 12:27:1968 int32_t NeedMorePlayData(size_t nSamples,
69 size_t nBytesPerSample,
70 size_t nChannels,
71 uint32_t samplesPerSec,
Fredrik Solenberg2a877972017-12-15 15:42:1572 void* audioSamples,
73 size_t& nSamplesOut,
74 int64_t* elapsed_time_ms,
75 int64_t* ntp_time_ms) override;
76
77 void PullRenderData(int bits_per_sample,
78 int sample_rate,
79 size_t number_of_channels,
80 size_t number_of_frames,
81 void* audio_data,
82 int64_t* elapsed_time_ms,
83 int64_t* ntp_time_ms) override;
84
Tim Nab8c775a2020-01-10 18:33:0585 void UpdateAudioSenders(std::vector<AudioSender*> senders,
86 int send_sample_rate_hz,
87 size_t send_num_channels);
Fredrik Solenberg2a877972017-12-15 15:42:1588 void SetStereoChannelSwapping(bool enable);
Fredrik Solenberg2a877972017-12-15 15:42:1589
90 private:
Olga Sharonova09ceed22020-09-30 16:27:3991 void SendProcessedData(std::unique_ptr<AudioFrame> audio_frame);
92
Fredrik Solenberg2a877972017-12-15 15:42:1593 // Shared.
94 AudioProcessing* audio_processing_ = nullptr;
95
96 // Capture side.
Olga Sharonova09ceed22020-09-30 16:27:3997
98 // Thread-safe.
99 const std::unique_ptr<AsyncAudioProcessing> async_audio_processing_;
100
Markus Handell62872802020-07-06 13:15:07101 mutable Mutex capture_lock_;
Tim Nab8c775a2020-01-10 18:33:05102 std::vector<AudioSender*> audio_senders_ RTC_GUARDED_BY(capture_lock_);
Fredrik Solenberg2a877972017-12-15 15:42:15103 int send_sample_rate_hz_ RTC_GUARDED_BY(capture_lock_) = 8000;
104 size_t send_num_channels_ RTC_GUARDED_BY(capture_lock_) = 1;
Fredrik Solenberg2a877972017-12-15 15:42:15105 bool swap_stereo_channels_ RTC_GUARDED_BY(capture_lock_) = false;
Fredrik Solenberg2a877972017-12-15 15:42:15106 PushResampler<int16_t> capture_resampler_;
Fredrik Solenberg2a877972017-12-15 15:42:15107
108 // Render side.
Olga Sharonova09ceed22020-09-30 16:27:39109
Fredrik Solenberg2a877972017-12-15 15:42:15110 rtc::scoped_refptr<AudioMixer> mixer_;
111 AudioFrame mixed_frame_;
112 // Converts mixed audio to the audio device output rate.
113 PushResampler<int16_t> render_resampler_;
Fredrik Solenberg2a877972017-12-15 15:42:15114};
115} // namespace webrtc
116
117#endif // AUDIO_AUDIO_TRANSPORT_IMPL_H_