Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3329)

Unified Diff: webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc

Issue 2695243005: Injectable audio encoders: BuiltinAudioEncoderFactory (Closed)
Patch Set: Fix build problems on Windows, Android and downstream. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc
diff --git a/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc b/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc
index baa5d382d327ef0abf16de5ffcfbd40fa5dab723..113fb63f55413ea6a1bd251162a1ffbd88b53e4b 100644
--- a/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc
+++ b/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc
@@ -10,9 +10,11 @@
#include "webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h"
+#include <algorithm>
#include <limits>
#include "webrtc/base/checks.h"
+#include "webrtc/base/string_to_number.h"
#include "webrtc/common_types.h"
#include "webrtc/modules/audio_coding/codecs/g711/g711_interface.h"
@@ -29,6 +31,35 @@ typename T::Config CreateConfig(const CodecInst& codec_inst) {
return config;
}
+template <typename T>
+typename T::Config CreateConfig(int payload_type,
+ const SdpAudioFormat& format) {
+ typename T::Config config;
+ config.frame_size_ms = 20;
+ auto ptime_iter = format.parameters.find("ptime");
+ if (ptime_iter != format.parameters.end()) {
+ auto ptime = rtc::StringToNumber<int>(ptime_iter->second);
+ if (ptime && *ptime > 0) {
+ const int whole_packets = *ptime / 10;
+ config.frame_size_ms = std::max(10, std::min(whole_packets * 10, 60));
+ }
+ }
+ config.num_channels = format.num_channels;
+ config.payload_type = payload_type;
+ return config;
+}
+
+template <typename T>
+rtc::Optional<AudioCodecInfo> QueryAudioEncoderImpl(
+ const SdpAudioFormat& format) {
+ if (STR_CASE_CMP(format.name.c_str(), T::GetPayloadName()) == 0 &&
+ format.clockrate_hz == 8000 && format.num_channels >= 1 &&
+ CreateConfig<T>(0, format).IsOk()) {
+ return rtc::Optional<AudioCodecInfo>({8000, format.num_channels, 64000});
+ }
+ return rtc::Optional<AudioCodecInfo>();
+}
+
} // namespace
bool AudioEncoderPcm::Config::IsOk() const {
@@ -107,6 +138,15 @@ void AudioEncoderPcm::Reset() {
AudioEncoderPcmA::AudioEncoderPcmA(const CodecInst& codec_inst)
: AudioEncoderPcmA(CreateConfig<AudioEncoderPcmA>(codec_inst)) {}
+AudioEncoderPcmA::AudioEncoderPcmA(int payload_type,
+ const SdpAudioFormat& format)
+ : AudioEncoderPcmA(CreateConfig<AudioEncoderPcmA>(payload_type, format)) {}
+
+rtc::Optional<AudioCodecInfo> AudioEncoderPcmA::QueryAudioEncoder(
+ const SdpAudioFormat& format) {
+ return QueryAudioEncoderImpl<AudioEncoderPcmA>(format);
+}
+
size_t AudioEncoderPcmA::EncodeCall(const int16_t* audio,
size_t input_len,
uint8_t* encoded) {
@@ -124,6 +164,15 @@ AudioEncoder::CodecType AudioEncoderPcmA::GetCodecType() const {
AudioEncoderPcmU::AudioEncoderPcmU(const CodecInst& codec_inst)
: AudioEncoderPcmU(CreateConfig<AudioEncoderPcmU>(codec_inst)) {}
+AudioEncoderPcmU::AudioEncoderPcmU(int payload_type,
+ const SdpAudioFormat& format)
+ : AudioEncoderPcmU(CreateConfig<AudioEncoderPcmU>(payload_type, format)) {}
+
+rtc::Optional<AudioCodecInfo> AudioEncoderPcmU::QueryAudioEncoder(
+ const SdpAudioFormat& format) {
+ return QueryAudioEncoderImpl<AudioEncoderPcmU>(format);
+}
+
size_t AudioEncoderPcmU::EncodeCall(const int16_t* audio,
size_t input_len,
uint8_t* encoded) {

Powered by Google App Engine
This is Rietveld 408576698