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

Unified Diff: webrtc/modules/audio_coding/neteq/tools/rtc_event_log_source.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: Initial version 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/rtc_event_log_source.cc
diff --git a/webrtc/modules/audio_coding/neteq/tools/rtc_event_log_source.cc b/webrtc/modules/audio_coding/neteq/tools/rtc_event_log_source.cc
new file mode 100644
index 0000000000000000000000000000000000000000..13f88cd5000385644972ea2bdd01e7b05ff3c8dc
--- /dev/null
+++ b/webrtc/modules/audio_coding/neteq/tools/rtc_event_log_source.cc
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2015 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/rtc_event_log_source.h"
+
+#include <assert.h>
+#include <string.h>
+
+#include "webrtc/base/checks.h"
+#include "webrtc/modules/audio_coding/neteq/tools/packet.h"
+#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
+#include "webrtc/video/rtc_event_log.h"
+
+// Files generated at build-time by the protobuf compiler.
+#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
+#include "external/webrtc/webrtc/video/rtc_event_log.pb.h"
+#else
+#include "webrtc/video/rtc_event_log.pb.h"
+#endif
+
+namespace webrtc {
+namespace test {
+
+RtcEventLogSource* RtcEventLogSource::Create(const std::string& file_name) {
+ RtcEventLogSource* source = new RtcEventLogSource();
+ CHECK(source->OpenFile(file_name));
+ return source;
+}
+
+RtcEventLogSource::~RtcEventLogSource() {
+}
+
+bool RtcEventLogSource::RegisterRtpHeaderExtension(RTPExtensionType type,
+ uint8_t id) {
+ assert(parser_.get());
hlundin-webrtc 2015/08/28 12:06:25 CHECK instead. This is test/tools code; better to
ivoc 2015/09/01 10:03:50 Done.
+ return parser_->RegisterRtpHeaderExtension(type, id);
+}
+
+Packet* RtcEventLogSource::NextPacket() {
+ for (; rtp_packet_index_ < event_log_->stream_size(); rtp_packet_index_++) {
+ const rtclog::Event& event = event_log_->stream(rtp_packet_index_);
+ if (event.has_type() && event.type() == rtclog::Event::RTP_EVENT) {
hlundin-webrtc 2015/08/28 12:06:25 This is a very long harangue of nested if statemen
ivoc 2015/09/01 10:03:50 Great idea, I refactored the code like you suggest
+ if (event.has_timestamp_us() && event.has_rtp_packet()) {
+ const rtclog::RtpPacket& rtp_packet = event.rtp_packet();
+ if (rtp_packet.has_type() && rtp_packet.type() == rtclog::AUDIO &&
+ rtp_packet.has_incoming() && rtp_packet.incoming() == true &&
hlundin-webrtc 2015/08/28 12:06:25 You can omit "== true".
ivoc 2015/09/01 10:03:50 Done.
+ rtp_packet.has_packet_length() && rtp_packet.packet_length() > 0 &&
+ rtp_packet.has_header() && rtp_packet.header().size() > 0 &&
+ rtp_packet.packet_length() >= rtp_packet.header().size()) {
+ // Increase the index to avoid rechecking this event the next time
+ // the function is called.
+ rtp_packet_index_++;
hlundin-webrtc 2015/08/28 12:06:25 The double increment (in the for statement and her
ivoc 2015/09/01 10:03:50 Done.
+ uint8_t* packet_data = new uint8_t[rtp_packet.header().size()];
+ memcpy(packet_data, rtp_packet.header().data(),
minyue-webrtc 2015/08/28 16:54:17 Do you need payload data for packet_data, and is r
ivoc 2015/09/01 10:03:50 Right now the rtp packet message in the protobuf o
minyue-webrtc 2015/09/01 11:48:35 Yes, that makes it clearer. Now I see why I had a
+ rtp_packet.header().size());
+ rtc::scoped_ptr<Packet> packet(
minyue-webrtc 2015/08/28 14:50:21 what is the life time of packet? I'd like the met
ivoc 2015/09/01 10:03:50 I agree that this is not super obvious, but the re
minyue-webrtc 2015/09/01 11:48:35 No bother. maybe no need of scoped_ptr around pack
+ new Packet(packet_data, rtp_packet.header().size(),
+ rtp_packet.packet_length(),
+ event.timestamp_us() / 1000, *parser_.get()));
+ if (!packet->valid_header()) {
hlundin-webrtc 2015/08/28 12:06:25 Are we expecting the logger to write invalid heade
ivoc 2015/09/01 10:03:50 The header is currently not checked while writing,
+ assert(false);
+ return nullptr;
+ }
+ if (filter_.test(packet->header().payloadType) ||
+ (use_ssrc_filter_ && packet->header().ssrc != ssrc_)) {
+ // This payload type should be filtered out. Continue to the next
hlundin-webrtc 2015/08/28 12:06:25 s/payload type/packet/
ivoc 2015/09/01 10:03:50 I replaced this, but I also restructured this code
+ // packet.
+ continue;
+ }
+ return packet.release();
+ }
+ }
+ }
+ }
+ return nullptr;
+}
+
+int RtcEventLogSource::NextAudioOutputEventMs() {
+ for (; audio_output_index_ < event_log_->stream_size();
+ audio_output_index_++) {
+ const rtclog::Event& event = event_log_->stream(audio_output_index_);
+ if (event.has_type() && event.type() == rtclog::Event::DEBUG_EVENT) {
hlundin-webrtc 2015/08/28 12:06:25 Same comment as above about a helper function.
ivoc 2015/09/01 10:03:50 I restructured in a similar way.
+ if (event.has_timestamp_us() && event.has_debug_event()) {
+ const rtclog::DebugEvent& debug_event = event.debug_event();
+ if (debug_event.has_type() &&
+ debug_event.type() == rtclog::DebugEvent::AUDIO_PLAYOUT) {
+ // Increase the index to avoid rechecking this event the next time
+ // the function is called.
+ audio_output_index_++;
hlundin-webrtc 2015/08/28 12:06:25 Same awkwardness here.
ivoc 2015/09/01 10:03:50 Same fix applied.
+ return event.timestamp_us() / 1000;
hlundin-webrtc 2015/08/28 12:06:25 What is the type of timestamp_us? If it is not int
ivoc 2015/09/01 10:03:50 The value is int64_t, so I changed the return type
+ }
+ }
+ }
+ }
+ return -1;
+}
+
+RtcEventLogSource::RtcEventLogSource()
+ : PacketSource(), parser_(RtpHeaderParser::Create()) {
+}
+
+bool RtcEventLogSource::OpenFile(const std::string& file_name) {
+ event_log_.reset(new rtclog::EventStream());
+ return RtcEventLog::ParseRtcEventLog(file_name, event_log_.get());
+}
+
+} // namespace test
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698