Mainly hlundin's patch.

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3405 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
niklas.enbom@webrtc.org
2013-01-24 18:53:43 +00:00
parent 4782911572
commit 05e7bfeeea
12 changed files with 277 additions and 16 deletions

View File

@ -0,0 +1,45 @@
/*
* 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/modules/audio_coding/neteq/tools/input_audio_file.h"
namespace webrtc {
namespace test {
bool InputAudioFile::Read(size_t samples, int16_t* destination) {
if (!fp_) {
return false;
}
size_t bytes_read = fread(destination, sizeof(int16_t), samples, fp_);
if (bytes_read < samples) {
// Rewind and read the missing sampels.
rewind(fp_);
size_t missing_samples = samples - bytes_read;
if (fread(destination, sizeof(int16_t), missing_samples, fp_) <
missing_samples) {
// Could not read enough even after rewinding the file.
return false;
}
}
return true;
}
void InputAudioFile::DuplicateInterleaved(const int16_t* source, size_t samples,
size_t channels,
int16_t* destination) {
for (size_t i = 0; i < samples; ++i) {
for (size_t j = 0; j < channels; ++j) {
destination[i * channels + j] = source[i];
}
}
}
} // namespace test
} // namespace webrtc

View File

@ -0,0 +1,54 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_INPUT_AUDIO_FILE_H_
#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_INPUT_AUDIO_FILE_H_
#include <cstdio>
#include <string>
#include "webrtc/system_wrappers/interface/constructor_magic.h"
#include "webrtc/typedefs.h"
namespace webrtc {
namespace test {
// Class for handling a looping input audio file.
class InputAudioFile {
public:
explicit InputAudioFile(const std::string file_name) {
fp_ = fopen(file_name.c_str(), "rb");
}
virtual ~InputAudioFile() {
fclose(fp_);
}
// Reads |samples| elements from source file to |destination|. Returns true
// if the read was successful, otherwise false. If the file end is reached,
// the file is rewound and reading continues from the beginning.
// The output |destination| must have the capacity to hold |samples| elements.
bool Read(size_t samples, int16_t* destination);
// Creates a multi-channel signal from a mono signal. Each sample is repeated
// |channels| times to create an interleaved multi-channel signal where all
// channels are identical. The output |destination| must have the capacity to
// hold samples * channels elements.
static void DuplicateInterleaved(const int16_t* source, size_t samples,
size_t channels, int16_t* destination);
private:
FILE* fp_;
DISALLOW_COPY_AND_ASSIGN(InputAudioFile);
};
} // namespace test
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_INPUT_AUDIO_FILE_H_

View File

@ -0,0 +1,41 @@
/*
* 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 <assert.h>
#include "webrtc/modules/audio_coding/neteq/tools/rtp_generator.h"
namespace webrtc {
namespace test {
uint32_t RtpGenerator::GetRtpHeader(uint8_t payload_type,
size_t payload_length_samples,
WebRtcRTPHeader* rtp_header) {
assert(rtp_header);
if (!rtp_header) {
return 0;
}
rtp_header->header.sequenceNumber = seq_number_++;
rtp_header->header.timestamp = timestamp_;
timestamp_ += payload_length_samples;
rtp_header->header.payloadType = payload_type;
rtp_header->header.markerBit = false;
rtp_header->header.ssrc = ssrc_;
rtp_header->header.numCSRCs = 0;
rtp_header->frameType = kAudioFrameSpeech;
uint32_t this_send_time = next_send_time_ms_;
assert(samples_per_ms_ > 0);
next_send_time_ms_ += payload_length_samples / samples_per_ms_;
return this_send_time;
}
} // namespace test
} // namespace webrtc

View File

@ -0,0 +1,53 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_RTP_GENERATOR_H_
#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_RTP_GENERATOR_H_
#include "webrtc/modules/interface/module_common_types.h"
#include "webrtc/system_wrappers/interface/constructor_magic.h"
#include "webrtc/typedefs.h"
namespace webrtc {
namespace test {
// Class for generating RTP headers.
class RtpGenerator {
public:
RtpGenerator(int samples_per_ms,
uint16_t start_seq_number = 0,
uint32_t start_timestamp = 0,
uint32_t start_send_time_ms = 0,
uint32_t ssrc = 0x12345678)
: seq_number_(start_seq_number),
timestamp_(start_timestamp),
next_send_time_ms_(start_send_time_ms),
ssrc_(ssrc),
samples_per_ms_(samples_per_ms) {
}
// Writes the next RTP header to |rtp_header|, wich will be of type
// |payload_type|. Returns the send time for this packet (in ms). The value of
// |payload_length_samples| determines the send time for the next packet.
uint32_t GetRtpHeader(uint8_t payload_type, size_t payload_length_samples,
WebRtcRTPHeader* rtp_header);
private:
uint16_t seq_number_;
uint32_t timestamp_;
uint32_t next_send_time_ms_;
const uint32_t ssrc_;
const int samples_per_ms_;
DISALLOW_COPY_AND_ASSIGN(RtpGenerator);
};
} // namespace test
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_RTP_GENERATOR_H_