webrtc_m130/audio/null_audio_poller.cc
Oleh Prypin 96a0f61917 Revert "[cleanup] Remove useless includes."
This reverts commit be8b5348c76105f8fe869b0cae4065ddca106419.

Reason for revert: Breaks downstream project

Original change's description:
> [cleanup] Remove useless includes.
> 
> Manual cleanup guided by include-what-you-use diagnostic.
> 
> Bug: webrtc:8311
> Change-Id: I00be03392cc7ee005101427ea7dc701621ccea68
> Reviewed-on: https://webrtc-review.googlesource.com/c/103320
> Commit-Queue: Yves Gerey <yvesg@webrtc.org>
> Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#25013}

TBR=phoglund@google.com,phoglund@webrtc.org,yvesg@webrtc.org

Change-Id: I7a6e1cdfef685173b76f234ad598083043dcd9a0
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:8311
Reviewed-on: https://webrtc-review.googlesource.com/c/104022
Reviewed-by: Oleh Prypin <oprypin@webrtc.org>
Commit-Queue: Oleh Prypin <oprypin@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25015}
2018-10-05 13:13:45 +00:00

67 lines
2.1 KiB
C++

/*
* Copyright (c) 2017 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.
*/
#include "audio/null_audio_poller.h"
#include "rtc_base/logging.h"
#include "rtc_base/thread.h"
namespace webrtc {
namespace internal {
namespace {
constexpr int64_t kPollDelayMs = 10; // WebRTC uses 10ms by default
constexpr size_t kNumChannels = 1;
constexpr uint32_t kSamplesPerSecond = 48000; // 48kHz
constexpr size_t kNumSamples = kSamplesPerSecond / 100; // 10ms of samples
} // namespace
NullAudioPoller::NullAudioPoller(AudioTransport* audio_transport)
: audio_transport_(audio_transport),
reschedule_at_(rtc::TimeMillis() + kPollDelayMs) {
RTC_DCHECK(audio_transport);
OnMessage(nullptr); // Start the poll loop.
}
NullAudioPoller::~NullAudioPoller() {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
rtc::Thread::Current()->Clear(this);
}
void NullAudioPoller::OnMessage(rtc::Message* msg) {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
// Buffer to hold the audio samples.
int16_t buffer[kNumSamples * kNumChannels];
// Output variables from |NeedMorePlayData|.
size_t n_samples;
int64_t elapsed_time_ms;
int64_t ntp_time_ms;
audio_transport_->NeedMorePlayData(kNumSamples, sizeof(int16_t), kNumChannels,
kSamplesPerSecond, buffer, n_samples,
&elapsed_time_ms, &ntp_time_ms);
// Reschedule the next poll iteration. If, for some reason, the given
// reschedule time has already passed, reschedule as soon as possible.
int64_t now = rtc::TimeMillis();
if (reschedule_at_ < now) {
reschedule_at_ = now;
}
rtc::Thread::Current()->PostAt(RTC_FROM_HERE, reschedule_at_, this, 0);
// Loop after next will be kPollDelayMs later.
reschedule_at_ += kPollDelayMs;
}
} // namespace internal
} // namespace webrtc