Commit e3af5f4d authored by Thomas Guilbert's avatar Thomas Guilbert Committed by Chromium LUCI CQ

Deprecate media::AudioBus methods

This CL converts deprecated AudioBus methods into explicit static
methods that behave the same way under the hood.

Bug: 619623
Change-Id: I54a8a61727b69a361ce1c789e572b829a99f32b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2603422Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarKenneth MacKay <kmackay@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Auto-Submit: Thomas Guilbert <tguilbert@chromium.org>
Commit-Queue: Thomas Guilbert <tguilbert@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841283}
parent 6bdb00da
......@@ -266,8 +266,8 @@ class CastAudioDecoderImpl : public CastAudioDecoder {
auto result = base::MakeRefCounted<::media::DecoderBuffer>(size);
if (output_format_ == kOutputSigned16) {
bus->ToInterleaved(num_frames, OutputFormatSizeInBytes(output_format_),
result->writable_data());
bus->ToInterleaved<::media::SignedInt16SampleTypeTraits>(
num_frames, reinterpret_cast<int16_t*>(result->writable_data()));
} else if (output_format_ == kOutputPlanarFloat) {
// Data in an AudioBus is already in planar float format; just copy each
// channel into the result buffer in order.
......
......@@ -203,7 +203,8 @@ class FileAudioSource : public AudioOutputStream::AudioSourceCallback {
// sufficient data remaining in the file to fill up the complete frame.
int frames = max_size / (dest->channels() * kBytesPerSample);
if (max_size) {
dest->FromInterleaved(file_->data() + pos_, frames, kBytesPerSample);
auto* source = reinterpret_cast<const int16_t*>(file_->data() + pos_);
dest->FromInterleaved<SignedInt16SampleTypeTraits>(source, frames);
pos_ += max_size;
}
......
......@@ -210,8 +210,12 @@ class FullDuplexAudioSinkSource
EXPECT_EQ(channels_, dest->channels());
size = std::min(dest->frames() * frame_size_, size);
EXPECT_EQ(static_cast<size_t>(size) % sizeof(*dest->channel(0)), 0U);
dest->FromInterleaved(source, size / frame_size_,
frame_size_ / channels_);
// We should only have 16 bits per sample.
DCHECK_EQ(frame_size_ / channels_, 2);
dest->FromInterleaved<SignedInt16SampleTypeTraits>(
reinterpret_cast<const int16_t*>(source), size / channels_);
buffer_->Seek(size);
return size / frame_size_;
}
......
......@@ -344,8 +344,10 @@ void PCMWaveOutAudioOutputStream::QueueNextPacket(WAVEHDR *buffer) {
// Note: If this ever changes to output raw float the data must be clipped
// and sanitized since it may come from an untrusted source such as NaCl.
audio_bus_->Scale(volume_);
audio_bus_->ToInterleaved(
frames_filled, format_.Format.wBitsPerSample / 8, buffer->lpData);
DCHECK_EQ(format_.Format.wBitsPerSample, 16);
audio_bus_->ToInterleaved<SignedInt16SampleTypeTraits>(
frames_filled, reinterpret_cast<int16_t*>(buffer->lpData));
buffer->dwBufferLength = used * format_.Format.nChannels / channels_;
} else {
......
......@@ -116,13 +116,33 @@ void AudioBlockFifo::PushInternal(const void* source,
std::min(block_frames_ - write_pos_, frames_to_push);
if (source) {
// Deinterleave the content to the FIFO and update the |write_pos_|.
current_block->FromInterleavedPartial(source_ptr, write_pos_, push_frames,
bytes_per_sample);
// Deinterleave the content to the FIFO.
switch (bytes_per_sample) {
case 1:
current_block->FromInterleavedPartial<UnsignedInt8SampleTypeTraits>(
source_ptr, write_pos_, push_frames);
break;
case 2:
current_block->FromInterleavedPartial<SignedInt16SampleTypeTraits>(
reinterpret_cast<const int16_t*>(source_ptr), write_pos_,
push_frames);
break;
case 4:
current_block->FromInterleavedPartial<SignedInt32SampleTypeTraits>(
reinterpret_cast<const int32_t*>(source_ptr), write_pos_,
push_frames);
break;
default:
NOTREACHED() << "Unsupported bytes per sample encountered: "
<< bytes_per_sample;
current_block->ZeroFramesPartial(write_pos_, push_frames);
}
} else {
current_block->ZeroFramesPartial(write_pos_, push_frames);
}
write_pos_ = (write_pos_ + push_frames) % block_frames_;
if (!write_pos_) {
// The current block is completely filled, increment |write_block_| and
// |available_blocks_|.
......
......@@ -273,81 +273,6 @@ void AudioBus::BuildChannelData(int channels, int aligned_frames, float* data) {
channel_data_.push_back(data + i * aligned_frames);
}
// Forwards to non-deprecated version.
void AudioBus::FromInterleaved(const void* source,
int frames,
int bytes_per_sample) {
DCHECK(!is_bitstream_format_);
switch (bytes_per_sample) {
case 1:
FromInterleaved<UnsignedInt8SampleTypeTraits>(
reinterpret_cast<const uint8_t*>(source), frames);
break;
case 2:
FromInterleaved<SignedInt16SampleTypeTraits>(
reinterpret_cast<const int16_t*>(source), frames);
break;
case 4:
FromInterleaved<SignedInt32SampleTypeTraits>(
reinterpret_cast<const int32_t*>(source), frames);
break;
default:
NOTREACHED() << "Unsupported bytes per sample encountered: "
<< bytes_per_sample;
ZeroFrames(frames);
}
}
// Forwards to non-deprecated version.
void AudioBus::FromInterleavedPartial(const void* source,
int start_frame,
int frames,
int bytes_per_sample) {
DCHECK(!is_bitstream_format_);
switch (bytes_per_sample) {
case 1:
FromInterleavedPartial<UnsignedInt8SampleTypeTraits>(
reinterpret_cast<const uint8_t*>(source), start_frame, frames);
break;
case 2:
FromInterleavedPartial<SignedInt16SampleTypeTraits>(
reinterpret_cast<const int16_t*>(source), start_frame, frames);
break;
case 4:
FromInterleavedPartial<SignedInt32SampleTypeTraits>(
reinterpret_cast<const int32_t*>(source), start_frame, frames);
break;
default:
NOTREACHED() << "Unsupported bytes per sample encountered: "
<< bytes_per_sample;
ZeroFramesPartial(start_frame, frames);
}
}
// Forwards to non-deprecated version.
void AudioBus::ToInterleaved(int frames,
int bytes_per_sample,
void* dest) const {
DCHECK(!is_bitstream_format_);
switch (bytes_per_sample) {
case 1:
ToInterleaved<UnsignedInt8SampleTypeTraits>(
frames, reinterpret_cast<uint8_t*>(dest));
break;
case 2:
ToInterleaved<SignedInt16SampleTypeTraits>(
frames, reinterpret_cast<int16_t*>(dest));
break;
case 4:
ToInterleaved<SignedInt32SampleTypeTraits>(
frames, reinterpret_cast<int32_t*>(dest));
break;
default:
NOTREACHED() << "Unsupported bytes per sample encountered: "
<< bytes_per_sample;
}
}
void AudioBus::CopyTo(AudioBus* dest) const {
dest->set_is_bitstream_format(is_bitstream_format());
if (is_bitstream_format()) {
......
......@@ -104,11 +104,6 @@ class MEDIA_SHMEM_EXPORT AudioBus {
const typename SourceSampleTypeTraits::ValueType* source_buffer,
int num_frames_to_write);
// DEPRECATED (https://crbug.com/580391)
// Please use the version templated with SourceSampleTypeTraits instead.
// TODO(chfremer): Remove (https://crbug.com/619623)
void FromInterleaved(const void* source, int frames, int bytes_per_sample);
// Similar to FromInterleaved...(), but overwrites the frames starting at a
// given offset |write_offset_in_frames| and does not zero out frames that are
// not overwritten.
......@@ -118,12 +113,6 @@ class MEDIA_SHMEM_EXPORT AudioBus {
int write_offset_in_frames,
int num_frames_to_write);
// DEPRECATED (https://crbug.com/580391)
// Please use the version templated with SourceSampleTypeTraits instead.
// TODO(chfremer): Remove (https://crbug.com/619623)
void FromInterleavedPartial(const void* source, int start_frame, int frames,
int bytes_per_sample);
// Reads the sample values stored in this AudioBus instance and places them
// into the given |dest_buffer| in interleaved format using the sample format
// specified by TargetSampleTypeTraits. For a list of ready-to-use
......@@ -134,11 +123,6 @@ class MEDIA_SHMEM_EXPORT AudioBus {
int num_frames_to_read,
typename TargetSampleTypeTraits::ValueType* dest_buffer) const;
// DEPRECATED (https://crbug.com/580391)
// Please use the version templated with TargetSampleTypeTraits instead.
// TODO(chfremer): Remove (https://crbug.com/619623)
void ToInterleaved(int frames, int bytes_per_sample, void* dest) const;
// Similar to ToInterleaved(), but reads the frames starting at a given
// offset |read_offset_in_frames|.
template <class TargetSampleTypeTraits>
......
......@@ -335,40 +335,6 @@ TEST_F(AudioBusTest, FromInterleaved) {
kTestVectorFrameCount * sizeof(*expected->channel(ch)));
}
// Test deprecated version that takes |bytes_per_sample| as an input.
{
SCOPED_TRACE("uint8_t");
bus->Zero();
bus->FromInterleaved(kTestVectorUint8, kTestVectorFrameCount,
sizeof(*kTestVectorUint8));
// Biased uint8_t calculations have poor precision, so the epsilon here is
// slightly more permissive than int16_t and int32_t calculations.
VerifyAreEqualWithEpsilon(bus.get(), expected.get(),
1.0f / (std::numeric_limits<uint8_t>::max() - 1));
}
{
SCOPED_TRACE("int16_t");
bus->Zero();
bus->FromInterleaved(kTestVectorInt16, kTestVectorFrameCount,
sizeof(*kTestVectorInt16));
VerifyAreEqualWithEpsilon(
bus.get(), expected.get(),
1.0f / (std::numeric_limits<uint16_t>::max() + 1.0f));
}
{
SCOPED_TRACE("int32_t");
bus->Zero();
bus->FromInterleaved(kTestVectorInt32, kTestVectorFrameCount,
sizeof(*kTestVectorInt32));
VerifyAreEqualWithEpsilon(
bus.get(), expected.get(),
1.0f / (std::numeric_limits<uint32_t>::max() + 1.0f));
}
// Test non-deprecated version that takes SampleTypeTraits as a template
// parameter.
{
SCOPED_TRACE("UnsignedInt8SampleTypeTraits");
bus->Zero();
......@@ -424,18 +390,6 @@ TEST_F(AudioBusTest, FromInterleavedPartial) {
kPartialFrames * sizeof(*expected->channel(ch)));
}
// Test deprecated version that takes |bytes_per_sample| as an input.
{
SCOPED_TRACE("int32_t");
bus->Zero();
bus->FromInterleavedPartial(
kTestVectorInt32 + kPartialStart * bus->channels(), kPartialStart,
kPartialFrames, sizeof(*kTestVectorInt32));
VerifyAreEqual(bus.get(), expected.get());
}
// Test non-deprecated version that takes SampleTypeTraits as a template
// parameter.
{
SCOPED_TRACE("SignedInt32SampleTypeTraits");
bus->Zero();
......@@ -456,43 +410,6 @@ TEST_F(AudioBusTest, ToInterleaved) {
kTestVectorFrameCount * sizeof(*bus->channel(ch)));
}
// Test deprecated version that takes |bytes_per_sample| as an input.
{
SCOPED_TRACE("uint8_t");
uint8_t test_array[base::size(kTestVectorUint8)];
bus->ToInterleaved(bus->frames(), sizeof(*kTestVectorUint8), test_array);
ASSERT_EQ(0,
memcmp(test_array, kTestVectorUint8, sizeof(kTestVectorUint8)));
}
{
SCOPED_TRACE("int16_t");
int16_t test_array[base::size(kTestVectorInt16)];
bus->ToInterleaved(bus->frames(), sizeof(*kTestVectorInt16), test_array);
ASSERT_EQ(0,
memcmp(test_array, kTestVectorInt16, sizeof(kTestVectorInt16)));
}
{
SCOPED_TRACE("int32_t");
int32_t test_array[base::size(kTestVectorInt32)];
bus->ToInterleaved(bus->frames(), sizeof(*kTestVectorInt32), test_array);
// Some compilers get better precision than others on the half-max test, so
// let the test pass with an off by one check on the half-max.
int32_t alternative_acceptable_result[base::size(kTestVectorInt32)];
memcpy(alternative_acceptable_result, kTestVectorInt32,
sizeof(kTestVectorInt32));
ASSERT_EQ(alternative_acceptable_result[4],
std::numeric_limits<int32_t>::max() / 2);
alternative_acceptable_result[4]++;
ASSERT_TRUE(
memcmp(test_array, kTestVectorInt32, sizeof(kTestVectorInt32)) == 0 ||
memcmp(test_array, alternative_acceptable_result,
sizeof(alternative_acceptable_result)) == 0);
}
// Test non-deprecated version that takes SampleTypeTraits as a template
// parameter.
{
SCOPED_TRACE("UnsignedInt8SampleTypeTraits");
uint8_t test_array[base::size(kTestVectorUint8)];
......
......@@ -276,9 +276,25 @@ bool AudioFileReader::OnNewFrame(
sizeof(float) * frames_read);
}
} else {
audio_bus->FromInterleaved(
frame->data[0], frames_read,
av_get_bytes_per_sample(codec_context_->sample_fmt));
int bytes_per_sample = av_get_bytes_per_sample(codec_context_->sample_fmt);
switch (bytes_per_sample) {
case 1:
audio_bus->FromInterleaved<UnsignedInt8SampleTypeTraits>(
reinterpret_cast<const uint8_t*>(frame->data[0]), frames_read);
break;
case 2:
audio_bus->FromInterleaved<SignedInt16SampleTypeTraits>(
reinterpret_cast<const int16_t*>(frame->data[0]), frames_read);
break;
case 4:
audio_bus->FromInterleaved<SignedInt32SampleTypeTraits>(
reinterpret_cast<const int32_t*>(frame->data[0]), frames_read);
break;
default:
NOTREACHED() << "Unsupported bytes per sample encountered: "
<< bytes_per_sample;
audio_bus->ZeroFrames(frames_read);
}
}
(*total_frames) += frames_read;
......
......@@ -146,8 +146,11 @@ void PeerConnectionRemoteAudioSource::OnData(const void* audio_data,
audio_bus_ = media::AudioBus::Create(number_of_channels, number_of_frames);
}
audio_bus_->FromInterleaved(audio_data, number_of_frames,
bits_per_sample / 8);
// Only 16 bits per sample is ever used. The FromInterleaved() call should
// be updated if that is no longer the case.
DCHECK_EQ(bits_per_sample, 16);
audio_bus_->FromInterleaved<media::SignedInt16SampleTypeTraits>(
reinterpret_cast<const int16_t*>(audio_data), number_of_frames);
media::AudioParameters params = MediaStreamAudioSource::GetAudioParameters();
if (!params.IsValid() ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment