AudioFrame::AudioFrame() { // Visual Studio doesn't like this in the class definition.
static_assert(sizeof(data_) == kMaxDataSizeBytes, "kMaxDataSizeBytes");
}
void AudioFrame::ResetWithoutMuting() { // TODO(wu): Zero is a valid value for `timestamp_`. We should initialize // 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;
channel_layout_ = CHANNEL_LAYOUT_NONE;
speech_type_ = kUndefined;
vad_activity_ = kVadUnknown;
packet_infos_ = RtpPacketInfos();
absolute_capture_timestamp_ms_ = std::nullopt;
}
void AudioFrame::CopyFrom(const AudioFrame& src) {
if (this == &src) return;
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.
absl::c_fill(data_, 0);
}
InterleavedView<const int16_t> AudioFrame::data_view() const { // If you get a nullptr from `data_view()`, it's likely because the // samples_per_channel_ and/or num_channels_ members haven't been properly // set. `data_view()` returns an InterleavedView<> which internally // uses std::span<>. 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 might point to nullptr. return InterleavedView<const int16_t>(muted_ ? &zeroed_data()[0] : &data_[='color: green'>0],
samples_per_channel_, num_channels_);
}
int16_t* AudioFrame::mutable_data() { // 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`.
if (muted_) {
absl::c_fill(data_, 0);
muted_ = false;
} return &data_[0];
}
InterleavedView<int16_t> AudioFrame::mutable_data(size_t samples_per_channel,
size_t num_channels) { const size_t total_samples = samples_per_channel * num_channels;
RTC_CHECK_LE(total_samples, data_.size());
RTC_CHECK_LE(num_channels, kMaxNumberOfAudioChannels); // Sanity check for valid argument values during development. // If `samples_per_channel` is < `num_channels` but larger than 0, // then chances are the order of arguments is incorrect.
RTC_DCHECK((samples_per_channel == 0 && num_channels == 0) ||
num_channels <= samples_per_channel)
<< "samples_per_channel=" << samples_per_channel
<< "num_channels=" << num_channels;
// 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_) {
absl::c_fill_n(data_, total_samples, 0);
muted_ = false;
}
samples_per_channel_ = samples_per_channel;
num_channels_ = num_channels; return InterleavedView<int16_t>(&data_[0], samples_per_channel, num_channels);
}
void AudioFrame::Mute() {
muted_ = true;
}
bool AudioFrame::muted() const { return muted_;
}
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
RTC_CHECK_LE(samples_per_channel_ * num_channels_, data_.size());
}
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_);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.