Reason for revert:
Breaks Chromium FYI content_browsertest on all platforms. The testcase that fails is WebRtcAecDumpBrowserTest.CallWithAecDump.
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Linux/builds/19388
Sample output:
[ RUN ] WebRtcAecDumpBrowserTest.CallWithAecDump
Xlib: extension "RANDR" missing on display ":9".
[4:14:0722/211548:1282124453:WARNING:webrtcvoiceengine.cc(472)] Unexpected codec: ISAC/48000/1 (105)
[4:14:0722/211548:1282124593:WARNING:webrtcvoiceengine.cc(472)] Unexpected codec: PCMU/8000/2 (110)
[4:14:0722/211548:1282124700:WARNING:webrtcvoiceengine.cc(472)] Unexpected codec: PCMA/8000/2 (118)
[4:14:0722/211548:1282124815:WARNING:webrtcvoiceengine.cc(472)] Unexpected codec: G722/8000/2 (119)
[19745:19745:0722/211548:1282133667:INFO:CONSOLE(64)] "Looking at video in element remote-view-1", source: http://127.0.0.1:48819/media/webrtc_test_utilities.js (64)
[19745:19745:0722/211548:1282136892:INFO:CONSOLE(64)] "Looking at video in element remote-view-2", source: http://127.0.0.1:48819/media/webrtc_test_utilities.js (64)
../../content/test/webrtc_content_browsertest_base.cc:62: Failure
Value of: ExecuteScriptAndExtractString( shell()->web_contents(), javascript, &result)
Actual: false
Expected: true
Failed to execute javascript call({video: true, audio: true});.
From javascript: (nothing)
When executing 'call({video: true, audio: true});'
../../content/test/webrtc_content_browsertest_base.cc:75: Failure
Failed
../../content/browser/media/webrtc_aecdump_browsertest.cc:26: Failure
Expected: (base::kNullProcessId) != (*id), actual: 0 vs 0
../../content/browser/media/webrtc_aecdump_browsertest.cc:95: Failure
Value of: GetRenderProcessHostId(&render_process_id)
Actual: false
Expected: true
../../content/browser/media/webrtc_aecdump_browsertest.cc:99: Failure
Value of: base::PathExists(dump_file)
Actual: false
Expected: true
../../content/browser/media/webrtc_aecdump_browsertest.cc:101: Failure
Value of: base::GetFileSize(dump_file, &file_size)
Actual: false
Expected: true
../../content/browser/media/webrtc_aecdump_browsertest.cc:102: Failure
Expected: (file_size) > (0), actual: 0 vs 0
[ FAILED ] WebRtcAecDumpBrowserTest.CallWithAecDump, where TypeParam = and GetParam() = (361 ms)
Original issue's description:
> Allow more than 2 input channels in AudioProcessing.
>
> The number of output channels is constrained to be equal to either 1 or the
> number of input channels.
>
> R=aluebs@webrtc.org, andrew@webrtc.org, pbos@webrtc.org
>
> Committed: c204754b7a
TBR=andrew@webrtc.org,aluebs@webrtc.org,ajm@chromium.org,pbos@chromium.org,pbos@webrtc.org,mgraczyk@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Review URL: https://codereview.webrtc.org/1253573005
Cr-Commit-Position: refs/heads/master@{#9621}
183 lines
6.0 KiB
C++
183 lines
6.0 KiB
C++
/*
|
|
* Copyright (c) 2014 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 "webrtc/common_audio/wav_file.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstdio>
|
|
#include <limits>
|
|
|
|
#include "webrtc/base/checks.h"
|
|
#include "webrtc/base/safe_conversions.h"
|
|
#include "webrtc/common_audio/include/audio_util.h"
|
|
#include "webrtc/common_audio/wav_header.h"
|
|
|
|
namespace webrtc {
|
|
|
|
// We write 16-bit PCM WAV files.
|
|
static const WavFormat kWavFormat = kWavFormatPcm;
|
|
static const int kBytesPerSample = 2;
|
|
|
|
// Doesn't take ownership of the file handle and won't close it.
|
|
class ReadableWavFile : public ReadableWav {
|
|
public:
|
|
explicit ReadableWavFile(FILE* file) : file_(file) {}
|
|
virtual size_t Read(void* buf, size_t num_bytes) {
|
|
return fread(buf, 1, num_bytes, file_);
|
|
}
|
|
|
|
private:
|
|
FILE* file_;
|
|
};
|
|
|
|
WavReader::WavReader(const std::string& filename)
|
|
: file_handle_(fopen(filename.c_str(), "rb")) {
|
|
CHECK(file_handle_ && "Could not open wav file for reading.");
|
|
|
|
ReadableWavFile readable(file_handle_);
|
|
WavFormat format;
|
|
int bytes_per_sample;
|
|
CHECK(ReadWavHeader(&readable, &num_channels_, &sample_rate_, &format,
|
|
&bytes_per_sample, &num_samples_));
|
|
num_samples_remaining_ = num_samples_;
|
|
CHECK_EQ(kWavFormat, format);
|
|
CHECK_EQ(kBytesPerSample, bytes_per_sample);
|
|
}
|
|
|
|
WavReader::~WavReader() {
|
|
Close();
|
|
}
|
|
|
|
size_t WavReader::ReadSamples(size_t num_samples, int16_t* samples) {
|
|
#ifndef WEBRTC_ARCH_LITTLE_ENDIAN
|
|
#error "Need to convert samples to big-endian when reading from WAV file"
|
|
#endif
|
|
// There could be metadata after the audio; ensure we don't read it.
|
|
num_samples = std::min(rtc::checked_cast<uint32_t>(num_samples),
|
|
num_samples_remaining_);
|
|
const size_t read =
|
|
fread(samples, sizeof(*samples), num_samples, file_handle_);
|
|
// If we didn't read what was requested, ensure we've reached the EOF.
|
|
CHECK(read == num_samples || feof(file_handle_));
|
|
CHECK_LE(read, num_samples_remaining_);
|
|
num_samples_remaining_ -= rtc::checked_cast<uint32_t>(read);
|
|
return read;
|
|
}
|
|
|
|
size_t WavReader::ReadSamples(size_t num_samples, float* samples) {
|
|
static const size_t kChunksize = 4096 / sizeof(uint16_t);
|
|
size_t read = 0;
|
|
for (size_t i = 0; i < num_samples; i += kChunksize) {
|
|
int16_t isamples[kChunksize];
|
|
size_t chunk = std::min(kChunksize, num_samples - i);
|
|
chunk = ReadSamples(chunk, isamples);
|
|
for (size_t j = 0; j < chunk; ++j)
|
|
samples[i + j] = isamples[j];
|
|
read += chunk;
|
|
}
|
|
return read;
|
|
}
|
|
|
|
void WavReader::Close() {
|
|
CHECK_EQ(0, fclose(file_handle_));
|
|
file_handle_ = NULL;
|
|
}
|
|
|
|
WavWriter::WavWriter(const std::string& filename, int sample_rate,
|
|
int num_channels)
|
|
: sample_rate_(sample_rate),
|
|
num_channels_(num_channels),
|
|
num_samples_(0),
|
|
file_handle_(fopen(filename.c_str(), "wb")) {
|
|
CHECK(file_handle_ && "Could not open wav file for writing.");
|
|
CHECK(CheckWavParameters(num_channels_,
|
|
sample_rate_,
|
|
kWavFormat,
|
|
kBytesPerSample,
|
|
num_samples_));
|
|
|
|
// Write a blank placeholder header, since we need to know the total number
|
|
// of samples before we can fill in the real data.
|
|
static const uint8_t blank_header[kWavHeaderSize] = {0};
|
|
CHECK_EQ(1u, fwrite(blank_header, kWavHeaderSize, 1, file_handle_));
|
|
}
|
|
|
|
WavWriter::~WavWriter() {
|
|
Close();
|
|
}
|
|
|
|
void WavWriter::WriteSamples(const int16_t* samples, size_t num_samples) {
|
|
#ifndef WEBRTC_ARCH_LITTLE_ENDIAN
|
|
#error "Need to convert samples to little-endian when writing to WAV file"
|
|
#endif
|
|
const size_t written =
|
|
fwrite(samples, sizeof(*samples), num_samples, file_handle_);
|
|
CHECK_EQ(num_samples, written);
|
|
num_samples_ += static_cast<uint32_t>(written);
|
|
CHECK(written <= std::numeric_limits<uint32_t>::max() ||
|
|
num_samples_ >= written); // detect uint32_t overflow
|
|
CHECK(CheckWavParameters(num_channels_,
|
|
sample_rate_,
|
|
kWavFormat,
|
|
kBytesPerSample,
|
|
num_samples_));
|
|
}
|
|
|
|
void WavWriter::WriteSamples(const float* samples, size_t num_samples) {
|
|
static const size_t kChunksize = 4096 / sizeof(uint16_t);
|
|
for (size_t i = 0; i < num_samples; i += kChunksize) {
|
|
int16_t isamples[kChunksize];
|
|
const size_t chunk = std::min(kChunksize, num_samples - i);
|
|
FloatS16ToS16(samples + i, chunk, isamples);
|
|
WriteSamples(isamples, chunk);
|
|
}
|
|
}
|
|
|
|
void WavWriter::Close() {
|
|
CHECK_EQ(0, fseek(file_handle_, 0, SEEK_SET));
|
|
uint8_t header[kWavHeaderSize];
|
|
WriteWavHeader(header, num_channels_, sample_rate_, kWavFormat,
|
|
kBytesPerSample, num_samples_);
|
|
CHECK_EQ(1u, fwrite(header, kWavHeaderSize, 1, file_handle_));
|
|
CHECK_EQ(0, fclose(file_handle_));
|
|
file_handle_ = NULL;
|
|
}
|
|
|
|
} // namespace webrtc
|
|
|
|
rtc_WavWriter* rtc_WavOpen(const char* filename,
|
|
int sample_rate,
|
|
int num_channels) {
|
|
return reinterpret_cast<rtc_WavWriter*>(
|
|
new webrtc::WavWriter(filename, sample_rate, num_channels));
|
|
}
|
|
|
|
void rtc_WavClose(rtc_WavWriter* wf) {
|
|
delete reinterpret_cast<webrtc::WavWriter*>(wf);
|
|
}
|
|
|
|
void rtc_WavWriteSamples(rtc_WavWriter* wf,
|
|
const float* samples,
|
|
size_t num_samples) {
|
|
reinterpret_cast<webrtc::WavWriter*>(wf)->WriteSamples(samples, num_samples);
|
|
}
|
|
|
|
int rtc_WavSampleRate(const rtc_WavWriter* wf) {
|
|
return reinterpret_cast<const webrtc::WavWriter*>(wf)->sample_rate();
|
|
}
|
|
|
|
int rtc_WavNumChannels(const rtc_WavWriter* wf) {
|
|
return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_channels();
|
|
}
|
|
|
|
uint32_t rtc_WavNumSamples(const rtc_WavWriter* wf) {
|
|
return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_samples();
|
|
}
|