Skip to content

Commit fdbbada

Browse files
jonexCommit Bot
authored and
Commit Bot
committed
Revert "Inlines NullAudioPoller functionality into AudioState class."
This reverts commit 0e96535. Reason for revert: Downstream test failure Original change's description: > Inlines NullAudioPoller functionality into AudioState class. > > As part of this, we also use TaskQueue and RepeatedTask rather > than rtc::Thread + rtc::MessageHandler. With the ultimate goal of > deprecating rtc::Thread. > > Bug: webrtc:9883 > Change-Id: I2fb851ac31ee2431435d51de78ff446572512201 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167528 > Commit-Queue: Sebastian Jansson <srte@webrtc.org> > Reviewed-by: Sam Zackrisson <saza@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#30430} TBR=saza@webrtc.org,srte@webrtc.org Change-Id: I4c77259f7b6477fc1cb79350f2d47817f106770d No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: webrtc:9883 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168046 Reviewed-by: Sebastian Jansson <srte@webrtc.org> Commit-Queue: Sebastian Jansson <srte@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30431}
1 parent 0e96535 commit fdbbada

File tree

5 files changed

+118
-28
lines changed

5 files changed

+118
-28
lines changed

audio/BUILD.gn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ rtc_library("audio") {
2929
"channel_send.cc",
3030
"channel_send.h",
3131
"conversion.h",
32+
"null_audio_poller.cc",
33+
"null_audio_poller.h",
3234
"remix_resample.cc",
3335
"remix_resample.h",
3436
]
@@ -80,7 +82,6 @@ rtc_library("audio") {
8082
"../rtc_base:rtc_task_queue",
8183
"../rtc_base:safe_minmax",
8284
"../rtc_base/experiments:field_trial_parser",
83-
"../rtc_base/task_utils:repeating_task",
8485
"../system_wrappers",
8586
"../system_wrappers:field_trial",
8687
"../system_wrappers:metrics",

audio/audio_state.cc

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ AudioState::~AudioState() {
3838
RTC_DCHECK(thread_checker_.IsCurrent());
3939
RTC_DCHECK(receiving_streams_.empty());
4040
RTC_DCHECK(sending_streams_.empty());
41-
null_audio_poller_.Stop();
4241
}
4342

4443
AudioProcessing* AudioState::audio_processing() {
@@ -177,31 +176,10 @@ void AudioState::UpdateNullAudioPollerState() {
177176
// Run NullAudioPoller when there are receiving streams and playout is
178177
// disabled.
179178
if (!receiving_streams_.empty() && !playout_enabled_) {
180-
if (!null_audio_poller_.Running()) {
181-
// TODO(srte): Replace current thread with an explicit task queue
182-
// instance.
183-
null_audio_poller_ =
184-
RepeatingTaskHandle::Start(rtc::Thread::Current(), [this] {
185-
// WebRTC uses 10ms audio windows by default
186-
constexpr TimeDelta kPollInterval = TimeDelta::ms(10);
187-
constexpr Frequency kSampleRate = Frequency::kHz(48);
188-
constexpr size_t kSamplesPerPoll =
189-
static_cast<size_t>(kSampleRate * kPollInterval);
190-
constexpr size_t kNumChannels = 1;
191-
int16_t audio_sample_buffer[kSamplesPerPoll * kNumChannels];
192-
// Output variables from |NeedMorePlayData|.
193-
size_t n_samples;
194-
int64_t elapsed_time_ms;
195-
int64_t ntp_time_ms;
196-
audio_transport_.NeedMorePlayData(kSamplesPerPoll, sizeof(int16_t),
197-
kNumChannels, kSampleRate.hertz(),
198-
audio_sample_buffer, n_samples,
199-
&elapsed_time_ms, &ntp_time_ms);
200-
return kPollInterval;
201-
});
202-
}
179+
if (!null_audio_poller_)
180+
null_audio_poller_ = std::make_unique<NullAudioPoller>(&audio_transport_);
203181
} else {
204-
null_audio_poller_.Stop();
182+
null_audio_poller_.reset();
205183
}
206184
}
207185
} // namespace internal

audio/audio_state.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
#include <unordered_set>
1717

1818
#include "audio/audio_transport_impl.h"
19+
#include "audio/null_audio_poller.h"
1920
#include "call/audio_state.h"
2021
#include "rtc_base/constructor_magic.h"
2122
#include "rtc_base/critical_section.h"
2223
#include "rtc_base/ref_count.h"
23-
#include "rtc_base/task_utils/repeating_task.h"
2424
#include "rtc_base/thread_checker.h"
2525

2626
namespace webrtc {
@@ -75,7 +75,7 @@ class AudioState : public webrtc::AudioState {
7575
// Null audio poller is used to continue polling the audio streams if audio
7676
// playout is disabled so that audio processing still happens and the audio
7777
// stats are still updated.
78-
RepeatingTaskHandle null_audio_poller_;
78+
std::unique_ptr<NullAudioPoller> null_audio_poller_;
7979

8080
std::unordered_set<webrtc::AudioReceiveStream*> receiving_streams_;
8181
struct StreamProperties {

audio/null_audio_poller.cc

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2017 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+
#include "audio/null_audio_poller.h"
12+
13+
#include <stddef.h>
14+
15+
#include "rtc_base/checks.h"
16+
#include "rtc_base/location.h"
17+
#include "rtc_base/thread.h"
18+
#include "rtc_base/time_utils.h"
19+
20+
namespace webrtc {
21+
namespace internal {
22+
23+
namespace {
24+
25+
constexpr int64_t kPollDelayMs = 10; // WebRTC uses 10ms by default
26+
27+
constexpr size_t kNumChannels = 1;
28+
constexpr uint32_t kSamplesPerSecond = 48000; // 48kHz
29+
constexpr size_t kNumSamples = kSamplesPerSecond / 100; // 10ms of samples
30+
31+
} // namespace
32+
33+
NullAudioPoller::NullAudioPoller(AudioTransport* audio_transport)
34+
: audio_transport_(audio_transport),
35+
reschedule_at_(rtc::TimeMillis() + kPollDelayMs) {
36+
RTC_DCHECK(audio_transport);
37+
OnMessage(nullptr); // Start the poll loop.
38+
}
39+
40+
NullAudioPoller::~NullAudioPoller() {
41+
RTC_DCHECK(thread_checker_.IsCurrent());
42+
rtc::Thread::Current()->Clear(this);
43+
}
44+
45+
void NullAudioPoller::OnMessage(rtc::Message* msg) {
46+
RTC_DCHECK(thread_checker_.IsCurrent());
47+
48+
// Buffer to hold the audio samples.
49+
int16_t buffer[kNumSamples * kNumChannels];
50+
// Output variables from |NeedMorePlayData|.
51+
size_t n_samples;
52+
int64_t elapsed_time_ms;
53+
int64_t ntp_time_ms;
54+
audio_transport_->NeedMorePlayData(kNumSamples, sizeof(int16_t), kNumChannels,
55+
kSamplesPerSecond, buffer, n_samples,
56+
&elapsed_time_ms, &ntp_time_ms);
57+
58+
// Reschedule the next poll iteration. If, for some reason, the given
59+
// reschedule time has already passed, reschedule as soon as possible.
60+
int64_t now = rtc::TimeMillis();
61+
if (reschedule_at_ < now) {
62+
reschedule_at_ = now;
63+
}
64+
rtc::Thread::Current()->PostAt(RTC_FROM_HERE, reschedule_at_, this, 0);
65+
66+
// Loop after next will be kPollDelayMs later.
67+
reschedule_at_ += kPollDelayMs;
68+
}
69+
70+
} // namespace internal
71+
} // namespace webrtc

audio/null_audio_poller.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2017 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_NULL_AUDIO_POLLER_H_
12+
#define AUDIO_NULL_AUDIO_POLLER_H_
13+
14+
#include <stdint.h>
15+
16+
#include "modules/audio_device/include/audio_device_defines.h"
17+
#include "rtc_base/message_handler.h"
18+
#include "rtc_base/thread_checker.h"
19+
20+
namespace webrtc {
21+
namespace internal {
22+
23+
class NullAudioPoller final : public rtc::MessageHandler {
24+
public:
25+
explicit NullAudioPoller(AudioTransport* audio_transport);
26+
~NullAudioPoller() override;
27+
28+
protected:
29+
void OnMessage(rtc::Message* msg) override;
30+
31+
private:
32+
rtc::ThreadChecker thread_checker_;
33+
AudioTransport* const audio_transport_;
34+
int64_t reschedule_at_;
35+
};
36+
37+
} // namespace internal
38+
} // namespace webrtc
39+
40+
#endif // AUDIO_NULL_AUDIO_POLLER_H_

0 commit comments

Comments
 (0)