VoE Changes to enable dual_streaming.

TEST=added new unit-test

This CL depends on issue 933015 http://webrtc-codereview.appspot.com/933015/
which is under review. Should be committed after issue 933015 is committed.
Committed: https://code.google.com/p/webrtc/source/detail?r=3231
Review URL: https://webrtc-codereview.appspot.com/970005

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3257 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
turaj@webrtc.org 2012-12-11 02:15:12 +00:00
parent 36965b1803
commit 42259e7ebc
9 changed files with 741 additions and 52 deletions

View File

@ -15,3 +15,22 @@
...
fun:__tz*
}
{
bug_1194
ThreadSanitizer:Race
fun:webrtc::TracePosix::AddTime
fun:webrtc::TraceImpl::AddImpl
fun:webrtc::Trace::Add
fun:webrtc::VoEBaseImpl::CreateChannel
fun:webrtc::voe::::VoECodecTest::SetUp
fun:testing::internal::HandleSehExceptionsInMethodIfSupported
}
{
buganizer issue 7313086 TSAN: posix warning with 2 threads
ThreadSanitizer:Race
fun:arena_thread_freeres
fun:__libc_thread_freeres
fun:start_thread
}

View File

@ -5579,60 +5579,24 @@ Channel::GetRTPStatistics(CallStatistics& stats)
return 0;
}
int
Channel::SetFECStatus(bool enable, int redPayloadtype)
{
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId),
"Channel::SetFECStatus()");
int Channel::SetFECStatus(bool enable, int redPayloadtype) {
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId),
"Channel::SetFECStatus()");
CodecInst codec;
if (SetRedPayloadType(redPayloadtype) < 0) {
_engineStatisticsPtr->SetLastError(
VE_CODEC_ERROR, kTraceError,
"SetSecondarySendCodec() Failed to register RED ACM");
return -1;
}
// Get default RED settings from the ACM database
bool foundRED(false);
const WebRtc_UWord8 nSupportedCodecs = AudioCodingModule::NumberOfCodecs();
for (int idx = 0; (!foundRED && idx < nSupportedCodecs); idx++)
{
_audioCodingModule.Codec(idx, codec);
if (!STR_CASE_CMP(codec.plname, "RED"))
{
foundRED = true;
}
}
if (!foundRED)
{
_engineStatisticsPtr->SetLastError(
VE_CODEC_ERROR, kTraceError,
"SetFECStatus() RED is not supported");
return -1;
}
if (redPayloadtype != -1)
{
codec.pltype = redPayloadtype;
}
if (_audioCodingModule.RegisterSendCodec(codec) != 0)
{
_engineStatisticsPtr->SetLastError(
VE_AUDIO_CODING_MODULE_ERROR, kTraceError,
"SetFECStatus() RED registration in ACM module failed");
return -1;
}
if (_rtpRtcpModule->SetSendREDPayloadType(codec.pltype) != 0)
{
_engineStatisticsPtr->SetLastError(
VE_RTP_RTCP_MODULE_ERROR, kTraceError,
"SetFECStatus() RED registration in RTP/RTCP module failed");
return -1;
}
if (_audioCodingModule.SetFECStatus(enable) != 0)
{
_engineStatisticsPtr->SetLastError(
VE_AUDIO_CODING_MODULE_ERROR, kTraceError,
"SetFECStatus() failed to set FEC state in the ACM");
return -1;
}
return 0;
if (_audioCodingModule.SetFECStatus(enable) != 0) {
_engineStatisticsPtr->SetLastError(
VE_AUDIO_CODING_MODULE_ERROR, kTraceError,
"SetFECStatus() failed to set FEC state in the ACM");
return -1;
}
return 0;
}
int
@ -6632,5 +6596,83 @@ int Channel::ApmProcessRx(AudioFrame& frame) {
return 0;
}
int Channel::SetSecondarySendCodec(const CodecInst& codec,
int red_payload_type) {
if (SetRedPayloadType(red_payload_type) < 0) {
_engineStatisticsPtr->SetLastError(
VE_AUDIO_CODING_MODULE_ERROR, kTraceError,
"SetSecondarySendCodec() Failed to register RED ACM");
return -1;
}
if (_audioCodingModule.RegisterSecondarySendCodec(codec) < 0) {
_engineStatisticsPtr->SetLastError(
VE_AUDIO_CODING_MODULE_ERROR, kTraceError,
"SetSecondarySendCodec() Failed to register secondary send codec in "
"ACM");
return -1;
}
return 0;
}
void Channel::RemoveSecondarySendCodec() {
_audioCodingModule.UnregisterSecondarySendCodec();
}
int Channel::GetSecondarySendCodec(CodecInst* codec) {
if (_audioCodingModule.SecondarySendCodec(codec) < 0) {
_engineStatisticsPtr->SetLastError(
VE_AUDIO_CODING_MODULE_ERROR, kTraceError,
"GetSecondarySendCodec() Failed to get secondary sent codec from ACM");
return -1;
}
return 0;
}
int Channel::SetRedPayloadType(int red_payload_type) {
if (red_payload_type < 0) {
_engineStatisticsPtr->SetLastError(
VE_PLTYPE_ERROR, kTraceError,
"SetRedPayloadType() invalid RED paylaod type");
return -1;
}
CodecInst codec;
bool found_red = false;
// Get default RED settings from the ACM database
const int num_codecs = AudioCodingModule::NumberOfCodecs();
for (int idx = 0; idx < num_codecs; idx++) {
_audioCodingModule.Codec(idx, codec);
if (!STR_CASE_CMP(codec.plname, "RED")) {
found_red = true;
break;
}
}
if (!found_red) {
_engineStatisticsPtr->SetLastError(
VE_CODEC_ERROR, kTraceError,
"SetRedPayloadType() RED is not supported");
return -1;
}
codec.pltype = red_payload_type;
if (_audioCodingModule.RegisterSendCodec(codec) < 0) {
_engineStatisticsPtr->SetLastError(
VE_AUDIO_CODING_MODULE_ERROR, kTraceError,
"SetRedPayloadType() RED registration in ACM module failed");
return -1;
}
if (_rtpRtcpModule->SetSendREDPayloadType(red_payload_type) != 0) {
_engineStatisticsPtr->SetLastError(
VE_RTP_RTCP_MODULE_ERROR, kTraceError,
"SetRedPayloadType() RED registration in RTP/RTCP module failed");
return -1;
}
return 0;
}
} // namespace voe
} // namespace webrtc

View File

@ -150,6 +150,11 @@ public:
WebRtc_Word32 SetISACMaxRate(int rateBps);
WebRtc_Word32 SetISACMaxPayloadSize(int sizeBytes);
// VoE dual-streaming.
int SetSecondarySendCodec(const CodecInst& codec, int red_payload_type);
void RemoveSecondarySendCodec();
int GetSecondarySendCodec(CodecInst* codec);
// VoENetwork
WebRtc_Word32 RegisterExternalTransport(Transport& transport);
WebRtc_Word32 DeRegisterExternalTransport();
@ -532,6 +537,7 @@ private:
void RegisterReceiveCodecsToRTPModule();
int ApmProcessRx(AudioFrame& audioFrame);
int SetRedPayloadType(int red_payload_type);
private:
CriticalSectionWrapper& _fileCritSect;
CriticalSectionWrapper& _callbackCritSect;

View File

@ -64,6 +64,23 @@ public:
// |channel|.
virtual int GetSendCodec(int channel, CodecInst& codec) = 0;
// Sets the |codec| as secondary codec for |channel|. Registering a
// secondary send codec enables dual-streaming. In dual-streaming mode,
// payloads of the primary and the secondary codecs are packed in RED
// payloads with |red_payload_type| as payload type. The Secondary codec
// MUST have the same sampling rate as the primary codec, otherwise the
// codec cannot be registered and -1 is returned. This method fails if a
// primary codec is not yet set.
virtual int SetSecondarySendCodec(int channel, const CodecInst& codec,
int red_payload_type) = 0;
// Removes the secondary codec from |channel|. This will terminate
// dual-streaming.
virtual int RemoveSecondarySendCodec(int channel) = 0;
// Gets |codec| which is used as secondary codec in |channel|.
virtual int GetSecondarySendCodec(int channel, CodecInst& codec) = 0;
// Gets the currently received |codec| for a specific |channel|.
virtual int GetRecCodec(int channel, CodecInst& codec) = 0;

View File

@ -85,6 +85,9 @@
#define VE_CANNOT_GET_SEND_CODEC 8110
#define VE_CANNOT_GET_REC_CODEC 8111
#define VE_ALREADY_INITED 8112
#define VE_CANNOT_SET_SECONDARY_SEND_CODEC 8113
#define VE_CANNOT_GET_SECONDARY_SEND_CODEC 8114
#define VE_CANNOT_REMOVE_SECONDARY_SEND_CODEC 8115
// Errors causing limited functionality
#define VE_RTCP_SOCKET_ERROR 9001

View File

@ -657,6 +657,111 @@ void VoECodecImpl::ExternalToACMCodecRepresentation(CodecInst& toInst,
}
}
int VoECodecImpl::SetSecondarySendCodec(int channel, const CodecInst& codec,
int red_payload_type) {
CodecInst copy_codec;
ExternalToACMCodecRepresentation(copy_codec, codec);
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"SetSecondarySendCodec(channel=%d, codec)", channel);
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
"codec: plname=%s, pacsize=%d, plfreq=%d, pltype=%d, "
"channels=%d, rate=%d", codec.plname, codec.pacsize,
codec.plfreq, codec.pltype, codec.channels, codec.rate);
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
}
// External sanity checks performed outside the ACM
if ((STR_CASE_CMP(copy_codec.plname, "L16") == 0) &&
(copy_codec.pacsize >= 960)) {
_shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
"SetSecondarySendCodec() invalid L16 packet size");
return -1;
}
// None of the following codecs can be registered as the secondary encoder.
if (!STR_CASE_CMP(copy_codec.plname, "CN") ||
!STR_CASE_CMP(copy_codec.plname, "TELEPHONE-EVENT") ||
!STR_CASE_CMP(copy_codec.plname, "RED")) {
_shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
"SetSecondarySendCodec() invalid codec name");
return -1;
}
// Only mono and stereo are supported.
if ((copy_codec.channels != 1) && (copy_codec.channels != 2)) {
_shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
"SetSecondarySendCodec() invalid number of channels");
return -1;
}
voe::ScopedChannel sc(_shared->channel_manager(), channel);
voe::Channel* channelPtr = sc.ChannelPtr();
if (channelPtr == NULL) {
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
"SetSecondarySendCodec() failed to locate channel");
return -1;
}
if (!AudioCodingModule::IsCodecValid(copy_codec)) {
_shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
"SetSecondarySendCodec() invalid codec");
return -1;
}
if (channelPtr->SetSecondarySendCodec(copy_codec, red_payload_type) != 0) {
_shared->SetLastError(VE_CANNOT_SET_SECONDARY_SEND_CODEC, kTraceError,
"SetSecondarySendCodec() failed to set secondary "
"send codec");
return -1;
}
return 0;
}
int VoECodecImpl::GetSecondarySendCodec(int channel, CodecInst& codec) {
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"GetSecondarySendCodec(channel=%d, codec=?)", channel);
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
}
voe::ScopedChannel sc(_shared->channel_manager(), channel);
voe::Channel* channelPtr = sc.ChannelPtr();
if (channelPtr == NULL) {
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
"GetSecondarySendCodec() failed to locate channel");
return -1;
}
CodecInst acm_codec;
if (channelPtr->GetSecondarySendCodec(&acm_codec) != 0) {
_shared->SetLastError(VE_CANNOT_GET_SECONDARY_SEND_CODEC, kTraceError,
"GetSecondarySendCodec() failed to get secondary "
"send codec");
return -1;
}
ACMToExternalCodecRepresentation(codec, acm_codec);
WEBRTC_TRACE(kTraceStateInfo, kTraceVoice,
VoEId(_shared->instance_id(), -1),
"GetSecondarySendCodec() => plname=%s, pacsize=%d, plfreq=%d, "
"channels=%d, rate=%d", codec.plname, codec.pacsize,
codec.plfreq, codec.channels, codec.rate);
return 0;
}
int VoECodecImpl::RemoveSecondarySendCodec(int channel) {
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"RemoveSecondarySendCodec(channel=%d)", channel);
voe::ScopedChannel sc(_shared->channel_manager(), channel);
voe::Channel* channelPtr = sc.ChannelPtr();
if (channelPtr == NULL) {
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
"RemoveSecondarySendCodec() failed to locate "
"channel");
return -1;
}
channelPtr->RemoveSecondarySendCodec();
return 0;
}
#endif // WEBRTC_VOICE_ENGINE_CODEC_API
} // namespace webrtc

View File

@ -70,6 +70,14 @@ public:
VadModes& mode,
bool& disabledDTX);
// Dual-streaming
virtual int SetSecondarySendCodec(int channel, const CodecInst& codec,
int red_payload_type);
virtual int RemoveSecondarySendCodec(int channel);
virtual int GetSecondarySendCodec(int channel, CodecInst& codec);
protected:
VoECodecImpl(voe::SharedData* shared);
virtual ~VoECodecImpl();

View File

@ -0,0 +1,488 @@
/*
* Copyright (c) 2012 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/voice_engine/include/voe_codec.h"
#include "gtest/gtest.h"
#include "webrtc/modules/audio_device/include/audio_device.h"
#include "webrtc/modules/audio_device/include/audio_device_defines.h"
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
#include "webrtc/voice_engine/include/voe_base.h"
#include "webrtc/voice_engine/include/voe_hardware.h"
#include "webrtc/voice_engine/voice_engine_defines.h"
namespace webrtc {
namespace voe {
namespace {
class FakeAudioDeviceModule : public AudioDeviceModule {
public:
FakeAudioDeviceModule() {}
~FakeAudioDeviceModule() {}
virtual int32_t AddRef() { return 0; }
virtual int32_t Release() { return 0; }
virtual int32_t RegisterEventObserver(AudioDeviceObserver* eventCallback) {
return 0;
}
virtual int32_t RegisterAudioCallback(AudioTransport* audioCallback) {
return 0;
}
virtual int32_t Init() { return 0; }
virtual int32_t SpeakerIsAvailable(bool* available) {
*available = true;
return 0;
}
virtual int32_t InitSpeaker() { return 0; }
virtual int32_t SetPlayoutDevice(uint16_t index) { return 0; }
virtual int32_t SetPlayoutDevice(WindowsDeviceType device) { return 0; }
virtual int32_t SetStereoPlayout(bool enable) { return 0; }
virtual int32_t StopPlayout() { return 0; }
virtual int32_t MicrophoneIsAvailable(bool* available) {
*available = true;
return 0;
}
virtual int32_t InitMicrophone() { return 0; }
virtual int32_t SetRecordingDevice(uint16_t index) { return 0; }
virtual int32_t SetRecordingDevice(WindowsDeviceType device) { return 0; }
virtual int32_t SetStereoRecording(bool enable) { return 0; }
virtual int32_t SetAGC(bool enable) { return 0; }
virtual int32_t StopRecording() { return 0; }
virtual int32_t TimeUntilNextProcess() { return 0; }
virtual int32_t Process() { return 0; }
virtual int32_t Terminate() { return 0; }
virtual int32_t ActiveAudioLayer(AudioLayer* audioLayer) const {
assert(false);
return 0;
}
virtual ErrorCode LastError() const {
assert(false);
return kAdmErrNone;
}
virtual bool Initialized() const {
assert(false);
return true;
}
virtual int16_t PlayoutDevices() {
assert(false);
return 0;
}
virtual int16_t RecordingDevices() {
assert(false);
return 0;
}
virtual int32_t PlayoutDeviceName(uint16_t index,
char name[kAdmMaxDeviceNameSize],
char guid[kAdmMaxGuidSize]) {
assert(false);
return 0;
}
virtual int32_t RecordingDeviceName(uint16_t index,
char name[kAdmMaxDeviceNameSize],
char guid[kAdmMaxGuidSize]) {
assert(false);
return 0;
}
virtual int32_t PlayoutIsAvailable(bool* available) {
assert(false);
return 0;
}
virtual int32_t InitPlayout() {
assert(false);
return 0;
}
virtual bool PlayoutIsInitialized() const {
assert(false);
return true;
}
virtual int32_t RecordingIsAvailable(bool* available) {
assert(false);
return 0;
}
virtual int32_t InitRecording() {
assert(false);
return 0;
}
virtual bool RecordingIsInitialized() const {
assert(false);
return true;
}
virtual int32_t StartPlayout() {
assert(false);
return 0;
}
virtual bool Playing() const {
assert(false);
return false;
}
virtual int32_t StartRecording() {
assert(false);
return 0;
}
virtual bool Recording() const {
assert(false);
return false;
}
virtual bool AGC() const {
assert(false);
return true;
}
virtual int32_t SetWaveOutVolume(uint16_t volumeLeft,
uint16_t volumeRight) {
assert(false);
return 0;
}
virtual int32_t WaveOutVolume(uint16_t* volumeLeft,
uint16_t* volumeRight) const {
assert(false);
return 0;
}
virtual bool SpeakerIsInitialized() const {
assert(false);
return true;
}
virtual bool MicrophoneIsInitialized() const {
assert(false);
return true;
}
virtual int32_t SpeakerVolumeIsAvailable(bool* available) {
assert(false);
return 0;
}
virtual int32_t SetSpeakerVolume(uint32_t volume) {
assert(false);
return 0;
}
virtual int32_t SpeakerVolume(uint32_t* volume) const {
assert(false);
return 0;
}
virtual int32_t MaxSpeakerVolume(uint32_t* maxVolume) const {
assert(false);
return 0;
}
virtual int32_t MinSpeakerVolume(uint32_t* minVolume) const {
assert(false);
return 0;
}
virtual int32_t SpeakerVolumeStepSize(uint16_t* stepSize) const {
assert(false);
return 0;
}
virtual int32_t MicrophoneVolumeIsAvailable(bool* available) {
assert(false);
return 0;
}
virtual int32_t SetMicrophoneVolume(uint32_t volume) {
assert(false);
return 0;
}
virtual int32_t MicrophoneVolume(uint32_t* volume) const {
assert(false);
return 0;
}
virtual int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const {
assert(false);
return 0;
}
virtual int32_t MinMicrophoneVolume(uint32_t* minVolume) const {
assert(false);
return 0;
}
virtual int32_t MicrophoneVolumeStepSize(uint16_t* stepSize) const {
assert(false);
return 0;
}
virtual int32_t SpeakerMuteIsAvailable(bool* available) {
assert(false);
return 0;
}
virtual int32_t SetSpeakerMute(bool enable) {
assert(false);
return 0;
}
virtual int32_t SpeakerMute(bool* enabled) const {
assert(false);
return 0;
}
virtual int32_t MicrophoneMuteIsAvailable(bool* available) {
assert(false);
return 0;
}
virtual int32_t SetMicrophoneMute(bool enable) {
assert(false);
return 0;
}
virtual int32_t MicrophoneMute(bool* enabled) const {
assert(false);
return 0;
}
virtual int32_t MicrophoneBoostIsAvailable(bool* available) {
assert(false);
return 0;
}
virtual int32_t SetMicrophoneBoost(bool enable) {
assert(false);
return 0;
}
virtual int32_t MicrophoneBoost(bool* enabled) const {
assert(false);
return 0;
}
virtual int32_t StereoPlayoutIsAvailable(bool* available) const {
*available = false;
return 0;
}
virtual int32_t StereoPlayout(bool* enabled) const {
assert(false);
return 0;
}
virtual int32_t StereoRecordingIsAvailable(bool* available) const {
*available = false;
return 0;
}
virtual int32_t StereoRecording(bool* enabled) const {
assert(false);
return 0;
}
virtual int32_t SetRecordingChannel(const ChannelType channel) {
assert(false);
return 0;
}
virtual int32_t RecordingChannel(ChannelType* channel) const {
assert(false);
return 0;
}
virtual int32_t SetPlayoutBuffer(const BufferType type,
uint16_t sizeMS = 0) {
assert(false);
return 0;
}
virtual int32_t PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const {
assert(false);
return 0;
}
virtual int32_t PlayoutDelay(uint16_t* delayMS) const {
assert(false);
return 0;
}
virtual int32_t RecordingDelay(uint16_t* delayMS) const {
assert(false);
return 0;
}
virtual int32_t CPULoad(uint16_t* load) const {
assert(false);
return 0;
}
virtual int32_t StartRawOutputFileRecording(
const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
assert(false);
return 0;
}
virtual int32_t StopRawOutputFileRecording() {
assert(false);
return 0;
}
virtual int32_t StartRawInputFileRecording(
const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
assert(false);
return 0;
}
virtual int32_t StopRawInputFileRecording() {
assert(false);
return 0;
}
virtual int32_t SetRecordingSampleRate(const uint32_t samplesPerSec) {
assert(false);
return 0;
}
virtual int32_t RecordingSampleRate(uint32_t* samplesPerSec) const {
assert(false);
return 0;
}
virtual int32_t SetPlayoutSampleRate(const uint32_t samplesPerSec) {
assert(false);
return 0;
}
virtual int32_t PlayoutSampleRate(uint32_t* samplesPerSec) const {
assert(false);
return 0;
}
virtual int32_t ResetAudioDevice() {
assert(false);
return 0;
}
virtual int32_t SetLoudspeakerStatus(bool enable) {
assert(false);
return 0;
}
virtual int32_t GetLoudspeakerStatus(bool* enabled) const {
assert(false);
return 0;
}
virtual int32_t EnableBuiltInAEC(bool enable) {
assert(false);
return -1;
}
virtual bool BuiltInAECIsEnabled() const {
assert(false);
return false;
}
};
class VoECodecTest : public ::testing::Test {
protected:
VoECodecTest()
: voe_(VoiceEngine::Create()),
base_(VoEBase::GetInterface(voe_)),
voe_codec_(VoECodec::GetInterface(voe_)),
channel_(-1),
adm_(new FakeAudioDeviceModule),
red_payload_type_(-1) {
}
~VoECodecTest() {}
void TearDown() {
base_->DeleteChannel(channel_);
base_->Terminate();
base_->Release();
voe_codec_->Release();
VoiceEngine::Delete(voe_);
}
void SetUp() {
// Check if all components are valid.
ASSERT_TRUE(voe_ != NULL);
ASSERT_TRUE(base_ != NULL);
ASSERT_TRUE(voe_codec_ != NULL);
ASSERT_TRUE(adm_.get() != NULL);
ASSERT_EQ(0, base_->Init(adm_.get()));
channel_ = base_->CreateChannel();
ASSERT_NE(-1, channel_);
CodecInst my_codec;
bool primary_found = false;
bool valid_secondary_found = false;
bool invalid_secondary_found = false;
// Find primary and secondary codecs.
int num_codecs = voe_codec_->NumOfCodecs();
int n = 0;
while (n < num_codecs && (!primary_found || !valid_secondary_found ||
!invalid_secondary_found || red_payload_type_ < 0)) {
EXPECT_EQ(0, voe_codec_->GetCodec(n, my_codec));
if (!STR_CASE_CMP(my_codec.plname, "isac") && my_codec.plfreq == 16000) {
memcpy(&valid_secondary_, &my_codec, sizeof(my_codec));
valid_secondary_found = true;
} else if (!STR_CASE_CMP(my_codec.plname, "isac") &&
my_codec.plfreq == 32000) {
memcpy(&invalid_secondary_, &my_codec, sizeof(my_codec));
invalid_secondary_found = true;
} else if (!STR_CASE_CMP(my_codec.plname, "L16") &&
my_codec.plfreq == 16000) {
memcpy(&primary_, &my_codec, sizeof(my_codec));
primary_found = true;
} else if (!STR_CASE_CMP(my_codec.plname, "RED")) {
red_payload_type_ = my_codec.pltype;
}
n++;
}
EXPECT_TRUE(primary_found);
EXPECT_TRUE(valid_secondary_found);
EXPECT_TRUE(invalid_secondary_found);
EXPECT_NE(-1, red_payload_type_);
}
VoiceEngine* voe_;
VoEBase* base_;
VoECodec* voe_codec_;
int channel_;
CodecInst primary_;
CodecInst valid_secondary_;
scoped_ptr<FakeAudioDeviceModule> adm_;
// A codec which is not valid to be registered as secondary codec.
CodecInst invalid_secondary_;
int red_payload_type_;
};
TEST_F(VoECodecTest, DualStreamSetSecondaryBeforePrimaryFails) {
// Setting secondary before a primary is registered should fail.
EXPECT_EQ(-1, voe_codec_->SetSecondarySendCodec(channel_, valid_secondary_,
red_payload_type_));
red_payload_type_ = 1;
}
TEST_F(VoECodecTest, DualStreamRegisterWithWrongInputsFails) {
// Register primary codec.
EXPECT_EQ(0, voe_codec_->SetSendCodec(channel_, primary_));
// Wrong secondary.
EXPECT_EQ(-1, voe_codec_->SetSecondarySendCodec(channel_, invalid_secondary_,
red_payload_type_));
// Wrong paylaod.
EXPECT_EQ(-1, voe_codec_->SetSecondarySendCodec(channel_, valid_secondary_,
-1));
// Wrong channel.
EXPECT_EQ(-1, voe_codec_->SetSecondarySendCodec(channel_ + 1,
valid_secondary_,
red_payload_type_));
}
TEST_F(VoECodecTest, DualStreamGetSecodaryEncoder) {
// Register primary codec.
EXPECT_EQ(0, voe_codec_->SetSendCodec(channel_, primary_));
// Register a valid codec.
EXPECT_EQ(0, voe_codec_->SetSecondarySendCodec(channel_, valid_secondary_,
red_payload_type_));
CodecInst my_codec;
// Get secondary codec from wrong channel.
EXPECT_EQ(-1, voe_codec_->GetSecondarySendCodec(channel_ + 1, my_codec));
// Get secondary and compare.
memset(&my_codec, 0, sizeof(my_codec));
EXPECT_EQ(0, voe_codec_->GetSecondarySendCodec(channel_, my_codec));
EXPECT_EQ(valid_secondary_.plfreq, my_codec.plfreq);
EXPECT_EQ(valid_secondary_.channels, my_codec.channels);
EXPECT_EQ(valid_secondary_.pacsize, my_codec.pacsize);
EXPECT_EQ(valid_secondary_.rate, my_codec.rate);
EXPECT_EQ(valid_secondary_.pltype, my_codec.pltype);
EXPECT_EQ(0, STR_CASE_CMP(valid_secondary_.plname, my_codec.plname));
}
TEST_F(VoECodecTest, DualStreamRemoveSecondaryCodec) {
// Register primary codec.
EXPECT_EQ(0, voe_codec_->SetSendCodec(channel_, primary_));
// Register a valid codec.
EXPECT_EQ(0, voe_codec_->SetSecondarySendCodec(channel_, valid_secondary_,
red_payload_type_));
// Remove from wrong channel.
EXPECT_EQ(-1, voe_codec_->RemoveSecondarySendCodec(channel_ + 1));
EXPECT_EQ(0, voe_codec_->RemoveSecondarySendCodec(channel_));
CodecInst my_codec;
// Get should fail, if secondary is removed.
EXPECT_EQ(-1, voe_codec_->GetSecondarySendCodec(channel_, my_codec));
}
} // namespace
} // namespace voe
} // namespace webrtc

View File

@ -146,6 +146,7 @@
'output_mixer_unittest.cc',
'transmit_mixer_unittest.cc',
'voe_audio_processing_unittest.cc',
'voe_codec_unittest.cc',
],
},
], # targets