Remove AudioCodingModule::Process()

An earlier change moved the encoding work from Process to
Add10MsData; process was just a no-op.

BUG=3520
COAUTHOR=kwiberg@webrtc.org
R=henrika@webrtc.org, minyue@webrtc.org, tina.legrand@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/43439004

Cr-Commit-Position: refs/heads/master@{#8553}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8553 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrik.lundin@webrtc.org 2015-03-02 12:29:30 +00:00
parent 25dd1dbb9f
commit f56c162310
21 changed files with 54 additions and 142 deletions

View File

@ -96,17 +96,13 @@ class AcmReceiverTestOldApi : public AudioPacketizationCallback,
frame.num_channels_ = codec.channels;
memset(frame.data_, 0, frame.samples_per_channel_ * frame.num_channels_ *
sizeof(int16_t));
int num_bytes = 0;
packet_sent_ = false;
last_packet_send_timestamp_ = timestamp_;
while (num_bytes == 0) {
while (!packet_sent_) {
frame.timestamp_ = timestamp_;
timestamp_ += frame.samples_per_channel_;
ASSERT_EQ(0, acm_->Add10MsData(frame));
num_bytes = acm_->Process();
ASSERT_GE(num_bytes, 0);
ASSERT_GE(acm_->Add10MsData(frame), 0);
}
ASSERT_TRUE(packet_sent_); // Sanity check.
}
// Last element of id should be negative.

View File

@ -80,10 +80,10 @@ Packet* AcmSendTestOldApi::NextPacket() {
input_frame_.num_channels_,
input_frame_.data_);
}
CHECK_EQ(0, acm_->Add10MsData(input_frame_));
data_to_send_ = false;
CHECK_GE(acm_->Add10MsData(input_frame_), 0);
input_frame_.timestamp_ += input_block_size_samples_;
int32_t encoded_bytes = acm_->Process();
if (encoded_bytes > 0) {
if (data_to_send_) {
// Encoded packet received.
return CreatePacket();
}
@ -106,6 +106,7 @@ int32_t AcmSendTestOldApi::SendData(
timestamp_ = timestamp;
last_payload_vec_.assign(payload_data, payload_data + payload_len_bytes);
assert(last_payload_vec_.size() == payload_len_bytes);
data_to_send_ = true;
return 0;
}

View File

@ -79,6 +79,7 @@ class AcmSendTestOldApi : public AudioPacketizationCallback,
uint32_t timestamp_;
uint16_t sequence_number_;
std::vector<uint8_t> last_payload_vec_;
bool data_to_send_;
DISALLOW_COPY_AND_ASSIGN(AcmSendTestOldApi);
};

View File

@ -145,7 +145,6 @@ AudioCodingModuleImpl::AudioCodingModuleImpl(
aux_rtp_header_(NULL),
receiver_initialized_(false),
first_10ms_data_(false),
last_encode_value_(0),
callback_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
packetization_callback_(NULL),
vad_callback_(NULL) {
@ -218,11 +217,6 @@ AudioCodingModuleImpl::~AudioCodingModuleImpl() {
"Destroyed");
}
int32_t AudioCodingModuleImpl::Process() {
CriticalSectionScoped lock(acm_crit_sect_);
return last_encode_value_;
}
int32_t AudioCodingModuleImpl::Encode() {
// Make room for 1 RED payload.
uint8_t stream[2 * MAX_PAYLOAD_SIZE_BYTE];
@ -752,15 +746,7 @@ int AudioCodingModuleImpl::RegisterTransportCallback(
// Add 10MS of raw (PCM) audio data to the encoder.
int AudioCodingModuleImpl::Add10MsData(const AudioFrame& audio_frame) {
int r = Add10MsDataInternal(audio_frame);
if (r < 0) {
CriticalSectionScoped lock(acm_crit_sect_);
last_encode_value_ = -1;
} else {
int r_encode = Encode();
CriticalSectionScoped lock(acm_crit_sect_);
last_encode_value_ = r_encode;
}
return r;
return r < 0 ? r : Encode();
}
int AudioCodingModuleImpl::Add10MsDataInternal(const AudioFrame& audio_frame) {
@ -1563,10 +1549,9 @@ const CodecInst* AudioCodingImpl::GetSenderCodecInst() {
}
int AudioCodingImpl::Add10MsAudio(const AudioFrame& audio_frame) {
if (acm_old_->Add10MsData(audio_frame) != 0) {
if (acm_old_->Add10MsDataInternal(audio_frame) != 0)
return -1;
}
return acm_old_->Process();
return acm_old_->Encode();
}
const ReceiverInfo* AudioCodingImpl::GetReceiverInfo() const {

View File

@ -24,6 +24,7 @@
namespace webrtc {
class CriticalSectionWrapper;
class AudioCodingImpl;
namespace acm2 {
@ -32,12 +33,11 @@ class ACMGenericCodec;
class AudioCodingModuleImpl : public AudioCodingModule {
public:
friend webrtc::AudioCodingImpl;
explicit AudioCodingModuleImpl(const AudioCodingModule::Config& config);
~AudioCodingModuleImpl();
// Process any pending tasks such as timeouts.
virtual int32_t Process() OVERRIDE;
/////////////////////////////////////////
// Sender
//
@ -335,7 +335,6 @@ class AudioCodingModuleImpl : public AudioCodingModule {
AudioFrame preprocess_frame_ GUARDED_BY(acm_crit_sect_);
bool first_10ms_data_ GUARDED_BY(acm_crit_sect_);
int last_encode_value_ GUARDED_BY(acm_crit_sect_);
CriticalSectionWrapper* callback_crit_sect_;
AudioPacketizationCallback* packetization_callback_

View File

@ -193,15 +193,15 @@ class AudioCodingModuleTestOldApi : public ::testing::Test {
}
virtual void InsertAudio() {
ASSERT_EQ(0, acm_->Add10MsData(input_frame_));
ASSERT_GE(acm_->Add10MsData(input_frame_), 0);
VerifyEncoding();
input_frame_.timestamp_ += kNumSamples10ms;
}
virtual void Encode() {
int32_t encoded_bytes = acm_->Process();
// Expect to get one packet with two bytes per sample, or no packet at all,
// depending on how many 10 ms blocks go into |codec_.pacsize|.
EXPECT_TRUE(encoded_bytes == 2 * codec_.pacsize || encoded_bytes == 0);
virtual void VerifyEncoding() {
int last_length = packet_cb_.last_payload_len_bytes();
EXPECT_TRUE(last_length == 2 * codec_.pacsize || last_length == 0)
<< "Last encoded packet was " << last_length << " bytes.";
}
const int id_;
@ -316,7 +316,6 @@ TEST_F(AudioCodingModuleTestOldApi, TransportCallbackIsInvokedForEachPacket) {
if (packet_cb_.num_calls() > 0)
EXPECT_EQ(kAudioFrameSpeech, packet_cb_.last_frame_type());
InsertAudio();
Encode();
}
EXPECT_EQ(kLoops / k10MsBlocksPerPacket, packet_cb_.num_calls());
EXPECT_EQ(kAudioFrameSpeech, packet_cb_.last_frame_type());
@ -330,13 +329,6 @@ TEST_F(AudioCodingModuleTestOldApi, TransportCallbackIsInvokedForEachPacket) {
class AudioCodingModuleTestWithComfortNoiseOldApi
: public AudioCodingModuleTestOldApi {
protected:
void Encode() override {
int32_t encoded_bytes = acm_->Process();
// Expect either one packet with 9 comfort noise parameters, or no packet
// at all.
EXPECT_TRUE(encoded_bytes == 9 || encoded_bytes == 0);
}
void RegisterCngCodec(int rtp_payload_type) {
CodecInst codec;
AudioCodingModule::Codec("CN", &codec, kSampleRateHz, 1);
@ -345,6 +337,12 @@ class AudioCodingModuleTestWithComfortNoiseOldApi
ASSERT_EQ(0, acm_->RegisterSendCodec(codec));
}
void VerifyEncoding() override {
int last_length = packet_cb_.last_payload_len_bytes();
EXPECT_TRUE(last_length == 9 || last_length == 0)
<< "Last encoded packet was " << last_length << " bytes.";
}
void DoTest(int blocks_per_packet, int cng_pt) {
const int kLoops = 40;
// This array defines the expected frame types, and when they should arrive.
@ -371,7 +369,6 @@ class AudioCodingModuleTestWithComfortNoiseOldApi
int num_calls_before = packet_cb_.num_calls();
EXPECT_EQ(i / blocks_per_packet, num_calls_before);
InsertAudio();
Encode();
int num_calls = packet_cb_.num_calls();
if (num_calls == num_calls_before + 1) {
EXPECT_EQ(expectation[num_calls - 1].ix, i);
@ -493,7 +490,6 @@ class AudioCodingModuleMtTestOldApi : public AudioCodingModuleTestOldApi {
}
++send_count_;
InsertAudio();
Encode();
if (TestDone()) {
test_complete_->Set();
}
@ -586,7 +582,6 @@ class AcmIsacMtTestOldApi : public AudioCodingModuleMtTestOldApi {
int loop_counter = 0;
while (packet_cb_.last_payload_len_bytes() == 0) {
InsertAudio();
Encode();
ASSERT_LT(loop_counter++, 10);
}
// Set |last_packet_number_| to one less that |num_calls| so that the packet
@ -632,7 +627,9 @@ class AcmIsacMtTestOldApi : public AudioCodingModuleMtTestOldApi {
AudioCodingModuleTestOldApi::InsertAudio();
}
void Encode() { ASSERT_GE(acm_->Process(), 0); }
// Override the verification function with no-op, since iSAC produces variable
// payload sizes.
void VerifyEncoding() override {}
// This method is the same as AudioCodingModuleMtTestOldApi::TestDone(), but
// here it is using the constants defined in this class (i.e., shorter test

View File

@ -101,8 +101,6 @@ class AudioCodingModule {
static AudioCodingModule* Create(int id, Clock* clock);
virtual ~AudioCodingModule() {};
virtual int32_t Process() = 0;
///////////////////////////////////////////////////////////////////////////
// Utility functions
//
@ -317,9 +315,12 @@ class AudioCodingModule {
///////////////////////////////////////////////////////////////////////////
// int32_t Add10MsData()
// Add 10MS of raw (PCM) audio data to the encoder. If the sampling
// Add 10MS of raw (PCM) audio data and encode it. If the sampling
// frequency of the audio does not match the sampling frequency of the
// current encoder ACM will resample the audio.
// current encoder ACM will resample the audio. If an encoded packet was
// produced, it will be delivered via the callback object registered using
// RegisterTransportCallback, and the return value from this function will
// be the number of bytes encoded.
//
// Input:
// -audio_frame : the input audio frame, containing raw audio
@ -328,10 +329,8 @@ class AudioCodingModule {
// AudioFrame.
//
// Return value:
// 0 successfully added the frame.
// -1 some error occurred and data is not added.
// < -1 to add the frame to the buffer n samples had to be
// overwritten, -n is the return value in this case.
// >= 0 number of bytes encoded.
// -1 some error occurred.
//
virtual int32_t Add10MsData(const AudioFrame& audio_frame) = 0;

View File

@ -411,33 +411,11 @@ bool APITest::PushAudioRunB() {
bool APITest::ProcessRunA() {
_processEventA->Wait(100);
if (_acmA->Process() < 0) {
// do not print error message if there is no encoder
bool thereIsEncoder;
{
ReadLockScoped rl(_apiTestRWLock);
thereIsEncoder = _thereIsEncoderA;
}
if (thereIsEncoder) {
fprintf(stderr, "\n>>>>> Process Failed at A <<<<<\n");
}
}
return true;
}
bool APITest::ProcessRunB() {
_processEventB->Wait(100);
if (_acmB->Process() < 0) {
bool thereIsEncoder;
{
ReadLockScoped rl(_apiTestRWLock);
thereIsEncoder = _thereIsEncoderB;
}
if (thereIsEncoder) {
fprintf(stderr, "\n>>>>> Process Failed at B <<<<<\n");
}
}
return true;
}

View File

@ -100,11 +100,8 @@ bool Sender::Add10MsData() {
if (!_pcmFile.EndOfFile()) {
EXPECT_GT(_pcmFile.Read10MsData(_audioFrame), 0);
int32_t ok = _acm->Add10MsData(_audioFrame);
EXPECT_EQ(0, ok);
if (ok != 0) {
return false;
}
return true;
EXPECT_GE(ok, 0);
return ok >= 0 ? true : false;
}
return false;
}
@ -114,7 +111,6 @@ void Sender::Run() {
if (!Add10MsData()) {
break;
}
EXPECT_GT(_acm->Process(), -1);
}
}

View File

@ -171,9 +171,6 @@ void SpatialAudio::EncodeDecode(const double leftPanning,
}
CHECK_ERROR(_acmRight->Add10MsData(audioFrame));
CHECK_ERROR(_acmLeft->Process());
CHECK_ERROR(_acmRight->Process());
CHECK_ERROR(_acmReceiver->PlayoutData10Ms(outFileSampFreq, &audioFrame));
_outFile.Write10MsData(audioFrame);
}
@ -190,8 +187,6 @@ void SpatialAudio::EncodeDecode() {
_inFile.Read10MsData(audioFrame);
CHECK_ERROR(_acmLeft->Add10MsData(audioFrame));
CHECK_ERROR(_acmLeft->Process());
CHECK_ERROR(_acmReceiver->PlayoutData10Ms(outFileSampFreq, &audioFrame));
_outFile.Write10MsData(audioFrame);
}

View File

@ -434,9 +434,6 @@ void TestAllCodecs::Run(TestPack* channel) {
infile_a_.Read10MsData(audio_frame);
CHECK_ERROR(acm_a_->Add10MsData(audio_frame));
// Run sender side of ACM.
CHECK_ERROR(acm_a_->Process());
// Verify that the received packet size matches the settings.
receive_size = channel->payload_size();
if (receive_size) {

View File

@ -311,8 +311,7 @@ void TestRedFec::Run() {
while (!_inFileA.EndOfFile()) {
EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0);
EXPECT_EQ(0, _acmA->Add10MsData(audioFrame));
EXPECT_GT(_acmA->Process(), -1);
EXPECT_GE(_acmA->Add10MsData(audioFrame), 0);
EXPECT_EQ(0, _acmB->PlayoutData10Ms(outFreqHzB, &audioFrame));
_outFileB.Write10MsData(audioFrame.data_, audioFrame.samples_per_channel_);
msecPassed += 10;

View File

@ -779,10 +779,7 @@ void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
}
in_file_stereo_->Read10MsData(audio_frame);
}
EXPECT_EQ(0, acm_a_->Add10MsData(audio_frame));
// Run sender side of ACM
EXPECT_GT(acm_a_->Process(), -1);
EXPECT_GE(acm_a_->Add10MsData(audio_frame), 0);
// Verify that the received packet size matches the settings.
rec_size = channel->payload_size();

View File

@ -242,8 +242,7 @@ void TestVADDTX::Run() {
_inFileA.Read10MsData(audioFrame);
audioFrame.timestamp_ = timestampA;
timestampA += SamplesIn10MsecA;
EXPECT_EQ(0, _acmA->Add10MsData(audioFrame));
EXPECT_GT(_acmA->Process(), -1);
EXPECT_GE(_acmA->Add10MsData(audioFrame), 0);
EXPECT_EQ(0, _acmB->PlayoutData10Ms(outFreqHzB, &audioFrame));
_outFileB.Write10MsData(audioFrame.data_, audioFrame.samples_per_channel_);
}

View File

@ -282,32 +282,21 @@ void TwoWayCommunication::Perform() {
// and B, APIs will be called, like ResetEncoder(), and the code should
// continue to run, and be able to recover.
bool expect_error_add = false;
bool expect_error_process = false;
while (!_inFileA.EndOfFile() && !_inFileB.EndOfFile()) {
msecPassed += 10;
EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0);
EXPECT_EQ(0, _acmA->Add10MsData(audioFrame));
EXPECT_EQ(0, _acmRefA->Add10MsData(audioFrame));
EXPECT_GE(_acmA->Add10MsData(audioFrame), 0);
EXPECT_GE(_acmRefA->Add10MsData(audioFrame), 0);
EXPECT_GT(_inFileB.Read10MsData(audioFrame), 0);
// Expect call to pass except for the time when no send codec is registered.
if (!expect_error_add) {
EXPECT_EQ(0, _acmB->Add10MsData(audioFrame));
EXPECT_GE(_acmB->Add10MsData(audioFrame), 0);
} else {
EXPECT_EQ(-1, _acmB->Add10MsData(audioFrame));
}
// Expect to pass except for the time when there either is no send codec
// registered, or no receive codec.
if (!expect_error_process) {
EXPECT_GT(_acmB->Process(), -1);
} else {
EXPECT_EQ(_acmB->Process(), -1);
}
EXPECT_EQ(0, _acmRefB->Add10MsData(audioFrame));
EXPECT_GT(_acmA->Process(), -1);
EXPECT_GT(_acmRefA->Process(), -1);
EXPECT_GT(_acmRefB->Process(), -1);
EXPECT_GE(_acmRefB->Add10MsData(audioFrame), 0);
EXPECT_EQ(0, _acmA->PlayoutData10Ms(outFreqHzA, &audioFrame));
_outFileA.Write10MsData(audioFrame);
EXPECT_EQ(0, _acmRefA->PlayoutData10Ms(outFreqHzA, &audioFrame));
@ -328,14 +317,12 @@ void TwoWayCommunication::Perform() {
EXPECT_EQ(0, _acmA->ResetEncoder());
EXPECT_EQ(0, _acmB->InitializeSender());
expect_error_add = true;
expect_error_process = true;
}
// Re-register send codec on side B.
if (((secPassed % 5) == 4) && (msecPassed >= 990)) {
EXPECT_EQ(0, _acmB->RegisterSendCodec(codecInst_B));
EXPECT_EQ(0, _acmB->SendCodec(&dummy));
expect_error_add = false;
expect_error_process = false;
}
// Reset decoder on side B, and initialize receiver on side A.
if (((secPassed % 7) == 6) && (msecPassed == 0)) {

View File

@ -209,8 +209,7 @@ class DelayTest {
}
in_file_a_.Read10MsData(audio_frame);
ASSERT_EQ(0, acm_a_->Add10MsData(audio_frame));
ASSERT_LE(0, acm_a_->Process());
ASSERT_GE(acm_a_->Add10MsData(audio_frame), 0);
ASSERT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame));
out_file_b_.Write10MsData(
audio_frame.data_,

View File

@ -246,10 +246,8 @@ void ISACTest::Perform() {
void ISACTest::Run10ms() {
AudioFrame audioFrame;
EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0);
EXPECT_EQ(0, _acmA->Add10MsData(audioFrame));
EXPECT_EQ(0, _acmB->Add10MsData(audioFrame));
EXPECT_GT(_acmA->Process(), -1);
EXPECT_GT(_acmB->Process(), -1);
EXPECT_GE(_acmA->Add10MsData(audioFrame), 0);
EXPECT_GE(_acmB->Add10MsData(audioFrame), 0);
EXPECT_EQ(0, _acmA->PlayoutData10Ms(32000, &audioFrame));
_outFileA.Write10MsData(audioFrame);
EXPECT_EQ(0, _acmB->PlayoutData10Ms(32000, &audioFrame));

View File

@ -145,8 +145,7 @@ class InitialPlayoutDelayTest : public ::testing::Test {
while (rms < kAmp / 2) {
in_audio_frame.timestamp_ = timestamp;
timestamp += in_audio_frame.samples_per_channel_;
ASSERT_EQ(0, acm_a_->Add10MsData(in_audio_frame));
ASSERT_LE(0, acm_a_->Process());
ASSERT_GE(acm_a_->Add10MsData(in_audio_frame), 0);
ASSERT_EQ(0, acm_b_->PlayoutData10Ms(codec.plfreq, &out_audio_frame));
rms = FrameRms(out_audio_frame);
++num_frames;

View File

@ -164,7 +164,7 @@ class InsertPacketWithTiming {
// Push in just enough audio.
for (int n = 0; n < num_10ms_in_codec_frame_; n++) {
pcm_in_fid_.Read10MsData(frame_);
EXPECT_EQ(0, send_acm_->Add10MsData(frame_));
EXPECT_GE(send_acm_->Add10MsData(frame_), 0);
}
// Set the parameters for the packet to be pushed in receiver ACM right
@ -179,10 +179,6 @@ class InsertPacketWithTiming {
lost = true;
}
// Process audio in send ACM, this should result in generation of a
// packet.
EXPECT_GT(send_acm_->Process(), 0);
if (FLAGS_verbose) {
if (!lost) {
std::cout << "\nInserting packet number " << seq_num

View File

@ -96,10 +96,6 @@ int32_t AudioCoder::Encode(const AudioFrame& audio,
return -1;
}
_encodedData = encodedData;
if(_acm->Process() == -1)
{
return -1;
}
encodedLengthInBytes = _encodedLengthInBytes;
return 0;
}

View File

@ -3560,7 +3560,10 @@ Channel::EncodeAndSend()
// The ACM resamples internally.
_audioFrame.timestamp_ = _timeStamp;
if (audio_coding_->Add10MsData((AudioFrame&)_audioFrame) != 0)
// This call will trigger AudioPacketizationCallback::SendData if encoding
// is done and payload is ready for packetization and transmission.
// Otherwise, it will return without invoking the callback.
if (audio_coding_->Add10MsData((AudioFrame&)_audioFrame) < 0)
{
WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId,_channelId),
"Channel::EncodeAndSend() ACM encoding failed");
@ -3568,12 +3571,7 @@ Channel::EncodeAndSend()
}
_timeStamp += _audioFrame.samples_per_channel_;
// --- Encode if complete frame is ready
// This call will trigger AudioPacketizationCallback::SendData if encoding
// is done and payload is ready for packetization and transmission.
return audio_coding_->Process();
return 0;
}
int Channel::RegisterExternalMediaProcessing(