Replacing the legacy tool RTPencode with a new rtp_encode

This new tool provides the same functionality as the legacy tool, but it
is implemented using AudioCodingModule and AudioEncoder APIs instead of
the naked codecs.

Bug: webrtc:2692
Change-Id: I29accd77d4ba5c7b5e1559853cbaf20ee812e6bc
Reviewed-on: https://webrtc-review.googlesource.com/24861
Commit-Queue: Henrik Lundin <henrik.lundin@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20857}
This commit is contained in:
Henrik Lundin
2017-11-24 09:28:57 +01:00
committed by Commit Bot
parent bb5ca2ef41
commit 1391bd472c
6 changed files with 383 additions and 1887 deletions

View File

@ -15,7 +15,8 @@
namespace webrtc {
namespace test {
InputAudioFile::InputAudioFile(const std::string file_name) {
InputAudioFile::InputAudioFile(const std::string file_name, bool loop_at_end)
: loop_at_end_(loop_at_end) {
fp_ = fopen(file_name.c_str(), "rb");
}
@ -27,6 +28,9 @@ bool InputAudioFile::Read(size_t samples, int16_t* destination) {
}
size_t samples_read = fread(destination, sizeof(int16_t), samples, fp_);
if (samples_read < samples) {
if (!loop_at_end_) {
return false;
}
// Rewind and read the missing samples.
rewind(fp_);
size_t missing_samples = samples - samples_read;
@ -54,7 +58,11 @@ bool InputAudioFile::Seek(int samples) {
long new_pos = current_pos + sizeof(int16_t) * samples; // Samples to bytes.
RTC_CHECK_GE(new_pos, 0)
<< "Trying to move to before the beginning of the file";
new_pos = new_pos % file_size; // Wrap around the end of the file.
if (loop_at_end_) {
new_pos = new_pos % file_size; // Wrap around the end of the file.
} else {
new_pos = new_pos > file_size ? file_size : new_pos; // Don't loop.
}
// Move to new position relative to the beginning of the file.
RTC_CHECK_EQ(0, fseek(fp_, new_pos, SEEK_SET));
return true;