Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(978)

Unified Diff: webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc

Issue 1316903002: Update to the neteq_rtpplay utility to support RtcEventLog input files. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added automatic filetype detection, lots of refactoring. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc
diff --git a/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc b/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc
index 6bcd717279b8b5bf4ce8423eaec62b825908997c..5021650d169039a49c9d676bd103f02417801138 100644
--- a/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc
+++ b/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc
@@ -19,6 +19,7 @@
#include <algorithm>
#include <iostream>
+#include <limits>
#include <string>
#include "google/gflags.h"
@@ -30,6 +31,7 @@
#include "webrtc/modules/audio_coding/neteq/tools/output_audio_file.h"
#include "webrtc/modules/audio_coding/neteq/tools/output_wav_file.h"
#include "webrtc/modules/audio_coding/neteq/tools/packet.h"
+#include "webrtc/modules/audio_coding/neteq/tools/rtc_event_log_source.h"
#include "webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h"
#include "webrtc/modules/interface/module_common_types.h"
#include "webrtc/system_wrappers/interface/trace.h"
@@ -384,8 +386,36 @@ int main(int argc, char* argv[]) {
}
printf("Input file: %s\n", argv[1]);
- rtc::scoped_ptr<webrtc::test::RtpFileSource> file_source(
- webrtc::test::RtpFileSource::Create(argv[1]));
+
+ // Check if the magic string "#!rtpplay1.0" appears at the beginning of the
minyue-webrtc 2015/09/01 11:48:35 nice!
hlundin-webrtc 2015/09/02 08:48:51 Yes, but I suggest you also add RTPencode as a mag
ivoc 2015/09/03 08:01:31 Ah, I did not know that. Thanks.
+ // file. If it does, the input file is an RTPdump file, otherwise we will
+ // assume it is an RtcEventLog file.
+ bool is_rtp_dump = false;
hlundin-webrtc 2015/09/02 08:48:51 This is a lot of extra code to check what is essen
ivoc 2015/09/03 08:01:31 You're right, that does seem like a nicer approach
+ {
+ const char magic_string[] = "#!rtpplay1.0";
+ const size_t magic_string_size = sizeof(magic_string) - 1;
+ char first_bytes[magic_string_size];
+ FILE* input_file = fopen(argv[1], "r");
+ if (input_file) {
+ size_t bytes_read = fread(first_bytes, 1, magic_string_size, input_file);
+ if (bytes_read == magic_string_size)
+ if (strncmp(magic_string, first_bytes, magic_string_size) == 0)
+ is_rtp_dump = true;
+ fclose(input_file);
+ } else {
+ std::cerr << "Unable to read input file." << std::endl;
+ return -1;
+ }
+ }
+ rtc::scoped_ptr<webrtc::test::PacketSource> file_source;
+ webrtc::test::RtcEventLogSource* event_log_source = nullptr;
+ if (is_rtp_dump) {
+ file_source.reset(webrtc::test::RtpFileSource::Create(argv[1]));
+ } else {
+ event_log_source = webrtc::test::RtcEventLogSource::Create(argv[1]);
+ file_source.reset(event_log_source);
+ }
+
assert(file_source.get());
// Check if an SSRC value was provided.
@@ -413,7 +443,6 @@ int main(int argc, char* argv[]) {
webrtc::Trace::ReturnTrace();
return 0;
}
- bool packet_available = true;
// Check the sample rate.
int sample_rate_hz = CodecSampleRate(packet->header().payloadType);
@@ -475,17 +504,29 @@ int main(int argc, char* argv[]) {
// This is the main simulation loop.
// Set the simulation clock to start immediately with the first packet.
- int start_time_ms = packet->time_ms();
- int time_now_ms = packet->time_ms();
- int next_input_time_ms = time_now_ms;
- int next_output_time_ms = time_now_ms;
+ int64_t start_time_ms = packet->time_ms();
hlundin-webrtc 2015/09/02 08:48:51 packet->time_ms() actually returns a double. Sugge
ivoc 2015/09/03 08:01:31 Done.
+ int64_t time_now_ms = packet->time_ms();
+ int64_t next_input_time_ms = time_now_ms;
+ int64_t next_output_time_ms = time_now_ms;
if (time_now_ms % kOutputBlockSizeMs != 0) {
// Make sure that next_output_time_ms is rounded up to the next multiple
// of kOutputBlockSizeMs. (Legacy bit-exactness.)
next_output_time_ms +=
kOutputBlockSizeMs - time_now_ms % kOutputBlockSizeMs;
}
- while (packet_available) {
+
+ bool packet_available = true;
+ bool output_event_available = true;
+ if (!is_rtp_dump) {
+ next_output_time_ms = event_log_source->NextAudioOutputEventMs();
+ if (next_output_time_ms == std::numeric_limits<int64_t>::max())
+ output_event_available = false;
+ start_time_ms = time_now_ms =
+ std::min(next_input_time_ms, next_output_time_ms);
+ }
+ while (packet_available || output_event_available) {
+ // Advance time to next event.
+ time_now_ms = std::min(next_input_time_ms, next_output_time_ms);
// Check if it is time to insert packet.
while (time_now_ms >= next_input_time_ms && packet_available) {
assert(packet->virtual_payload_length_bytes() > 0);
@@ -534,24 +575,27 @@ int main(int argc, char* argv[]) {
webrtc::test::Packet* temp_packet = file_source->NextPacket();
if (temp_packet) {
packet.reset(temp_packet);
+ if (replace_payload) {
+ // At this point |packet| contains the packet *after* |next_packet|.
+ // Swap Packet objects between |packet| and |next_packet|.
+ packet.swap(next_packet);
+ // Swap the status indicators unless they're already the same.
+ if (packet_available != next_packet_available) {
+ packet_available = !packet_available;
+ next_packet_available = !next_packet_available;
+ }
+ }
+ next_input_time_ms = packet->time_ms();
hlundin-webrtc 2015/09/02 08:48:51 checked_cast here too
ivoc 2015/09/03 08:01:31 Added. I also added one in the call to neteq->Inse
} else {
+ // Set next input time to the maximum value of int64_t to prevent the
+ // time_now_ms from becoming stuck at the final value.
+ next_input_time_ms = std::numeric_limits<int64_t>::max();
packet_available = false;
}
- if (replace_payload) {
- // At this point |packet| contains the packet *after* |next_packet|.
- // Swap Packet objects between |packet| and |next_packet|.
- packet.swap(next_packet);
- // Swap the status indicators unless they're already the same.
- if (packet_available != next_packet_available) {
- packet_available = !packet_available;
- next_packet_available = !next_packet_available;
- }
- }
- next_input_time_ms = packet->time_ms();
}
// Check if it is time to get output audio.
- if (time_now_ms >= next_output_time_ms) {
+ while (time_now_ms >= next_output_time_ms && output_event_available) {
static const int kOutDataLen =
kOutputBlockSizeMs * kMaxSamplesPerMs * kMaxChannels;
int16_t out_data[kOutDataLen];
@@ -575,14 +619,20 @@ int main(int argc, char* argv[]) {
webrtc::Trace::ReturnTrace();
exit(1);
}
- next_output_time_ms += kOutputBlockSizeMs;
+ if (is_rtp_dump) {
+ next_output_time_ms += kOutputBlockSizeMs;
+ if (!packet_available)
+ output_event_available = false;
+ } else {
+ next_output_time_ms = event_log_source->NextAudioOutputEventMs();
+ if (next_output_time_ms == std::numeric_limits<int64_t>::max())
+ output_event_available = false;
+ }
}
- // Advance time to next event.
- time_now_ms = std::min(next_input_time_ms, next_output_time_ms);
}
-
printf("Simulation done\n");
- printf("Produced %i ms of audio\n", time_now_ms - start_time_ms);
+ printf("Produced %i ms of audio\n",
+ static_cast<int>(time_now_ms - start_time_ms));
delete neteq;
webrtc::Trace::ReturnTrace();
« no previous file with comments | « webrtc/modules/audio_coding/neteq/neteq_tests.gypi ('k') | webrtc/modules/audio_coding/neteq/tools/rtc_event_log_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698