2018-02-13 15:03:43 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018 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 "api/audio/audio_frame.h"
|
|
|
|
|
|
2018-04-16 11:17:10 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2024-06-18 16:20:35 +03:00
|
|
|
#include <cstdint>
|
2024-08-29 13:00:40 +00:00
|
|
|
#include <optional>
|
2024-06-18 16:20:35 +03:00
|
|
|
|
|
|
|
|
#include "api/array_view.h"
|
|
|
|
|
#include "api/audio/audio_view.h"
|
|
|
|
|
#include "api/audio/channel_layout.h"
|
|
|
|
|
#include "api/rtp_packet_infos.h"
|
2018-02-13 15:03:43 +01:00
|
|
|
#include "rtc_base/checks.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/time_utils.h"
|
2018-02-13 15:03:43 +01:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
AudioFrame::AudioFrame() {
|
|
|
|
|
// Visual Studio doesn't like this in the class definition.
|
|
|
|
|
static_assert(sizeof(data_) == kMaxDataSizeBytes, "kMaxDataSizeBytes");
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-30 14:04:44 +02:00
|
|
|
AudioFrame::AudioFrame(int sample_rate_hz,
|
|
|
|
|
size_t num_channels,
|
|
|
|
|
ChannelLayout layout /*= CHANNEL_LAYOUT_UNSUPPORTED*/)
|
|
|
|
|
: samples_per_channel_(SampleRateToDefaultChannelSize(sample_rate_hz)),
|
|
|
|
|
sample_rate_hz_(sample_rate_hz),
|
|
|
|
|
num_channels_(num_channels),
|
|
|
|
|
channel_layout_(layout == CHANNEL_LAYOUT_UNSUPPORTED
|
|
|
|
|
? GuessChannelLayout(num_channels)
|
|
|
|
|
: layout) {
|
|
|
|
|
RTC_DCHECK_LE(num_channels_, kMaxConcurrentChannels);
|
|
|
|
|
RTC_DCHECK_GT(sample_rate_hz_, 0);
|
|
|
|
|
RTC_DCHECK_GT(samples_per_channel_, 0u);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-13 15:03:43 +01:00
|
|
|
void AudioFrame::Reset() {
|
|
|
|
|
ResetWithoutMuting();
|
|
|
|
|
muted_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioFrame::ResetWithoutMuting() {
|
2021-07-25 21:50:14 +02:00
|
|
|
// TODO(wu): Zero is a valid value for `timestamp_`. We should initialize
|
2018-02-13 15:03:43 +01:00
|
|
|
// to an invalid value, or add a new member to indicate invalidity.
|
|
|
|
|
timestamp_ = 0;
|
|
|
|
|
elapsed_time_ms_ = -1;
|
|
|
|
|
ntp_time_ms_ = -1;
|
|
|
|
|
samples_per_channel_ = 0;
|
|
|
|
|
sample_rate_hz_ = 0;
|
|
|
|
|
num_channels_ = 0;
|
2019-07-04 11:27:52 +02:00
|
|
|
channel_layout_ = CHANNEL_LAYOUT_NONE;
|
2018-02-13 15:03:43 +01:00
|
|
|
speech_type_ = kUndefined;
|
|
|
|
|
vad_activity_ = kVadUnknown;
|
|
|
|
|
profile_timestamp_ms_ = 0;
|
Reland "Reland "Add plumbing of RtpPacketInfos to each AudioFrame as input for SourceTracker.""
This reverts commit fab3460a821abe336ab610c6d6dfc0d392dac263.
Reason for revert: fix downstream instead
Original change's description:
> Revert "Reland "Add plumbing of RtpPacketInfos to each AudioFrame as input for SourceTracker.""
>
> This reverts commit 9973933d2e606d64fcdc753acb9ba3afd6e30569.
>
> Reason for revert: breaking downstream projects and not reviewed by direct owners
>
> Original change's description:
> > Reland "Add plumbing of RtpPacketInfos to each AudioFrame as input for SourceTracker."
> >
> > This reverts commit 24192c267a40eb7d6b1850489ccdbf7a84f8ff0f.
> >
> > Reason for revert: Analyzed the performance regression in more detail.
> >
> > Most of the regression comes from the extra RtpPacketInfos-related memory allocations in every `NetEq::GetAudio()` call. Commit 1796a820f60cb9429bf4bcf13a40a41794ac8fb0 has removed roughly 2/3rds of the extra allocations from the impacted perf tests. Remaining perf impact is expected to be about "8 microseconds of CPU time per second" on the Linux benchmarking machines and "15 us per second" on Windows/Mac.
> >
> > There are options to optimize further but they are unlikely worth doing. Note for example that `NetEqPerformanceTest` uses the PCM codec while the real-world use cases would likely use the much heavier Opus codec. The numbers from `OpusSpeedTest` and `NetEqPerformanceTest` suggest that Opus decoding is about 10x as expensive as NetEq overall.
> >
> > Original change's description:
> > > Revert "Add plumbing of RtpPacketInfos to each AudioFrame as input for SourceTracker."
> > >
> > > This reverts commit 3e8ef940fe86cf6285afb80e68d2a0bedc631b9f.
> > >
> > > Reason for revert: This CL causes a performance regression in NetEq, see https://bugs.chromium.org/p/chromium/issues/detail?id=982260.
> > >
> > > Original change's description:
> > > > Add plumbing of RtpPacketInfos to each AudioFrame as input for SourceTracker.
> > > >
> > > > This change adds the plumbing of RtpPacketInfo from ChannelReceive::OnRtpPacket() to ChannelReceive::GetAudioFrameWithInfo() for audio. It is a step towards replacing the non-spec compliant ContributingSources that updates itself at packet-receive time, with the spec-compliant SourceTracker that will update itself at frame-delivery-to-track time.
> > > >
> > > > Bug: webrtc:10668
> > > > Change-Id: I03385d6865bbc7bfbef7634f88de820a934f787a
> > > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/139890
> > > > Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> > > > Reviewed-by: Minyue Li <minyue@webrtc.org>
> > > > Commit-Queue: Chen Xing <chxg@google.com>
> > > > Cr-Commit-Position: refs/heads/master@{#28434}
> > >
> > > TBR=kwiberg@webrtc.org,stefan@webrtc.org,minyue@webrtc.org,chxg@google.com
> > >
> > > Bug: webrtc:10668, chromium:982260
> > > Change-Id: I5e2cfde78c59d1123e21869564d76ed3f6193a5c
> > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/145339
> > > Reviewed-by: Ivo Creusen <ivoc@webrtc.org>
> > > Commit-Queue: Ivo Creusen <ivoc@webrtc.org>
> > > Cr-Commit-Position: refs/heads/master@{#28561}
> >
> > TBR=kwiberg@webrtc.org,stefan@webrtc.org,ivoc@webrtc.org,minyue@webrtc.org,chxg@google.com
> >
> > # Not skipping CQ checks because original CL landed > 1 day ago.
> >
> > Bug: webrtc:10668, chromium:982260
> > Change-Id: Ie375a0b327ee368317bf3a04b2f1415c3a974470
> > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/146707
> > Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> > Commit-Queue: Chen Xing <chxg@google.com>
> > Cr-Commit-Position: refs/heads/master@{#28664}
>
> TBR=kwiberg@webrtc.org,stefan@webrtc.org,ivoc@webrtc.org,minyue@webrtc.org,chxg@google.com
>
> Change-Id: I652cb0814d83b514d3bee34e65ca3bb693099b22
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:10668, chromium:982260
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/146712
> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
> Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#28671}
TBR=alessiob@webrtc.org,kwiberg@webrtc.org,stefan@webrtc.org,ivoc@webrtc.org,minyue@webrtc.org,chxg@google.com
Change-Id: Id43b7b3da79b4f48004b41767482bae1c1fa1e16
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:10668, chromium:982260
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/146713
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28672}
2019-07-24 16:47:02 +00:00
|
|
|
packet_infos_ = RtpPacketInfos();
|
2024-08-29 13:00:40 +00:00
|
|
|
absolute_capture_timestamp_ms_ = std::nullopt;
|
2018-02-13 15:03:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioFrame::UpdateFrame(uint32_t timestamp,
|
2018-04-11 13:00:18 +02:00
|
|
|
const int16_t* data,
|
|
|
|
|
size_t samples_per_channel,
|
|
|
|
|
int sample_rate_hz,
|
|
|
|
|
SpeechType speech_type,
|
|
|
|
|
VADActivity vad_activity,
|
|
|
|
|
size_t num_channels) {
|
2024-04-30 14:04:44 +02:00
|
|
|
RTC_CHECK_LE(num_channels, kMaxConcurrentChannels);
|
2018-02-13 15:03:43 +01:00
|
|
|
timestamp_ = timestamp;
|
|
|
|
|
samples_per_channel_ = samples_per_channel;
|
|
|
|
|
sample_rate_hz_ = sample_rate_hz;
|
|
|
|
|
speech_type_ = speech_type;
|
|
|
|
|
vad_activity_ = vad_activity;
|
|
|
|
|
num_channels_ = num_channels;
|
2019-07-04 11:27:52 +02:00
|
|
|
channel_layout_ = GuessChannelLayout(num_channels);
|
|
|
|
|
if (channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED) {
|
|
|
|
|
RTC_DCHECK_EQ(num_channels, ChannelLayoutToChannelCount(channel_layout_));
|
|
|
|
|
}
|
2018-02-13 15:03:43 +01:00
|
|
|
|
|
|
|
|
const size_t length = samples_per_channel * num_channels;
|
2024-05-29 09:52:55 +02:00
|
|
|
RTC_CHECK_LE(length, data_.size());
|
2018-02-13 15:03:43 +01:00
|
|
|
if (data != nullptr) {
|
2024-05-29 09:52:55 +02:00
|
|
|
memcpy(data_.data(), data, sizeof(int16_t) * length);
|
2018-02-13 15:03:43 +01:00
|
|
|
muted_ = false;
|
|
|
|
|
} else {
|
|
|
|
|
muted_ = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioFrame::CopyFrom(const AudioFrame& src) {
|
|
|
|
|
if (this == &src)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-04-30 20:13:29 +02:00
|
|
|
if (muted_ && !src.muted()) {
|
|
|
|
|
// TODO: bugs.webrtc.org/5647 - Since the default value for `muted_` is
|
|
|
|
|
// false and `data_` may still be uninitialized (because we don't initialize
|
|
|
|
|
// data_ as part of construction), we clear the full buffer here before
|
|
|
|
|
// copying over new values. If we don't, msan might complain in some tests.
|
|
|
|
|
// Consider locking down construction, avoiding the default constructor and
|
|
|
|
|
// prefering construction that initializes all state.
|
2024-05-29 09:52:55 +02:00
|
|
|
ClearSamples(data_);
|
2024-04-30 20:13:29 +02:00
|
|
|
}
|
|
|
|
|
|
2018-02-13 15:03:43 +01:00
|
|
|
timestamp_ = src.timestamp_;
|
|
|
|
|
elapsed_time_ms_ = src.elapsed_time_ms_;
|
|
|
|
|
ntp_time_ms_ = src.ntp_time_ms_;
|
Reland "Reland "Add plumbing of RtpPacketInfos to each AudioFrame as input for SourceTracker.""
This reverts commit fab3460a821abe336ab610c6d6dfc0d392dac263.
Reason for revert: fix downstream instead
Original change's description:
> Revert "Reland "Add plumbing of RtpPacketInfos to each AudioFrame as input for SourceTracker.""
>
> This reverts commit 9973933d2e606d64fcdc753acb9ba3afd6e30569.
>
> Reason for revert: breaking downstream projects and not reviewed by direct owners
>
> Original change's description:
> > Reland "Add plumbing of RtpPacketInfos to each AudioFrame as input for SourceTracker."
> >
> > This reverts commit 24192c267a40eb7d6b1850489ccdbf7a84f8ff0f.
> >
> > Reason for revert: Analyzed the performance regression in more detail.
> >
> > Most of the regression comes from the extra RtpPacketInfos-related memory allocations in every `NetEq::GetAudio()` call. Commit 1796a820f60cb9429bf4bcf13a40a41794ac8fb0 has removed roughly 2/3rds of the extra allocations from the impacted perf tests. Remaining perf impact is expected to be about "8 microseconds of CPU time per second" on the Linux benchmarking machines and "15 us per second" on Windows/Mac.
> >
> > There are options to optimize further but they are unlikely worth doing. Note for example that `NetEqPerformanceTest` uses the PCM codec while the real-world use cases would likely use the much heavier Opus codec. The numbers from `OpusSpeedTest` and `NetEqPerformanceTest` suggest that Opus decoding is about 10x as expensive as NetEq overall.
> >
> > Original change's description:
> > > Revert "Add plumbing of RtpPacketInfos to each AudioFrame as input for SourceTracker."
> > >
> > > This reverts commit 3e8ef940fe86cf6285afb80e68d2a0bedc631b9f.
> > >
> > > Reason for revert: This CL causes a performance regression in NetEq, see https://bugs.chromium.org/p/chromium/issues/detail?id=982260.
> > >
> > > Original change's description:
> > > > Add plumbing of RtpPacketInfos to each AudioFrame as input for SourceTracker.
> > > >
> > > > This change adds the plumbing of RtpPacketInfo from ChannelReceive::OnRtpPacket() to ChannelReceive::GetAudioFrameWithInfo() for audio. It is a step towards replacing the non-spec compliant ContributingSources that updates itself at packet-receive time, with the spec-compliant SourceTracker that will update itself at frame-delivery-to-track time.
> > > >
> > > > Bug: webrtc:10668
> > > > Change-Id: I03385d6865bbc7bfbef7634f88de820a934f787a
> > > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/139890
> > > > Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> > > > Reviewed-by: Minyue Li <minyue@webrtc.org>
> > > > Commit-Queue: Chen Xing <chxg@google.com>
> > > > Cr-Commit-Position: refs/heads/master@{#28434}
> > >
> > > TBR=kwiberg@webrtc.org,stefan@webrtc.org,minyue@webrtc.org,chxg@google.com
> > >
> > > Bug: webrtc:10668, chromium:982260
> > > Change-Id: I5e2cfde78c59d1123e21869564d76ed3f6193a5c
> > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/145339
> > > Reviewed-by: Ivo Creusen <ivoc@webrtc.org>
> > > Commit-Queue: Ivo Creusen <ivoc@webrtc.org>
> > > Cr-Commit-Position: refs/heads/master@{#28561}
> >
> > TBR=kwiberg@webrtc.org,stefan@webrtc.org,ivoc@webrtc.org,minyue@webrtc.org,chxg@google.com
> >
> > # Not skipping CQ checks because original CL landed > 1 day ago.
> >
> > Bug: webrtc:10668, chromium:982260
> > Change-Id: Ie375a0b327ee368317bf3a04b2f1415c3a974470
> > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/146707
> > Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> > Commit-Queue: Chen Xing <chxg@google.com>
> > Cr-Commit-Position: refs/heads/master@{#28664}
>
> TBR=kwiberg@webrtc.org,stefan@webrtc.org,ivoc@webrtc.org,minyue@webrtc.org,chxg@google.com
>
> Change-Id: I652cb0814d83b514d3bee34e65ca3bb693099b22
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:10668, chromium:982260
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/146712
> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
> Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#28671}
TBR=alessiob@webrtc.org,kwiberg@webrtc.org,stefan@webrtc.org,ivoc@webrtc.org,minyue@webrtc.org,chxg@google.com
Change-Id: Id43b7b3da79b4f48004b41767482bae1c1fa1e16
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:10668, chromium:982260
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/146713
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28672}
2019-07-24 16:47:02 +00:00
|
|
|
packet_infos_ = src.packet_infos_;
|
2018-02-13 15:03:43 +01:00
|
|
|
muted_ = src.muted();
|
|
|
|
|
samples_per_channel_ = src.samples_per_channel_;
|
|
|
|
|
sample_rate_hz_ = src.sample_rate_hz_;
|
|
|
|
|
speech_type_ = src.speech_type_;
|
|
|
|
|
vad_activity_ = src.vad_activity_;
|
|
|
|
|
num_channels_ = src.num_channels_;
|
2019-07-04 11:27:52 +02:00
|
|
|
channel_layout_ = src.channel_layout_;
|
2020-02-18 15:45:41 +01:00
|
|
|
absolute_capture_timestamp_ms_ = src.absolute_capture_timestamp_ms();
|
2018-02-13 15:03:43 +01:00
|
|
|
|
2024-04-30 20:13:29 +02:00
|
|
|
auto data = src.data_view();
|
2024-05-29 09:52:55 +02:00
|
|
|
RTC_CHECK_LE(data.size(), data_.size());
|
2024-04-30 20:13:29 +02:00
|
|
|
if (!muted_ && !data.empty()) {
|
|
|
|
|
memcpy(&data_[0], &data[0], sizeof(int16_t) * data.size());
|
2018-02-13 15:03:43 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioFrame::UpdateProfileTimeStamp() {
|
|
|
|
|
profile_timestamp_ms_ = rtc::TimeMillis();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64_t AudioFrame::ElapsedProfileTimeMs() const {
|
|
|
|
|
if (profile_timestamp_ms_ == 0) {
|
|
|
|
|
// Profiling has not been activated.
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return rtc::TimeSince(profile_timestamp_ms_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int16_t* AudioFrame::data() const {
|
2024-05-29 09:52:55 +02:00
|
|
|
return muted_ ? zeroed_data().begin() : data_.data();
|
2024-04-30 14:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-24 16:43:55 +02:00
|
|
|
InterleavedView<const int16_t> AudioFrame::data_view() const {
|
2024-04-30 14:04:44 +02:00
|
|
|
// If you get a nullptr from `data_view()`, it's likely because the
|
2024-05-24 16:43:55 +02:00
|
|
|
// samples_per_channel_ and/or num_channels_ members haven't been properly
|
|
|
|
|
// set. Since `data_view()` returns an InterleavedView<> (which internally
|
|
|
|
|
// uses rtc::ArrayView<>), we inherit the behavior in InterleavedView when the
|
|
|
|
|
// view size is 0 that ArrayView<>::data() returns nullptr. So, even when an
|
|
|
|
|
// AudioFrame is muted and we want to return `zeroed_data()`, if
|
|
|
|
|
// samples_per_channel_ or num_channels_ is 0, the view will point to
|
|
|
|
|
// nullptr.
|
|
|
|
|
return InterleavedView<const int16_t>(muted_ ? &zeroed_data()[0] : &data_[0],
|
|
|
|
|
samples_per_channel_, num_channels_);
|
2018-02-13 15:03:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int16_t* AudioFrame::mutable_data() {
|
2024-04-30 14:04:44 +02:00
|
|
|
// TODO: bugs.webrtc.org/5647 - Can we skip zeroing the buffer?
|
|
|
|
|
// Consider instead if we should rather zero the buffer when `muted_` is set
|
|
|
|
|
// to `true`.
|
2018-02-13 15:03:43 +01:00
|
|
|
if (muted_) {
|
2024-05-29 09:52:55 +02:00
|
|
|
ClearSamples(data_);
|
2018-02-13 15:03:43 +01:00
|
|
|
muted_ = false;
|
|
|
|
|
}
|
2024-05-29 09:52:55 +02:00
|
|
|
return &data_[0];
|
2018-02-13 15:03:43 +01:00
|
|
|
}
|
|
|
|
|
|
2024-05-24 16:43:55 +02:00
|
|
|
InterleavedView<int16_t> AudioFrame::mutable_data(size_t samples_per_channel,
|
|
|
|
|
size_t num_channels) {
|
2024-04-30 14:04:44 +02:00
|
|
|
const size_t total_samples = samples_per_channel * num_channels;
|
2024-05-29 09:52:55 +02:00
|
|
|
RTC_CHECK_LE(total_samples, data_.size());
|
2024-04-30 14:04:44 +02:00
|
|
|
RTC_CHECK_LE(num_channels, kMaxConcurrentChannels);
|
|
|
|
|
// Sanity check for valid argument values during development.
|
2024-04-30 20:13:29 +02:00
|
|
|
// If `samples_per_channel` is < `num_channels` but larger than 0,
|
2024-04-30 14:04:44 +02:00
|
|
|
// then chances are the order of arguments is incorrect.
|
|
|
|
|
RTC_DCHECK((samples_per_channel == 0 && num_channels == 0) ||
|
2024-04-30 20:13:29 +02:00
|
|
|
num_channels <= samples_per_channel)
|
|
|
|
|
<< "samples_per_channel=" << samples_per_channel
|
|
|
|
|
<< "num_channels=" << num_channels;
|
2024-04-30 14:04:44 +02:00
|
|
|
|
|
|
|
|
// TODO: bugs.webrtc.org/5647 - Can we skip zeroing the buffer?
|
|
|
|
|
// Consider instead if we should rather zero the whole buffer when `muted_` is
|
|
|
|
|
// set to `true`.
|
|
|
|
|
if (muted_) {
|
2024-05-29 09:52:55 +02:00
|
|
|
ClearSamples(data_, total_samples);
|
2024-04-30 14:04:44 +02:00
|
|
|
muted_ = false;
|
|
|
|
|
}
|
|
|
|
|
samples_per_channel_ = samples_per_channel;
|
|
|
|
|
num_channels_ = num_channels;
|
2024-05-24 16:43:55 +02:00
|
|
|
return InterleavedView<int16_t>(&data_[0], samples_per_channel, num_channels);
|
2024-04-30 14:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
2018-02-13 15:03:43 +01:00
|
|
|
void AudioFrame::Mute() {
|
|
|
|
|
muted_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AudioFrame::muted() const {
|
|
|
|
|
return muted_;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-29 23:44:23 +02:00
|
|
|
void AudioFrame::SetLayoutAndNumChannels(ChannelLayout layout,
|
|
|
|
|
size_t num_channels) {
|
|
|
|
|
channel_layout_ = layout;
|
|
|
|
|
num_channels_ = num_channels;
|
|
|
|
|
#if RTC_DCHECK_IS_ON
|
|
|
|
|
// Do a sanity check that the layout and num_channels match.
|
|
|
|
|
// If this lookup yield 0u, then the layout is likely CHANNEL_LAYOUT_DISCRETE.
|
|
|
|
|
auto expected_num_channels = ChannelLayoutToChannelCount(layout);
|
|
|
|
|
if (expected_num_channels) { // If expected_num_channels is 0
|
|
|
|
|
RTC_DCHECK_EQ(expected_num_channels, num_channels_);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2024-05-29 09:52:55 +02:00
|
|
|
RTC_CHECK_LE(samples_per_channel_ * num_channels_, data_.size());
|
2024-04-29 23:44:23 +02:00
|
|
|
}
|
|
|
|
|
|
2024-04-30 14:04:44 +02:00
|
|
|
void AudioFrame::SetSampleRateAndChannelSize(int sample_rate) {
|
|
|
|
|
sample_rate_hz_ = sample_rate;
|
|
|
|
|
// We could call `AudioProcessing::GetFrameSize()` here, but that requires
|
|
|
|
|
// adding a dependency on the ":audio_processing" build target, which can
|
|
|
|
|
// complicate the dependency tree. Some refactoring is probably in order to
|
|
|
|
|
// get some consistency around this since there are many places across the
|
|
|
|
|
// code that assume this default buffer size.
|
|
|
|
|
samples_per_channel_ = SampleRateToDefaultChannelSize(sample_rate_hz_);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-13 15:03:43 +01:00
|
|
|
// static
|
2024-04-30 14:04:44 +02:00
|
|
|
rtc::ArrayView<const int16_t> AudioFrame::zeroed_data() {
|
2018-04-20 12:35:14 +02:00
|
|
|
static int16_t* null_data = new int16_t[kMaxDataSizeSamples]();
|
2024-04-30 14:04:44 +02:00
|
|
|
return rtc::ArrayView<const int16_t>(null_data, kMaxDataSizeSamples);
|
2018-02-13 15:03:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|