Reason for revert:
voice_engine_unittests: FilePlayerTest.PlayWavPcm16File and FilePlayerTest.PlayWavPcmuFile fail on 32-bit android (android_rel and android-dbg try bots, Android32 Tests (L Nexus5) and Android32 Tests (L Nexus7.2) build bots).
Not sure why this would happen, since I just moved the test without modifying it. Some test filtering that no longer manages to disable them? Anyway, reverting until I know how to fix.
This was actually caught by the try bots, but I missed it because I was manually ignoring them because of an error with the bots. :-(
Original issue's description:
> Move FilePlayer and FileRecorder to Voice Engine
>
> Because Voice Engine was the only user.
>
> R=perkj@webrtc.org, solenberg@webrtc.org
>
> Committed: 65874b163e
TBR=perkj@webrtc.org,solenberg@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Review-Url: https://codereview.webrtc.org/2092633002
Cr-Commit-Position: refs/heads/master@{#13267}
117 lines
4.0 KiB
C++
117 lines
4.0 KiB
C++
/*
|
|
* 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/common_types.h"
|
|
#include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h"
|
|
#include "webrtc/modules/include/module_common_types.h"
|
|
#include "webrtc/modules/utility/source/coder.h"
|
|
|
|
namespace webrtc {
|
|
namespace {
|
|
AudioCodingModule::Config GetAcmConfig(uint32_t id) {
|
|
AudioCodingModule::Config config;
|
|
// This class does not handle muted output.
|
|
config.neteq_config.enable_muted_state = false;
|
|
config.id = id;
|
|
config.decoder_factory = CreateBuiltinAudioDecoderFactory();
|
|
return config;
|
|
}
|
|
} // namespace
|
|
|
|
AudioCoder::AudioCoder(uint32_t instance_id)
|
|
: acm_(AudioCodingModule::Create(GetAcmConfig(instance_id))),
|
|
receive_codec_(),
|
|
encode_timestamp_(0),
|
|
encoded_data_(nullptr),
|
|
encoded_length_in_bytes_(0),
|
|
decode_timestamp_(0) {
|
|
acm_->InitializeReceiver();
|
|
acm_->RegisterTransportCallback(this);
|
|
}
|
|
|
|
AudioCoder::~AudioCoder() {}
|
|
|
|
int32_t AudioCoder::SetEncodeCodec(const CodecInst& codec_inst) {
|
|
const bool success = codec_manager_.RegisterEncoder(codec_inst) &&
|
|
codec_manager_.MakeEncoder(&rent_a_codec_, acm_.get());
|
|
return success ? 0 : -1;
|
|
}
|
|
|
|
int32_t AudioCoder::SetDecodeCodec(const CodecInst& codec_inst) {
|
|
if (acm_->RegisterReceiveCodec(codec_inst, [&] {
|
|
return rent_a_codec_.RentIsacDecoder(codec_inst.plfreq);
|
|
}) == -1) {
|
|
return -1;
|
|
}
|
|
memcpy(&receive_codec_, &codec_inst, sizeof(CodecInst));
|
|
return 0;
|
|
}
|
|
|
|
int32_t AudioCoder::Decode(AudioFrame& decoded_audio,
|
|
uint32_t samp_freq_hz,
|
|
const int8_t* incoming_payload,
|
|
size_t payload_length) {
|
|
if (payload_length > 0) {
|
|
const uint8_t payload_type = receive_codec_.pltype;
|
|
decode_timestamp_ += receive_codec_.pacsize;
|
|
if (acm_->IncomingPayload((const uint8_t*)incoming_payload, payload_length,
|
|
payload_type, decode_timestamp_) == -1) {
|
|
return -1;
|
|
}
|
|
}
|
|
bool muted;
|
|
int32_t ret =
|
|
acm_->PlayoutData10Ms((uint16_t)samp_freq_hz, &decoded_audio, &muted);
|
|
RTC_DCHECK(!muted);
|
|
return ret;
|
|
}
|
|
|
|
int32_t AudioCoder::PlayoutData(AudioFrame& decoded_audio,
|
|
uint16_t& samp_freq_hz) {
|
|
bool muted;
|
|
int32_t ret = acm_->PlayoutData10Ms(samp_freq_hz, &decoded_audio, &muted);
|
|
RTC_DCHECK(!muted);
|
|
return ret;
|
|
}
|
|
|
|
int32_t AudioCoder::Encode(const AudioFrame& audio,
|
|
int8_t* encoded_data,
|
|
size_t& encoded_length_in_bytes) {
|
|
// Fake a timestamp in case audio doesn't contain a correct timestamp.
|
|
// Make a local copy of the audio frame since audio is const
|
|
AudioFrame audio_frame;
|
|
audio_frame.CopyFrom(audio);
|
|
audio_frame.timestamp_ = encode_timestamp_;
|
|
encode_timestamp_ += static_cast<uint32_t>(audio_frame.samples_per_channel_);
|
|
|
|
// For any codec with a frame size that is longer than 10 ms the encoded
|
|
// length in bytes should be zero until a a full frame has been encoded.
|
|
encoded_length_in_bytes_ = 0;
|
|
if (acm_->Add10MsData((AudioFrame&)audio_frame) == -1) {
|
|
return -1;
|
|
}
|
|
encoded_data_ = encoded_data;
|
|
encoded_length_in_bytes = encoded_length_in_bytes_;
|
|
return 0;
|
|
}
|
|
|
|
int32_t AudioCoder::SendData(FrameType /* frame_type */,
|
|
uint8_t /* payload_type */,
|
|
uint32_t /* time_stamp */,
|
|
const uint8_t* payload_data,
|
|
size_t payload_size,
|
|
const RTPFragmentationHeader* /* fragmentation*/) {
|
|
memcpy(encoded_data_, payload_data, sizeof(uint8_t) * payload_size);
|
|
encoded_length_in_bytes_ = payload_size;
|
|
return 0;
|
|
}
|
|
|
|
} // namespace webrtc
|