iSAC floating-point implementation of the Audio{En,De}coderFactoryTemplate APIs

BUG=webrtc:7835, webrtc:7841

Review-Url: https://codereview.webrtc.org/3001483002
Cr-Commit-Position: refs/heads/master@{#19427}
This commit is contained in:
kwiberg 2017-08-21 06:11:18 -07:00 committed by Commit Bot
parent 0069b45179
commit e57556c764
8 changed files with 278 additions and 0 deletions

View File

@ -37,3 +37,29 @@ rtc_static_library("audio_decoder_isac_fix") {
"../../../rtc_base:rtc_base_approved",
]
}
rtc_static_library("audio_encoder_isac_float") {
sources = [
"audio_encoder_isac_float.cc",
"audio_encoder_isac_float.h",
]
deps = [
"..:audio_codecs_api",
"../../..:webrtc_common",
"../../../modules/audio_coding:isac",
"../../../rtc_base:rtc_base_approved",
]
}
rtc_static_library("audio_decoder_isac_float") {
sources = [
"audio_decoder_isac_float.cc",
"audio_decoder_isac_float.h",
]
deps = [
"..:audio_codecs_api",
"../../..:webrtc_common",
"../../../modules/audio_coding:isac",
"../../../rtc_base:rtc_base_approved",
]
}

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2017 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/api/audio_codecs/isac/audio_decoder_isac_float.h"
#include "webrtc/common_types.h"
#include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isac.h"
#include "webrtc/rtc_base/ptr_util.h"
namespace webrtc {
rtc::Optional<AudioDecoderIsacFloat::Config> AudioDecoderIsacFloat::SdpToConfig(
const SdpAudioFormat& format) {
if (STR_CASE_CMP(format.name.c_str(), "ISAC") == 0 &&
(format.clockrate_hz == 16000 || format.clockrate_hz == 32000) &&
format.num_channels == 1) {
Config config;
config.sample_rate_hz = format.clockrate_hz;
return rtc::Optional<Config>(config);
} else {
return rtc::Optional<Config>();
}
}
void AudioDecoderIsacFloat::AppendSupportedDecoders(
std::vector<AudioCodecSpec>* specs) {
specs->push_back({{"ISAC", 16000, 1}, {16000, 1, 32000, 10000, 32000}});
specs->push_back({{"ISAC", 32000, 1}, {32000, 1, 56000, 10000, 56000}});
}
std::unique_ptr<AudioDecoder> AudioDecoderIsacFloat::MakeAudioDecoder(
Config config) {
RTC_DCHECK(config.IsOk());
return rtc::MakeUnique<AudioDecoderIsacFloatImpl>(config.sample_rate_hz);
}
} // namespace webrtc

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2017 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.
*/
#ifndef WEBRTC_API_AUDIO_CODECS_ISAC_AUDIO_DECODER_ISAC_FLOAT_H_
#define WEBRTC_API_AUDIO_CODECS_ISAC_AUDIO_DECODER_ISAC_FLOAT_H_
#include <memory>
#include <vector>
#include "webrtc/api/audio_codecs/audio_decoder.h"
#include "webrtc/api/audio_codecs/audio_format.h"
#include "webrtc/rtc_base/optional.h"
namespace webrtc {
// iSAC decoder API (floating-point implementation) for use as a template
// parameter to CreateAudioDecoderFactory<...>().
//
// NOTE: This struct is still under development and may change without notice.
struct AudioDecoderIsacFloat {
struct Config {
bool IsOk() const {
return sample_rate_hz == 16000 || sample_rate_hz == 32000;
}
int sample_rate_hz = 16000;
};
static rtc::Optional<Config> SdpToConfig(const SdpAudioFormat& audio_format);
static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs);
static std::unique_ptr<AudioDecoder> MakeAudioDecoder(Config config);
};
} // namespace webrtc
#endif // WEBRTC_API_AUDIO_CODECS_ISAC_AUDIO_DECODER_ISAC_FLOAT_H_

View File

@ -0,0 +1,73 @@
/*
* Copyright (c) 2017 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/api/audio_codecs/isac/audio_encoder_isac_float.h"
#include "webrtc/common_types.h"
#include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isac.h"
#include "webrtc/rtc_base/ptr_util.h"
#include "webrtc/rtc_base/string_to_number.h"
namespace webrtc {
rtc::Optional<AudioEncoderIsacFloat::Config> AudioEncoderIsacFloat::SdpToConfig(
const SdpAudioFormat& format) {
if (STR_CASE_CMP(format.name.c_str(), "ISAC") == 0 &&
(format.clockrate_hz == 16000 || format.clockrate_hz == 32000) &&
format.num_channels == 1) {
Config config;
config.sample_rate_hz = format.clockrate_hz;
if (config.sample_rate_hz == 16000) {
// For sample rate 16 kHz, optionally use 60 ms frames, instead of the
// default 30 ms.
const auto ptime_iter = format.parameters.find("ptime");
if (ptime_iter != format.parameters.end()) {
const auto ptime = rtc::StringToNumber<int>(ptime_iter->second);
if (ptime && *ptime >= 60) {
config.frame_size_ms = 60;
}
}
}
return rtc::Optional<Config>(config);
} else {
return rtc::Optional<Config>();
}
}
void AudioEncoderIsacFloat::AppendSupportedEncoders(
std::vector<AudioCodecSpec>* specs) {
for (int sample_rate_hz : {16000, 32000}) {
const SdpAudioFormat fmt = {"ISAC", sample_rate_hz, 1};
const AudioCodecInfo info = QueryAudioEncoder(*SdpToConfig(fmt));
specs->push_back({fmt, info});
}
}
AudioCodecInfo AudioEncoderIsacFloat::QueryAudioEncoder(
const AudioEncoderIsacFloat::Config& config) {
RTC_DCHECK(config.IsOk());
constexpr int min_bitrate = 10000;
const int max_bitrate = config.sample_rate_hz == 16000 ? 32000 : 56000;
const int default_bitrate = max_bitrate;
return {config.sample_rate_hz, 1, default_bitrate, min_bitrate, max_bitrate};
}
std::unique_ptr<AudioEncoder> AudioEncoderIsacFloat::MakeAudioEncoder(
const AudioEncoderIsacFloat::Config& config,
int payload_type) {
RTC_DCHECK(config.IsOk());
AudioEncoderIsacFloatImpl::Config c;
c.sample_rate_hz = config.sample_rate_hz;
c.frame_size_ms = config.frame_size_ms;
c.payload_type = payload_type;
return rtc::MakeUnique<AudioEncoderIsacFloatImpl>(c);
}
} // namespace webrtc

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2017 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.
*/
#ifndef WEBRTC_API_AUDIO_CODECS_ISAC_AUDIO_ENCODER_ISAC_FLOAT_H_
#define WEBRTC_API_AUDIO_CODECS_ISAC_AUDIO_ENCODER_ISAC_FLOAT_H_
#include <memory>
#include <vector>
#include "webrtc/api/audio_codecs/audio_encoder.h"
#include "webrtc/api/audio_codecs/audio_format.h"
#include "webrtc/rtc_base/optional.h"
namespace webrtc {
// iSAC encoder API (floating-point implementation) for use as a template
// parameter to CreateAudioEncoderFactory<...>().
//
// NOTE: This struct is still under development and may change without notice.
struct AudioEncoderIsacFloat {
struct Config {
bool IsOk() const {
return (sample_rate_hz == 16000 &&
(frame_size_ms == 30 || frame_size_ms == 60)) ||
(sample_rate_hz == 32000 && frame_size_ms == 30);
}
int sample_rate_hz = 16000;
int frame_size_ms = 30;
};
static rtc::Optional<Config> SdpToConfig(const SdpAudioFormat& audio_format);
static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs);
static AudioCodecInfo QueryAudioEncoder(const Config& config);
static std::unique_ptr<AudioEncoder> MakeAudioEncoder(const Config& config,
int payload_type);
};
} // namespace webrtc
#endif // WEBRTC_API_AUDIO_CODECS_ISAC_AUDIO_ENCODER_ISAC_FLOAT_H_

View File

@ -34,7 +34,9 @@ if (rtc_include_tests) {
"../ilbc:audio_decoder_ilbc",
"../ilbc:audio_encoder_ilbc",
"../isac:audio_decoder_isac_fix",
"../isac:audio_decoder_isac_float",
"../isac:audio_encoder_isac_fix",
"../isac:audio_encoder_isac_float",
"../opus:audio_decoder_opus",
"../opus:audio_encoder_opus",
"//testing/gmock",

View File

@ -14,6 +14,7 @@
#include "webrtc/api/audio_codecs/g722/audio_decoder_g722.h"
#include "webrtc/api/audio_codecs/ilbc/audio_decoder_ilbc.h"
#include "webrtc/api/audio_codecs/isac/audio_decoder_isac_fix.h"
#include "webrtc/api/audio_codecs/isac/audio_decoder_isac_float.h"
#include "webrtc/api/audio_codecs/opus/audio_decoder_opus.h"
#include "webrtc/rtc_base/ptr_util.h"
#include "webrtc/test/gmock.h"
@ -174,12 +175,32 @@ TEST(AudioDecoderFactoryTemplateTest, IsacFix) {
{"ISAC", 16000, 1}, {16000, 1, 32000, 10000, 32000}}));
EXPECT_FALSE(factory->IsSupportedDecoder({"isac", 16000, 2}));
EXPECT_TRUE(factory->IsSupportedDecoder({"isac", 16000, 1}));
EXPECT_FALSE(factory->IsSupportedDecoder({"isac", 32000, 1}));
EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"isac", 8000, 1}));
auto dec = factory->MakeAudioDecoder({"isac", 16000, 1});
ASSERT_NE(nullptr, dec);
EXPECT_EQ(16000, dec->SampleRateHz());
}
TEST(AudioDecoderFactoryTemplateTest, IsacFloat) {
auto factory = CreateAudioDecoderFactory<AudioDecoderIsacFloat>();
EXPECT_THAT(
factory->GetSupportedDecoders(),
testing::ElementsAre(
AudioCodecSpec{{"ISAC", 16000, 1}, {16000, 1, 32000, 10000, 32000}},
AudioCodecSpec{{"ISAC", 32000, 1}, {32000, 1, 56000, 10000, 56000}}));
EXPECT_FALSE(factory->IsSupportedDecoder({"isac", 16000, 2}));
EXPECT_TRUE(factory->IsSupportedDecoder({"isac", 16000, 1}));
EXPECT_TRUE(factory->IsSupportedDecoder({"isac", 32000, 1}));
EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"isac", 8000, 1}));
auto dec1 = factory->MakeAudioDecoder({"isac", 16000, 1});
ASSERT_NE(nullptr, dec1);
EXPECT_EQ(16000, dec1->SampleRateHz());
auto dec2 = factory->MakeAudioDecoder({"isac", 32000, 1});
ASSERT_NE(nullptr, dec2);
EXPECT_EQ(32000, dec2->SampleRateHz());
}
TEST(AudioDecoderFactoryTemplateTest, L16) {
auto factory = CreateAudioDecoderFactory<AudioDecoderL16>();
EXPECT_THAT(

View File

@ -14,6 +14,7 @@
#include "webrtc/api/audio_codecs/g722/audio_encoder_g722.h"
#include "webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc.h"
#include "webrtc/api/audio_codecs/isac/audio_encoder_isac_fix.h"
#include "webrtc/api/audio_codecs/isac/audio_encoder_isac_float.h"
#include "webrtc/api/audio_codecs/opus/audio_encoder_opus.h"
#include "webrtc/rtc_base/ptr_util.h"
#include "webrtc/test/gmock.h"
@ -181,6 +182,8 @@ TEST(AudioEncoderFactoryTemplateTest, IsacFix) {
factory->QueryAudioEncoder({"isac", 16000, 2}));
EXPECT_EQ(rtc::Optional<AudioCodecInfo>({16000, 1, 32000, 10000, 32000}),
factory->QueryAudioEncoder({"isac", 16000, 1}));
EXPECT_EQ(rtc::Optional<AudioCodecInfo>(),
factory->QueryAudioEncoder({"isac", 32000, 1}));
EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"isac", 8000, 1}));
auto enc1 = factory->MakeAudioEncoder(17, {"isac", 16000, 1});
ASSERT_NE(nullptr, enc1);
@ -192,6 +195,28 @@ TEST(AudioEncoderFactoryTemplateTest, IsacFix) {
EXPECT_EQ(6u, enc2->Num10MsFramesInNextPacket());
}
TEST(AudioEncoderFactoryTemplateTest, IsacFloat) {
auto factory = CreateAudioEncoderFactory<AudioEncoderIsacFloat>();
EXPECT_THAT(
factory->GetSupportedEncoders(),
testing::ElementsAre(
AudioCodecSpec{{"ISAC", 16000, 1}, {16000, 1, 32000, 10000, 32000}},
AudioCodecSpec{{"ISAC", 32000, 1}, {32000, 1, 56000, 10000, 56000}}));
EXPECT_EQ(rtc::Optional<AudioCodecInfo>(),
factory->QueryAudioEncoder({"isac", 16000, 2}));
EXPECT_EQ(rtc::Optional<AudioCodecInfo>({16000, 1, 32000, 10000, 32000}),
factory->QueryAudioEncoder({"isac", 16000, 1}));
EXPECT_EQ(rtc::Optional<AudioCodecInfo>({32000, 1, 56000, 10000, 56000}),
factory->QueryAudioEncoder({"isac", 32000, 1}));
EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"isac", 8000, 1}));
auto enc1 = factory->MakeAudioEncoder(17, {"isac", 16000, 1});
ASSERT_NE(nullptr, enc1);
EXPECT_EQ(16000, enc1->SampleRateHz());
auto enc2 = factory->MakeAudioEncoder(17, {"isac", 32000, 1});
ASSERT_NE(nullptr, enc2);
EXPECT_EQ(32000, enc2->SampleRateHz());
}
TEST(AudioEncoderFactoryTemplateTest, L16) {
auto factory = CreateAudioEncoderFactory<AudioEncoderL16>();
EXPECT_THAT(