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

Unified Diff: webrtc/modules/audio_coding/main/acm2/acm_dump.cc

Issue 1209563002: Added support for keeping a buffer of the previous X seconds, to add to (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « no previous file | webrtc/modules/audio_coding/main/acm2/acm_dump_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/audio_coding/main/acm2/acm_dump.cc
diff --git a/webrtc/modules/audio_coding/main/acm2/acm_dump.cc b/webrtc/modules/audio_coding/main/acm2/acm_dump.cc
index 4454c25947d5d1d1d226aea04d75833d362ddf39..ed8491ad4e361322cecbbafb76a246cc31fde5b2 100644
--- a/webrtc/modules/audio_coding/main/acm2/acm_dump.cc
+++ b/webrtc/modules/audio_coding/main/acm2/acm_dump.cc
@@ -10,7 +10,7 @@
#include "webrtc/modules/audio_coding/main/acm2/acm_dump.h"
-#include <sstream>
+#include <deque>
#include "webrtc/base/checks.h"
#include "webrtc/base/thread_annotations.h"
@@ -67,10 +67,20 @@ class AcmDumpImpl final : public AcmDump {
void LogDebugEventLocked(DebugEvent event_type,
const std::string& event_message)
EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ // Writes the event to the file. Note that this will destroy the state of the
+ // input argument.
+ void StoreToFile(ACMDumpEvent& event) EXCLUSIVE_LOCKS_REQUIRED(crit_);
kwiberg-webrtc 2015/06/24 15:38:16 The convention is to use pointers for arguments th
ivoc 2015/06/25 11:24:08 Okay, changed to a pointer.
+ // Adds the event to the list of recent events, and removes any events that
+ // are too old and no longer fall in the time window.
+ void RecentEvent(const ACMDumpEvent& event) EXCLUSIVE_LOCKS_REQUIRED(crit_);
kwiberg-webrtc 2015/06/24 15:38:16 Maybe "AddRecentEvent"?
ivoc 2015/06/25 11:24:08 Okay, seems like a better name.
+
+ // Amount of time in us to record log events, before starting the actual log.
+ const int recent_log_duration_us = 10000000;
rtc::scoped_ptr<webrtc::CriticalSectionWrapper> crit_;
rtc::scoped_ptr<webrtc::FileWrapper> file_ GUARDED_BY(crit_);
rtc::scoped_ptr<ACMDumpEventStream> stream_ GUARDED_BY(crit_);
+ std::deque<ACMDumpEvent> recent_log_events_ GUARDED_BY(crit_);
bool active_ GUARDED_BY(crit_);
int64_t start_time_us_ GUARDED_BY(crit_);
int64_t duration_us_ GUARDED_BY(crit_);
@@ -112,38 +122,38 @@ void AcmDumpImpl::StartLogging(const std::string& file_name, int duration_ms) {
if (file_->OpenFile(file_name.c_str(), false) != 0) {
return;
}
- // Add a single object to the stream that is reused at every log event.
- stream_->add_stream();
+ // Add start event to the recent event list, and remove any old events from
+ // the list.
+ LogDebugEventLocked(DebugEvent::kLogStart, "");
active_ = true;
start_time_us_ = clock_->TimeInMicroseconds();
duration_us_ = static_cast<int64_t>(duration_ms) * 1000;
- // Log the start event.
- std::stringstream log_msg;
- log_msg << "Initial timestamp: " << start_time_us_;
- LogDebugEventLocked(DebugEvent::kLogStart, log_msg.str());
+ // Write all the recent events to the log file.
+ for (auto&& event: recent_log_events_) {
+ StoreToFile(event);
+ }
+ recent_log_events_.clear();
}
void AcmDumpImpl::LogRtpPacket(bool incoming,
const uint8_t* packet,
size_t length) {
CriticalSectionScoped lock(crit_.get());
- if (!CurrentlyLogging()) {
+ ACMDumpEvent rtp_event;
+ rtp_event.clear_debug_event();
+ const int64_t timestamp = clock_->TimeInMicroseconds();
+ rtp_event.set_timestamp_us(timestamp);
+ rtp_event.set_type(webrtc::ACMDumpEvent::RTP_EVENT);
+ rtp_event.mutable_packet()->set_direction(
+ incoming ? ACMDumpRTPPacket::INCOMING : ACMDumpRTPPacket::OUTGOING);
+ rtp_event.mutable_packet()->set_rtp_data(packet, length);
+ if (CurrentlyLogging()) {
+ StoreToFile(rtp_event);
+ }
+ else {
StopIfNecessary();
- return;
+ RecentEvent(rtp_event);
}
- // Reuse the same object at every log event.
- auto rtp_event = stream_->mutable_stream(0);
- rtp_event->clear_debug_event();
- const int64_t timestamp = clock_->TimeInMicroseconds() - start_time_us_;
- rtp_event->set_timestamp_us(timestamp);
- rtp_event->set_type(webrtc::ACMDumpEvent::RTP_EVENT);
- rtp_event->mutable_packet()->set_direction(
- incoming ? ACMDumpRTPPacket::INCOMING : ACMDumpRTPPacket::OUTGOING);
- rtp_event->mutable_packet()->set_rtp_data(packet, length);
- std::string dump_buffer;
- stream_->SerializeToString(&dump_buffer);
- file_->Write(dump_buffer.data(), dump_buffer.size());
- file_->Flush();
}
void AcmDumpImpl::LogDebugEvent(DebugEvent event_type,
@@ -175,25 +185,45 @@ void AcmDumpImpl::Clear() {
void AcmDumpImpl::LogDebugEventLocked(DebugEvent event_type,
const std::string& event_message) {
- if (!CurrentlyLogging()) {
+ ACMDumpEvent event;
+ int64_t timestamp = clock_->TimeInMicroseconds();
+ event.set_timestamp_us(timestamp);
+ event.set_type(webrtc::ACMDumpEvent::DEBUG_EVENT);
+ event.clear_packet();
+ auto debug_event = event.mutable_debug_event();
+ debug_event->set_type(convertDebugEvent(event_type));
+ debug_event->set_message(event_message);
+ if (CurrentlyLogging()) {
+ StoreToFile(event);
+ }
+ else {
StopIfNecessary();
- return;
+ RecentEvent(event);
}
+}
+void AcmDumpImpl::StoreToFile(ACMDumpEvent& event) {
// Reuse the same object at every log event.
- auto event = stream_->mutable_stream(0);
- int64_t timestamp = clock_->TimeInMicroseconds() - start_time_us_;
- event->set_timestamp_us(timestamp);
- event->set_type(webrtc::ACMDumpEvent::DEBUG_EVENT);
- event->clear_packet();
- auto debug_event = event->mutable_debug_event();
- debug_event->set_type(convertDebugEvent(event_type));
- debug_event->set_message(event_message);
+ if (stream_->stream_size() < 1) {
+ stream_->add_stream();
+ }
+ stream_->mutable_stream(0)->Swap(&event);
+
std::string dump_buffer;
stream_->SerializeToString(&dump_buffer);
file_->Write(dump_buffer.data(), dump_buffer.size());
+ file_->Flush();
kwiberg-webrtc 2015/06/24 15:38:16 This change seems unrelated to the rest of the CL.
ivoc 2015/06/25 11:24:08 It was needed for the unittest to work, but I have
+}
+
+void AcmDumpImpl::RecentEvent(const ACMDumpEvent& event) {
+ recent_log_events_.push_back(event);
+ while (recent_log_events_.front().timestamp_us() <
+ event.timestamp_us() - recent_log_duration_us) {
+ recent_log_events_.pop_front();
+ }
}
+
#endif // RTC_AUDIOCODING_DEBUG_DUMP
// AcmDump member functions.
« no previous file with comments | « no previous file | webrtc/modules/audio_coding/main/acm2/acm_dump_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698