2014-12-11 10:47:19 +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.
|
|
|
|
|
*/
|
|
|
|
|
|
2015-11-18 23:07:57 +01:00
|
|
|
#include "webrtc/modules/audio_coding/codecs/pcm16b/audio_encoder_pcm16b.h"
|
2015-05-07 12:35:12 +02:00
|
|
|
|
2017-04-06 10:03:21 -07:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
2015-05-07 12:35:12 +02:00
|
|
|
#include "webrtc/common_types.h"
|
2015-11-18 23:07:57 +01:00
|
|
|
#include "webrtc/modules/audio_coding/codecs/pcm16b/pcm16b.h"
|
2017-07-06 19:44:34 +02:00
|
|
|
#include "webrtc/rtc_base/checks.h"
|
|
|
|
|
#include "webrtc/rtc_base/safe_conversions.h"
|
2014-12-11 10:47:19 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t AudioEncoderPcm16B::EncodeCall(const int16_t* audio,
|
|
|
|
|
size_t input_len,
|
|
|
|
|
uint8_t* encoded) {
|
|
|
|
|
return WebRtcPcm16b_Encode(audio, input_len, encoded);
|
2014-12-11 10:47:19 +00:00
|
|
|
}
|
|
|
|
|
|
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 AudioEncoderPcm16B::BytesPerSample() const {
|
2015-06-18 14:58:34 +02:00
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-16 07:34:24 -07:00
|
|
|
AudioEncoder::CodecType AudioEncoderPcm16B::GetCodecType() const {
|
|
|
|
|
return CodecType::kOther;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-07 12:35:12 +02:00
|
|
|
namespace {
|
2017-08-25 22:22:42 -07:00
|
|
|
|
2015-05-07 12:35:12 +02:00
|
|
|
AudioEncoderPcm16B::Config CreateConfig(const CodecInst& codec_inst) {
|
|
|
|
|
AudioEncoderPcm16B::Config config;
|
|
|
|
|
config.num_channels = codec_inst.channels;
|
|
|
|
|
config.sample_rate_hz = codec_inst.plfreq;
|
|
|
|
|
config.frame_size_ms = rtc::CheckedDivExact(
|
|
|
|
|
codec_inst.pacsize, rtc::CheckedDivExact(config.sample_rate_hz, 1000));
|
|
|
|
|
config.payload_type = codec_inst.pltype;
|
|
|
|
|
return config;
|
|
|
|
|
}
|
2017-04-06 10:03:21 -07:00
|
|
|
|
2015-05-07 12:35:12 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
2015-09-08 05:57:53 -07:00
|
|
|
bool AudioEncoderPcm16B::Config::IsOk() const {
|
|
|
|
|
if ((sample_rate_hz != 8000) && (sample_rate_hz != 16000) &&
|
|
|
|
|
(sample_rate_hz != 32000) && (sample_rate_hz != 48000))
|
|
|
|
|
return false;
|
|
|
|
|
return AudioEncoderPcm::Config::IsOk();
|
2015-05-07 12:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-08 05:57:53 -07:00
|
|
|
AudioEncoderPcm16B::AudioEncoderPcm16B(const CodecInst& codec_inst)
|
|
|
|
|
: AudioEncoderPcm16B(CreateConfig(codec_inst)) {}
|
|
|
|
|
|
2014-12-11 10:47:19 +00:00
|
|
|
} // namespace webrtc
|