2014-10-31 21:51:03 +00:00
|
|
|
/*
|
|
|
|
|
* 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>
|
2015-11-20 00:11:53 -08:00
|
|
|
#include <sstream>
|
2014-10-31 21:51:03 +00:00
|
|
|
|
|
|
|
|
#include "webrtc/base/checks.h"
|
Revert of Safe numeric library: base/numerics (copied from Chromium) (patchset #11 id:250001 of https://codereview.webrtc.org/1753293002/ )
Reason for revert:
Looks like the Chrome iOS build is broken because of these two changes. So I'm going to have to revert. Here's the error:
https://build.chromium.org/p/tryserver.chromium.mac/builders/ios_rel_device_ninja/builds/185624/steps/compile/logs/stdio
FAILED: rm -f arch/libsafe_numerics.arm64.a && ./gyp-mac-tool filter-libtool libtool -static -o arch/libsafe_numerics.arm64.a
error: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: no files specified
Usage: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table <filename>] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]
FAILED: rm -f arch/libsafe_numerics.armv7.a && ./gyp-mac-tool filter-libtool libtool -static -o arch/libsafe_numerics.armv7.a
error: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: no files specified
Usage: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table <filename>] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]
ninja: build stopped: subcommand failed.
Original issue's description:
> Safe numeric library added: base/numerics (copied from Chromium)
>
> This copies the contents (unittest excluded) of base/numerics in
> chromium to base/numerics in webrtc. Files added:
> - safe_conversions.h
> - safe_conversions_impl.h
> - safe_math.h
> - safe_math_impl.h
>
> A really old version of safe_conversions[_impl].h previously existed in
> base/, this has been deleted and sources using it have been updated
> to include the new base/numerics/safe_converions.h.
>
> This CL also adds a DEPS file to webrtc/base.
>
> NOPRESUBMIT=True
> BUG=webrtc:5548, webrtc:5623
>
> Committed: https://crrev.com/de1c81b2d2196be611674aa6019b9db3a9329042
> Cr-Commit-Position: refs/heads/master@{#11907}
TBR=kjellander@webrtc.org,kwiberg@webrtc.org,tina.legrand@webrtc.org,hbos@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5548, webrtc:5623
Review URL: https://codereview.webrtc.org/1792613002 .
Cr-Commit-Position: refs/heads/master@{#11965}
2016-03-11 17:12:32 -08:00
|
|
|
#include "webrtc/base/safe_conversions.h"
|
2014-10-31 21:51:03 +00:00
|
|
|
#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;
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
static const size_t kBytesPerSample = 2;
|
2014-10-31 21:51:03 +00:00
|
|
|
|
2014-12-16 20:17:21 +00:00
|
|
|
// 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_;
|
|
|
|
|
};
|
|
|
|
|
|
2015-11-20 00:11:53 -08:00
|
|
|
std::string WavFile::FormatAsString() const {
|
|
|
|
|
std::ostringstream s;
|
|
|
|
|
s << "Sample rate: " << sample_rate() << " Hz, Channels: " << num_channels()
|
|
|
|
|
<< ", Duration: "
|
|
|
|
|
<< (1.f * num_samples()) / (num_channels() * sample_rate()) << " s";
|
|
|
|
|
return s.str();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 21:51:03 +00:00
|
|
|
WavReader::WavReader(const std::string& filename)
|
|
|
|
|
: file_handle_(fopen(filename.c_str(), "rb")) {
|
2015-11-20 00:11:53 -08:00
|
|
|
RTC_CHECK(file_handle_) << "Could not open wav file for reading.";
|
2014-10-31 21:51:03 +00:00
|
|
|
|
2014-12-16 20:17:21 +00:00
|
|
|
ReadableWavFile readable(file_handle_);
|
2014-10-31 21:51:03 +00:00
|
|
|
WavFormat format;
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
size_t bytes_per_sample;
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK(ReadWavHeader(&readable, &num_channels_, &sample_rate_, &format,
|
|
|
|
|
&bytes_per_sample, &num_samples_));
|
2014-12-16 20:17:21 +00:00
|
|
|
num_samples_remaining_ = num_samples_;
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK_EQ(kWavFormat, format);
|
|
|
|
|
RTC_CHECK_EQ(kBytesPerSample, bytes_per_sample);
|
2014-10-31 21:51:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WavReader::~WavReader() {
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 02:13:28 -08:00
|
|
|
int WavReader::sample_rate() const {
|
|
|
|
|
return sample_rate_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t WavReader::num_channels() const {
|
|
|
|
|
return num_channels_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t WavReader::num_samples() const {
|
|
|
|
|
return num_samples_;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 21:51:03 +00:00
|
|
|
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
|
2014-12-16 20:17:21 +00:00
|
|
|
// There could be metadata after the audio; ensure we don't read it.
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
num_samples = std::min(num_samples, num_samples_remaining_);
|
2014-10-31 21:51:03 +00:00
|
|
|
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.
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK(read == num_samples || feof(file_handle_));
|
|
|
|
|
RTC_CHECK_LE(read, num_samples_remaining_);
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
num_samples_remaining_ -= read;
|
2014-10-31 21:51:03 +00:00
|
|
|
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() {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK_EQ(0, fclose(file_handle_));
|
2014-10-31 21:51:03 +00:00
|
|
|
file_handle_ = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WavWriter::WavWriter(const std::string& filename, int sample_rate,
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t num_channels)
|
2014-10-31 21:51:03 +00:00
|
|
|
: sample_rate_(sample_rate),
|
|
|
|
|
num_channels_(num_channels),
|
|
|
|
|
num_samples_(0),
|
|
|
|
|
file_handle_(fopen(filename.c_str(), "wb")) {
|
2015-11-20 00:11:53 -08:00
|
|
|
RTC_CHECK(file_handle_) << "Could not open wav file for writing.";
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK(CheckWavParameters(num_channels_, sample_rate_, kWavFormat,
|
|
|
|
|
kBytesPerSample, num_samples_));
|
2014-10-31 21:51:03 +00:00
|
|
|
|
|
|
|
|
// 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};
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK_EQ(1u, fwrite(blank_header, kWavHeaderSize, 1, file_handle_));
|
2014-10-31 21:51:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WavWriter::~WavWriter() {
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 02:13:28 -08:00
|
|
|
int WavWriter::sample_rate() const {
|
|
|
|
|
return sample_rate_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t WavWriter::num_channels() const {
|
|
|
|
|
return num_channels_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t WavWriter::num_samples() const {
|
|
|
|
|
return num_samples_;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 21:51:03 +00:00
|
|
|
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_);
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK_EQ(num_samples, written);
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
num_samples_ += written;
|
|
|
|
|
RTC_CHECK(num_samples_ >= written); // detect size_t overflow
|
2014-10-31 21:51:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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() {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK_EQ(0, fseek(file_handle_, 0, SEEK_SET));
|
2014-10-31 21:51:03 +00:00
|
|
|
uint8_t header[kWavHeaderSize];
|
2014-11-03 18:20:06 +00:00
|
|
|
WriteWavHeader(header, num_channels_, sample_rate_, kWavFormat,
|
|
|
|
|
kBytesPerSample, num_samples_);
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK_EQ(1u, fwrite(header, kWavHeaderSize, 1, file_handle_));
|
|
|
|
|
RTC_CHECK_EQ(0, fclose(file_handle_));
|
2014-10-31 21:51:03 +00:00
|
|
|
file_handle_ = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
rtc_WavWriter* rtc_WavOpen(const char* filename,
|
|
|
|
|
int sample_rate,
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t num_channels) {
|
2014-10-31 21:51:03 +00:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t rtc_WavNumChannels(const rtc_WavWriter* wf) {
|
2014-10-31 21:51:03 +00:00
|
|
|
return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_channels();
|
|
|
|
|
}
|
|
|
|
|
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
size_t rtc_WavNumSamples(const rtc_WavWriter* wf) {
|
2014-10-31 21:51:03 +00:00
|
|
|
return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_samples();
|
|
|
|
|
}
|