BlueGit

ict rusty-teams

Files

rusty-teams / vendor / webrtc-sys / libwebrtc / patches / external_audio_source.patch

external_audio_source.patch

external_audio_source.patch 5.8 KiB Download Raw
1diff --git a/api/media_stream_interface.h b/api/media_stream_interface.h
2index 643b5f273b..7b5b568692 100644
3--- a/api/media_stream_interface.h
4+++ b/api/media_stream_interface.h
5@@ -270,6 +270,11 @@ class RTC_EXPORT AudioSourceInterface : public MediaSourceInterface {
6 // audio network adaptation on the source is the wrong layer of abstraction).
7 virtual const AudioOptions options() const;
8 virtual void SetOptions(const AudioOptions & /* options */) {}
9+
10+ // Returns true if this source delivers audio externally (via AddSink),
11+ // bypassing the ADM/AudioState audio distribution path.
12+ // When true, AudioSendStream should not register with AudioState.
13+ virtual bool is_external_source() const { return false; }
14 };
15
16 // Interface of the audio processor used by the audio track to collect
17diff --git a/audio/audio_send_stream.cc b/audio/audio_send_stream.cc
18index e9e72b48e7..ca21052ff7 100644
19--- a/audio/audio_send_stream.cc
20+++ b/audio/audio_send_stream.cc
21@@ -377,8 +377,13 @@ void AudioSendStream::Start() {
22 }
23 channel_send_->StartSend();
24 sending_ = true;
25- audio_state()->AddSendingStream(this, encoder_sample_rate_hz_,
26- encoder_num_channels_);
27+ // Only register with AudioState if not using external source.
28+ // External sources (like NativeAudioSource) deliver audio directly via AddSink,
29+ // so we don't want AudioState to also send device audio to this stream.
30+ if (!config_.external_source) {
31+ audio_state()->AddSendingStream(this, encoder_sample_rate_hz_,
32+ encoder_num_channels_);
33+ }
34 }
35
36 void AudioSendStream::Stop() {
37@@ -389,8 +394,10 @@ void AudioSendStream::Stop() {
38 RTC_LOG(LS_INFO) << "AudioSendStream::Stop: " << config_.rtp.ssrc;
39 RemoveBitrateObserver();
40 channel_send_->StopSend();
41- sending_ = false;
42- audio_state()->RemoveSendingStream(this);
43+ // Only unregister if we registered (when not using external source).
44+ if (!config_.external_source) {
45+ audio_state()->RemoveSendingStream(this);
46+ }
47 }
48
49 void AudioSendStream::SendAudioData(std::unique_ptr<AudioFrame> audio_frame) {
50diff --git a/call/audio_send_stream.h b/call/audio_send_stream.h
51index 40bfd812a4..a482b16d70 100644
52--- a/call/audio_send_stream.h
53+++ b/call/audio_send_stream.h
54@@ -176,6 +176,12 @@ class AudioSendStream : public AudioSender {
55 // An optional frame transformer used by insertable streams to transform
56 // encoded frames.
57 scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer;
58+
59+ // When true, this stream uses an external audio source (not ADM).
60+ // AudioState will NOT send device-captured audio to this stream.
61+ // Audio is delivered directly via the source's AddSink mechanism.
62+ // This prevents mixing of device audio with externally-sourced audio.
63+ bool external_source = false;
64 };
65
66 ~AudioSendStream() override = default;
67diff --git a/media/base/audio_source.h b/media/base/audio_source.h
68index 04a7d19dfa..9f513f3c75 100644
69--- a/media/base/audio_source.h
70+++ b/media/base/audio_source.h
71@@ -49,6 +49,10 @@ class AudioSource {
72 // to the source at a time.
73 virtual void SetSink(Sink* sink) = 0;
74
75+ // Returns true if this source delivers audio externally (bypassing ADM).
76+ // When true, AudioSendStream should not register with AudioState.
77+ virtual bool is_external_source() const { return false; }
78+
79 protected:
80 virtual ~AudioSource() {}
81 };
82diff --git a/media/engine/webrtc_voice_engine.cc b/media/engine/webrtc_voice_engine.cc
83index 38a3a2f2d9..e3a3bfdfe7 100644
84--- a/media/engine/webrtc_voice_engine.cc
85+++ b/media/engine/webrtc_voice_engine.cc
86@@ -936,6 +936,14 @@ class WebRtcVoiceSendChannel::WebRtcAudioSendStream : public AudioSource::Sink {
87 RTC_DCHECK(source_ == source);
88 return;
89 }
90+
91+ // Check if this is an external audio source (delivers audio via AddSink).
92+ // If so, mark the config so AudioState doesn't send device audio to this
93+ // stream. This must be done before UpdateSendState() calls Start().
94+ if (source->is_external_source() && !config_.external_source) {
95+ config_.external_source = true;
96+ stream_->Reconfigure(config_, nullptr);
97+ }
98 source->SetSink(this);
99 source_ = source;
100 UpdateSendState();
101diff --git a/pc/rtp_sender.cc b/pc/rtp_sender.cc
102index b360be5ec6..55f8bcfb87 100644
103--- a/pc/rtp_sender.cc
104+++ b/pc/rtp_sender.cc
105@@ -1265,6 +1265,13 @@ void AudioRtpSender::SetSend() {
106 if (stopped_) {
107 return;
108 }
109+
110+ // Propagate is_external_source from AudioSourceInterface to the sink adapter.
111+ // This ensures the voice engine knows not to mix ADM audio with external sources.
112+ if (audio_track()->GetSource() && audio_track()->GetSource()->is_external_source()) {
113+ sink_adapter_->set_is_external_source(true);
114+ }
115+
116 AudioOptions options;
117 const bool track_enabled = track_->enabled();
118 std::optional<AudioOptions> track_source_options;
119diff --git a/pc/rtp_sender.h b/pc/rtp_sender.h
120index a8f3bbd08a..85ab34497e 100644
121--- a/pc/rtp_sender.h
122+++ b/pc/rtp_sender.h
123@@ -368,6 +368,12 @@ class LocalAudioSinkAdapter : public AudioTrackSinkInterface,
124 LocalAudioSinkAdapter();
125 ~LocalAudioSinkAdapter() override;
126
127+ // Set whether the original AudioSourceInterface is an external source.
128+ // This propagates the is_external_source state from AudioSourceInterface
129+ // to this AudioSource adapter.
130+ void set_is_external_source(bool value) { is_external_source_ = value; }
131+ bool is_external_source() const override { return is_external_source_; }
132+
133 private:
134 // AudioSinkInterface implementation.
135 void OnData(const void* audio_data,
136@@ -398,6 +404,7 @@ class LocalAudioSinkAdapter : public AudioTrackSinkInterface,
137 // Critical section protecting `sink_`.
138 Mutex lock_;
139 int num_preferred_channels_ = -1;
140+ bool is_external_source_ = false;
141 };
142
143 class AudioRtpSender : public DtmfProviderInterface, public RtpSenderBase {