fork/rust-sdks

git clone https://git.julia.blue/fork/rust-sdks

Théo Monnomexpose apm stream_delay (#616)7cbdddf

main
2.3 KiB75 linesraw
1/*
2 * Copyright 2023 LiveKit
3 *
4 * Licensed under the Apache License, Version 2.0 (the “License”);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an “AS IS” BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <memory>
20
21#include "api/scoped_refptr.h"
22#include "api/video_codecs/video_decoder_factory.h"
23#include "api/video_codecs/video_encoder_factory.h"
24#include "modules/audio_processing/aec3/echo_canceller3.h"
25#include "modules/audio_processing/audio_buffer.h"
26
27namespace livekit {
28
29struct AudioProcessingConfig {
30  bool echo_canceller_enabled;
31  bool gain_controller_enabled;
32  bool high_pass_filter_enabled;
33  bool noise_suppression_enabled;
34
35  webrtc::AudioProcessing::Config ToWebrtcConfig() const {
36    webrtc::AudioProcessing::Config config;
37    config.echo_canceller.enabled = echo_canceller_enabled;
38    config.gain_controller2.enabled = gain_controller_enabled;
39    config.high_pass_filter.enabled = high_pass_filter_enabled;
40    config.noise_suppression.enabled = noise_suppression_enabled;
41    return config;
42  }
43};
44
45class AudioProcessingModule {
46 public:
47  AudioProcessingModule(const AudioProcessingConfig& config);
48
49  int process_stream(const int16_t* src,
50                     size_t src_len,
51                     int16_t* dst,
52                     size_t dst_len,
53                     int sample_rate,
54                     int num_channels);
55
56  int process_reverse_stream(const int16_t* src,
57                             size_t src_len,
58                             int16_t* dst,
59                             size_t dst_len,
60                             int sample_rate,
61                             int num_channels);
62
63  int set_stream_delay_ms(int delay_ms);
64
65 private:
66  rtc::scoped_refptr<webrtc::AudioProcessing> apm_;
67};
68
69std::unique_ptr<AudioProcessingModule> create_apm(
70    bool echo_canceller_enabled,
71    bool gain_controller_enabled,
72    bool high_pass_filter_enabled,
73    bool noise_suppression_enabled);
74
75}  // namespace livekit