summaryrefslogtreecommitdiffstats
path: root/media/cast/logging
diff options
context:
space:
mode:
authorimcheng@chromium.org <imcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-25 23:39:48 +0000
committerimcheng@chromium.org <imcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-25 23:39:48 +0000
commit0107bccbfcc8eecf0a205fef8b09dd91d0d2b1a0 (patch)
tree15f40bf56e12397561b23740bc8e4d87e2877c1c /media/cast/logging
parent0f79ff6fbb52a33e73ca56246b64db39b59d3dbe (diff)
downloadchromium_src-0107bccbfcc8eecf0a205fef8b09dd91d0d2b1a0.zip
chromium_src-0107bccbfcc8eecf0a205fef8b09dd91d0d2b1a0.tar.gz
chromium_src-0107bccbfcc8eecf0a205fef8b09dd91d0d2b1a0.tar.bz2
Cast: Limit number of events/packets in EncodingEventSubscriber protos.
There is now a limit on number of events per proto (AggregatedFrameEvent and BasePacketEvent). There is also a limit on number of packets per frame (i.e. number of BasePacketEvent in AggregatedPacketEvent). If either limit is exceeded, a new proto will be created for that frame. The underlying implementation of EncodingEventSubscriber is also changed. When the internal map reaches a certain size, its old entries will be transferred to a vector for storage. This is done to keep the map small and lookup fast. A proto will also be transferred to storage if adding an event to it would result in exceeding the limit stated above. The scheme is not perfect, but such situation rarely happens in practice. Also changed deserialization to be able to merge protos of the same frame. This is done to keep protos size in check. Also, LogSerializer will now fail DCHECK if the protos exceed the maximum size 2^16 - 1. (Because we encode size as 16 bits). BUG= Review URL: https://codereview.chromium.org/241833002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266289 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/cast/logging')
-rw-r--r--media/cast/logging/encoding_event_subscriber.cc255
-rw-r--r--media/cast/logging/encoding_event_subscriber.h61
-rw-r--r--media/cast/logging/encoding_event_subscriber_unittest.cc157
-rw-r--r--media/cast/logging/log_deserializer.cc64
-rw-r--r--media/cast/logging/log_deserializer.h13
-rw-r--r--media/cast/logging/log_serializer.cc39
-rw-r--r--media/cast/logging/log_serializer.h5
-rw-r--r--media/cast/logging/serialize_deserialize_test.cc53
8 files changed, 451 insertions, 196 deletions
diff --git a/media/cast/logging/encoding_event_subscriber.cc b/media/cast/logging/encoding_event_subscriber.cc
index 2804988..52924f7 100644
--- a/media/cast/logging/encoding_event_subscriber.cc
+++ b/media/cast/logging/encoding_event_subscriber.cc
@@ -16,6 +16,23 @@ using media::cast::proto::AggregatedPacketEvent;
using media::cast::proto::BasePacketEvent;
using media::cast::proto::LogMetadata;
+namespace {
+
+// A size limit on maps to keep lookups fast.
+const size_t kMaxMapSize = 200;
+
+// The smallest (oredered by RTP timestamp) |kNumMapEntriesToTransfer| entries
+// will be moved when the map size reaches |kMaxMapSize|.
+// Must be smaller than |kMaxMapSize|.
+const size_t kNumMapEntriesToTransfer = 100;
+
+template <typename ProtoPtr>
+bool IsRtpTimestampLessThan(const ProtoPtr& lhs, const ProtoPtr& rhs) {
+ return lhs->relative_rtp_timestamp() < rhs->relative_rtp_timestamp();
+}
+
+}
+
namespace media {
namespace cast {
@@ -24,6 +41,8 @@ EncodingEventSubscriber::EncodingEventSubscriber(
size_t max_frames)
: event_media_type_(event_media_type),
max_frames_(max_frames),
+ frame_event_storage_index_(0),
+ packet_event_storage_index_(0),
seen_first_rtp_timestamp_(false),
first_rtp_timestamp_(0u) {}
@@ -35,108 +54,149 @@ void EncodingEventSubscriber::OnReceiveFrameEvent(
const FrameEvent& frame_event) {
DCHECK(thread_checker_.CalledOnValidThread());
- if (ShouldProcessEvent(frame_event.type)) {
- RtpTimestamp relative_rtp_timestamp =
- GetRelativeRtpTimestamp(frame_event.rtp_timestamp);
- FrameEventMap::iterator it = frame_event_map_.find(relative_rtp_timestamp);
- linked_ptr<AggregatedFrameEvent> event_proto;
+ if (!ShouldProcessEvent(frame_event.type))
+ return;
- // Look up existing entry. If not found, create a new entry and add to map.
- if (it == frame_event_map_.end()) {
+ RtpTimestamp relative_rtp_timestamp =
+ GetRelativeRtpTimestamp(frame_event.rtp_timestamp);
+ FrameEventMap::iterator it = frame_event_map_.find(relative_rtp_timestamp);
+ linked_ptr<AggregatedFrameEvent> event_proto;
+
+ // Look up existing entry. If not found, create a new entry and add to map.
+ if (it == frame_event_map_.end()) {
+ event_proto.reset(new AggregatedFrameEvent);
+ event_proto->set_relative_rtp_timestamp(relative_rtp_timestamp);
+ frame_event_map_.insert(
+ std::make_pair(relative_rtp_timestamp, event_proto));
+ } else {
+ event_proto = it->second;
+ if (event_proto->event_type_size() >= kMaxEventsPerProto) {
+ DVLOG(2) << "Too many events in frame " << frame_event.rtp_timestamp
+ << ". Using new frame event proto.";
+ AddFrameEventToStorage(event_proto);
event_proto.reset(new AggregatedFrameEvent);
event_proto->set_relative_rtp_timestamp(relative_rtp_timestamp);
- frame_event_map_.insert(
- std::make_pair(relative_rtp_timestamp, event_proto));
- } else {
- event_proto = it->second;
+ it->second = event_proto;
}
+ }
- event_proto->add_event_type(ToProtoEventType(frame_event.type));
- event_proto->add_event_timestamp_ms(
- (frame_event.timestamp - base::TimeTicks()).InMilliseconds());
-
- if (frame_event.type == kAudioFrameEncoded) {
- event_proto->set_encoded_frame_size(frame_event.size);
- } else if (frame_event.type == kVideoFrameEncoded) {
- event_proto->set_encoded_frame_size(frame_event.size);
- event_proto->set_key_frame(frame_event.key_frame);
- event_proto->set_target_bitrate(frame_event.target_bitrate);
- } else if (frame_event.type == kAudioPlayoutDelay ||
- frame_event.type == kVideoRenderDelay) {
- event_proto->set_delay_millis(frame_event.delay_delta.InMilliseconds());
- }
+ event_proto->add_event_type(ToProtoEventType(frame_event.type));
+ event_proto->add_event_timestamp_ms(
+ (frame_event.timestamp - base::TimeTicks()).InMilliseconds());
- TruncateFrameEventMapIfNeeded();
+ if (frame_event.type == kAudioFrameEncoded) {
+ event_proto->set_encoded_frame_size(frame_event.size);
+ } else if (frame_event.type == kVideoFrameEncoded) {
+ event_proto->set_encoded_frame_size(frame_event.size);
+ event_proto->set_key_frame(frame_event.key_frame);
+ event_proto->set_target_bitrate(frame_event.target_bitrate);
+ } else if (frame_event.type == kAudioPlayoutDelay ||
+ frame_event.type == kVideoRenderDelay) {
+ event_proto->set_delay_millis(frame_event.delay_delta.InMilliseconds());
}
- DCHECK(frame_event_map_.size() <= max_frames_);
+ if (frame_event_map_.size() > kMaxMapSize)
+ TransferFrameEvents(kNumMapEntriesToTransfer);
+
+ DCHECK(frame_event_map_.size() <= kMaxMapSize);
+ DCHECK(frame_event_storage_.size() <= max_frames_);
}
void EncodingEventSubscriber::OnReceivePacketEvent(
const PacketEvent& packet_event) {
DCHECK(thread_checker_.CalledOnValidThread());
- if (ShouldProcessEvent(packet_event.type)) {
- RtpTimestamp relative_rtp_timestamp =
- GetRelativeRtpTimestamp(packet_event.rtp_timestamp);
- PacketEventMap::iterator it =
- packet_event_map_.find(relative_rtp_timestamp);
- linked_ptr<AggregatedPacketEvent> event_proto;
- BasePacketEvent* base_packet_event_proto = NULL;
+ if (!ShouldProcessEvent(packet_event.type))
+ return;
+ RtpTimestamp relative_rtp_timestamp =
+ GetRelativeRtpTimestamp(packet_event.rtp_timestamp);
+ PacketEventMap::iterator it =
+ packet_event_map_.find(relative_rtp_timestamp);
+ linked_ptr<AggregatedPacketEvent> event_proto;
+ BasePacketEvent* base_packet_event_proto = NULL;
+
+ // Look up existing entry. If not found, create a new entry and add to map.
+ if (it == packet_event_map_.end()) {
+ event_proto.reset(new AggregatedPacketEvent);
+ event_proto->set_relative_rtp_timestamp(relative_rtp_timestamp);
+ packet_event_map_.insert(
+ std::make_pair(relative_rtp_timestamp, event_proto));
+ base_packet_event_proto = event_proto->add_base_packet_event();
+ base_packet_event_proto->set_packet_id(packet_event.packet_id);
+ } else {
+ // Found existing entry, now look up existing BasePacketEvent using packet
+ // ID. If not found, create a new entry and add to proto.
+ event_proto = it->second;
+ RepeatedPtrField<BasePacketEvent>* field =
+ event_proto->mutable_base_packet_event();
+ for (RepeatedPtrField<BasePacketEvent>::pointer_iterator base_it =
+ field->pointer_begin();
+ base_it != field->pointer_end();
+ ++base_it) {
+ if ((*base_it)->packet_id() == packet_event.packet_id) {
+ base_packet_event_proto = *base_it;
+ break;
+ }
+ }
+ if (!base_packet_event_proto) {
+ if (event_proto->base_packet_event_size() >= kMaxPacketsPerFrame) {
+ DVLOG(3) << "Too many packets in AggregatedPacketEvent "
+ << packet_event.rtp_timestamp << ". "
+ << "Using new packet event proto.";
+ AddPacketEventToStorage(event_proto);
+ event_proto.reset(new AggregatedPacketEvent);
+ event_proto->set_relative_rtp_timestamp(relative_rtp_timestamp);
+ it->second = event_proto;
+ }
- // Look up existing entry. If not found, create a new entry and add to map.
- if (it == packet_event_map_.end()) {
+ base_packet_event_proto = event_proto->add_base_packet_event();
+ base_packet_event_proto->set_packet_id(packet_event.packet_id);
+ } else if (base_packet_event_proto->event_type_size() >=
+ kMaxEventsPerProto) {
+ DVLOG(3) << "Too many events in packet "
+ << packet_event.rtp_timestamp << ", "
+ << packet_event.packet_id << ". Using new packet event proto.";
+ AddPacketEventToStorage(event_proto);
event_proto.reset(new AggregatedPacketEvent);
event_proto->set_relative_rtp_timestamp(relative_rtp_timestamp);
- packet_event_map_.insert(
- std::make_pair(relative_rtp_timestamp, event_proto));
+ it->second = event_proto;
base_packet_event_proto = event_proto->add_base_packet_event();
base_packet_event_proto->set_packet_id(packet_event.packet_id);
- } else {
- // Found existing entry, now look up existing BasePacketEvent using packet
- // ID. If not found, create a new entry and add to proto.
- event_proto = it->second;
- RepeatedPtrField<BasePacketEvent>* field =
- event_proto->mutable_base_packet_event();
- for (RepeatedPtrField<BasePacketEvent>::pointer_iterator it =
- field->pointer_begin();
- it != field->pointer_end();
- ++it) {
- if ((*it)->packet_id() == packet_event.packet_id) {
- base_packet_event_proto = *it;
- break;
- }
- }
- if (!base_packet_event_proto) {
- base_packet_event_proto = event_proto->add_base_packet_event();
- base_packet_event_proto->set_packet_id(packet_event.packet_id);
- }
}
+ }
- base_packet_event_proto->add_event_type(
- ToProtoEventType(packet_event.type));
- base_packet_event_proto->add_event_timestamp_ms(
- (packet_event.timestamp - base::TimeTicks()).InMilliseconds());
+ base_packet_event_proto->add_event_type(
+ ToProtoEventType(packet_event.type));
+ base_packet_event_proto->add_event_timestamp_ms(
+ (packet_event.timestamp - base::TimeTicks()).InMilliseconds());
- TruncatePacketEventMapIfNeeded();
- }
+ if (packet_event_map_.size() > kMaxMapSize)
+ TransferPacketEvents(kNumMapEntriesToTransfer);
- DCHECK(packet_event_map_.size() <= max_frames_);
+ DCHECK(packet_event_map_.size() <= kMaxMapSize);
+ DCHECK(packet_event_storage_.size() <= max_frames_);
}
void EncodingEventSubscriber::GetEventsAndReset(LogMetadata* metadata,
- FrameEventMap* frame_events,
- PacketEventMap* packet_events) {
+ FrameEventList* frame_events, PacketEventList* packet_events) {
DCHECK(thread_checker_.CalledOnValidThread());
+ // Flush all events.
+ TransferFrameEvents(frame_event_map_.size());
+ TransferPacketEvents(packet_event_map_.size());
+ std::sort(frame_event_storage_.begin(), frame_event_storage_.end(),
+ &IsRtpTimestampLessThan<linked_ptr<AggregatedFrameEvent> >);
+ std::sort(packet_event_storage_.begin(), packet_event_storage_.end(),
+ &IsRtpTimestampLessThan<linked_ptr<AggregatedPacketEvent> >);
+
metadata->set_is_audio(event_media_type_ == AUDIO_EVENT);
metadata->set_first_rtp_timestamp(first_rtp_timestamp_);
- metadata->set_num_frame_events(frame_event_map_.size());
- metadata->set_num_packet_events(packet_event_map_.size());
+ metadata->set_num_frame_events(frame_event_storage_.size());
+ metadata->set_num_packet_events(packet_event_storage_.size());
metadata->set_reference_timestamp_ms_at_unix_epoch(
(base::TimeTicks::UnixEpoch() - base::TimeTicks()).InMilliseconds());
- frame_events->swap(frame_event_map_);
- packet_events->swap(packet_event_map_);
+ frame_events->swap(frame_event_storage_);
+ packet_events->swap(packet_event_storage_);
Reset();
}
@@ -144,18 +204,49 @@ bool EncodingEventSubscriber::ShouldProcessEvent(CastLoggingEvent event) {
return GetEventMediaType(event) == event_media_type_;
}
-void EncodingEventSubscriber::TruncateFrameEventMapIfNeeded() {
- // This works because this is called everytime an event is inserted and
- // we only insert events one at a time.
- if (frame_event_map_.size() > max_frames_)
- frame_event_map_.erase(frame_event_map_.begin());
+void EncodingEventSubscriber::TransferFrameEvents(size_t max_num_entries) {
+ DCHECK(frame_event_map_.size() >= max_num_entries);
+
+ FrameEventMap::iterator it = frame_event_map_.begin();
+ for (size_t i = 0;
+ i < max_num_entries && it != frame_event_map_.end();
+ i++, ++it) {
+ AddFrameEventToStorage(it->second);
+ }
+
+ frame_event_map_.erase(frame_event_map_.begin(), it);
}
-void EncodingEventSubscriber::TruncatePacketEventMapIfNeeded() {
- // This works because this is called everytime an event is inserted and
- // we only insert events one at a time.
- if (packet_event_map_.size() > max_frames_)
- packet_event_map_.erase(packet_event_map_.begin());
+void EncodingEventSubscriber::TransferPacketEvents(size_t max_num_entries) {
+ PacketEventMap::iterator it = packet_event_map_.begin();
+ for (size_t i = 0;
+ i < max_num_entries && it != packet_event_map_.end();
+ i++, ++it) {
+ AddPacketEventToStorage(it->second);
+ }
+
+ packet_event_map_.erase(packet_event_map_.begin(), it);
+}
+
+void EncodingEventSubscriber::AddFrameEventToStorage(
+ const linked_ptr<AggregatedFrameEvent>& frame_event_proto) {
+ if (frame_event_storage_.size() >= max_frames_) {
+ frame_event_storage_[frame_event_storage_index_] = frame_event_proto;
+ } else {
+ frame_event_storage_.push_back(frame_event_proto);
+ }
+
+ frame_event_storage_index_ = (frame_event_storage_index_ + 1) % max_frames_;
+}
+
+void EncodingEventSubscriber::AddPacketEventToStorage(
+ const linked_ptr<AggregatedPacketEvent>& packet_event_proto) {
+ if (packet_event_storage_.size() >= max_frames_)
+ packet_event_storage_[packet_event_storage_index_] = packet_event_proto;
+ else
+ packet_event_storage_.push_back(packet_event_proto);
+
+ packet_event_storage_index_ = (packet_event_storage_index_ + 1) % max_frames_;
}
RtpTimestamp EncodingEventSubscriber::GetRelativeRtpTimestamp(
@@ -170,7 +261,11 @@ RtpTimestamp EncodingEventSubscriber::GetRelativeRtpTimestamp(
void EncodingEventSubscriber::Reset() {
frame_event_map_.clear();
+ frame_event_storage_.clear();
+ frame_event_storage_index_ = 0;
packet_event_map_.clear();
+ packet_event_storage_.clear();
+ packet_event_storage_index_ = 0;
seen_first_rtp_timestamp_ = false;
first_rtp_timestamp_ = 0u;
}
diff --git a/media/cast/logging/encoding_event_subscriber.h b/media/cast/logging/encoding_event_subscriber.h
index e134f50..c507499 100644
--- a/media/cast/logging/encoding_event_subscriber.h
+++ b/media/cast/logging/encoding_event_subscriber.h
@@ -16,21 +16,32 @@
namespace media {
namespace cast {
-typedef std::map<RtpTimestamp,
- linked_ptr<media::cast::proto::AggregatedFrameEvent> >
- FrameEventMap;
-typedef std::map<RtpTimestamp,
- linked_ptr<media::cast::proto::AggregatedPacketEvent> >
- PacketEventMap;
+// Number of packets per frame recorded by the subscriber.
+// Once the max number of packets has been reached, a new aggregated proto
+// will be created.
+static const int kMaxPacketsPerFrame = 64;
+// Number of events per proto recorded by the subscriber.
+// Once the max number of events has been reached, a new aggregated proto
+// will be created.
+static const int kMaxEventsPerProto = 16;
+
+typedef std::vector<linked_ptr<media::cast::proto::AggregatedFrameEvent> >
+ FrameEventList;
+typedef std::vector<linked_ptr<media::cast::proto::AggregatedPacketEvent> >
+ PacketEventList;
// A RawEventSubscriber implementation that subscribes to events,
// encodes them in protocol buffer format, and aggregates them into a more
-// compact structure.
+// compact structure. Aggregation is per-frame, and uses a map with RTP
+// timestamp as key. Periodically, old entries in the map will be transferred
+// to a storage vector. This helps keep the size of the map small and
+// lookup times fast. The storage itself is a circular buffer that will
+// overwrite old entries once it has reached the size configured by user.
class EncodingEventSubscriber : public RawEventSubscriber {
public:
// |event_media_type|: The subscriber will only process events that
// corresponds to this type.
- // |max_frames|: How many events to keep in the frame / packet map.
+ // |max_frames|: How many events to keep in the frame / packet storage.
// This helps keep memory usage bounded.
// Every time one of |OnReceive[Frame,Packet]Event()| is
// called, it will check if the respective map size has exceeded |max_frames|.
@@ -47,18 +58,35 @@ class EncodingEventSubscriber : public RawEventSubscriber {
// Assigns frame events and packet events received so far to |frame_events|
// and |packet_events| and resets the internal state.
// In addition, assign metadata associated with these events to |metadata|.
+ // The protos in |frame_events| and |packets_events| are sorted in
+ // ascending RTP timestamp order.
void GetEventsAndReset(media::cast::proto::LogMetadata* metadata,
- FrameEventMap* frame_events,
- PacketEventMap* packet_events);
+ FrameEventList* frame_events,
+ PacketEventList* packet_events);
private:
+ typedef std::map<RtpTimestamp,
+ linked_ptr<media::cast::proto::AggregatedFrameEvent> >
+ FrameEventMap;
+ typedef std::map<RtpTimestamp,
+ linked_ptr<media::cast::proto::AggregatedPacketEvent> >
+ PacketEventMap;
+
bool ShouldProcessEvent(CastLoggingEvent event);
- // Removes oldest entry from |frame_event_map_| (ordered by RTP timestamp).
- void TruncateFrameEventMapIfNeeded();
+ // Transfer up to |max_num_entries| smallest entries from |frame_event_map_|
+ // to |frame_event_storage_|. This helps keep size of |frame_event_map_| small
+ // and lookup speed fast.
+ void TransferFrameEvents(size_t max_num_entries);
+ // See above.
+ void TransferPacketEvents(size_t max_num_entries);
- // Removes oldest entry from |packet_event_map_| (ordered by RTP timestamp).
- void TruncatePacketEventMapIfNeeded();
+ void AddFrameEventToStorage(
+ const linked_ptr<media::cast::proto::AggregatedFrameEvent>&
+ frame_event_proto);
+ void AddPacketEventToStorage(
+ const linked_ptr<media::cast::proto::AggregatedPacketEvent>&
+ packet_event_proto);
// Returns the difference between |rtp_timestamp| and |first_rtp_timestamp_|.
// Sets |first_rtp_timestamp_| if it is not already set.
@@ -71,7 +99,12 @@ class EncodingEventSubscriber : public RawEventSubscriber {
const size_t max_frames_;
FrameEventMap frame_event_map_;
+ FrameEventList frame_event_storage_;
+ int frame_event_storage_index_;
+
PacketEventMap packet_event_map_;
+ PacketEventList packet_event_storage_;
+ int packet_event_storage_index_;
// All functions must be called on the main thread.
base::ThreadChecker thread_checker_;
diff --git a/media/cast/logging/encoding_event_subscriber_unittest.cc b/media/cast/logging/encoding_event_subscriber_unittest.cc
index 4e30bbc..eafe3f1 100644
--- a/media/cast/logging/encoding_event_subscriber_unittest.cc
+++ b/media/cast/logging/encoding_event_subscriber_unittest.cc
@@ -64,8 +64,8 @@ class EncodingEventSubscriberTest : public ::testing::Test {
scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
scoped_refptr<CastEnvironment> cast_environment_;
scoped_ptr<EncodingEventSubscriber> event_subscriber_;
- FrameEventMap frame_events_;
- PacketEventMap packet_events_;
+ FrameEventList frame_events_;
+ PacketEventList packet_events_;
LogMetadata metadata_;
RtpTimestamp first_rtp_timestamp_;
};
@@ -90,8 +90,8 @@ TEST_F(EncodingEventSubscriberTest, FrameEventTruncating) {
GetEventsAndReset();
ASSERT_EQ(10u, frame_events_.size());
- EXPECT_EQ(100u, frame_events_.begin()->first);
- EXPECT_EQ(1000u, frame_events_.rbegin()->first);
+ EXPECT_EQ(100u, frame_events_.front()->relative_rtp_timestamp());
+ EXPECT_EQ(1000u, frame_events_.back()->relative_rtp_timestamp());
}
TEST_F(EncodingEventSubscriberTest, PacketEventTruncating) {
@@ -113,8 +113,8 @@ TEST_F(EncodingEventSubscriberTest, PacketEventTruncating) {
GetEventsAndReset();
ASSERT_EQ(10u, packet_events_.size());
- EXPECT_EQ(100u, packet_events_.begin()->first);
- EXPECT_EQ(1000u, packet_events_.rbegin()->first);
+ EXPECT_EQ(100u, packet_events_.front()->relative_rtp_timestamp());
+ EXPECT_EQ(1000u, packet_events_.back()->relative_rtp_timestamp());
}
TEST_F(EncodingEventSubscriberTest, EventFiltering) {
@@ -135,10 +135,10 @@ TEST_F(EncodingEventSubscriberTest, EventFiltering) {
GetEventsAndReset();
- FrameEventMap::iterator frame_it = frame_events_.find(0);
- ASSERT_TRUE(frame_it != frame_events_.end());
+ ASSERT_EQ(1u, frame_events_.size());
+ FrameEventList::iterator it = frame_events_.begin();
- linked_ptr<AggregatedFrameEvent> frame_event = frame_it->second;
+ linked_ptr<AggregatedFrameEvent> frame_event = *it;
ASSERT_EQ(1, frame_event->event_type_size());
EXPECT_EQ(media::cast::proto::VIDEO_FRAME_DECODED,
@@ -162,10 +162,9 @@ TEST_F(EncodingEventSubscriberTest, FrameEvent) {
ASSERT_EQ(1u, frame_events_.size());
RtpTimestamp relative_rtp_timestamp = rtp_timestamp - first_rtp_timestamp_;
- FrameEventMap::iterator it = frame_events_.find(relative_rtp_timestamp);
- ASSERT_TRUE(it != frame_events_.end());
+ FrameEventList::iterator it = frame_events_.begin();
- linked_ptr<AggregatedFrameEvent> event = it->second;
+ linked_ptr<AggregatedFrameEvent> event = *it;
EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
@@ -195,10 +194,9 @@ TEST_F(EncodingEventSubscriberTest, FrameEventDelay) {
ASSERT_EQ(1u, frame_events_.size());
RtpTimestamp relative_rtp_timestamp = rtp_timestamp - first_rtp_timestamp_;
- FrameEventMap::iterator it = frame_events_.find(relative_rtp_timestamp);
- ASSERT_TRUE(it != frame_events_.end());
+ FrameEventList::iterator it = frame_events_.begin();
- linked_ptr<AggregatedFrameEvent> event = it->second;
+ linked_ptr<AggregatedFrameEvent> event = *it;
EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
@@ -228,10 +226,9 @@ TEST_F(EncodingEventSubscriberTest, FrameEventSize) {
ASSERT_EQ(1u, frame_events_.size());
RtpTimestamp relative_rtp_timestamp = rtp_timestamp - first_rtp_timestamp_;
- FrameEventMap::iterator it = frame_events_.find(relative_rtp_timestamp);
- ASSERT_TRUE(it != frame_events_.end());
+ FrameEventList::iterator it = frame_events_.begin();
- linked_ptr<AggregatedFrameEvent> event = it->second;
+ linked_ptr<AggregatedFrameEvent> event = *it;
EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
@@ -273,10 +270,9 @@ TEST_F(EncodingEventSubscriberTest, MultipleFrameEvents) {
ASSERT_EQ(2u, frame_events_.size());
RtpTimestamp relative_rtp_timestamp = rtp_timestamp1 - first_rtp_timestamp_;
- FrameEventMap::iterator it = frame_events_.find(relative_rtp_timestamp);
- ASSERT_TRUE(it != frame_events_.end());
+ FrameEventList::iterator it = frame_events_.begin();
- linked_ptr<AggregatedFrameEvent> event = it->second;
+ linked_ptr<AggregatedFrameEvent> event = *it;
EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
@@ -291,10 +287,9 @@ TEST_F(EncodingEventSubscriberTest, MultipleFrameEvents) {
EXPECT_FALSE(event->has_key_frame());
relative_rtp_timestamp = rtp_timestamp2 - first_rtp_timestamp_;
- it = frame_events_.find(relative_rtp_timestamp);
- ASSERT_TRUE(it != frame_events_.end());
+ ++it;
- event = it->second;
+ event = *it;
EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
@@ -322,10 +317,9 @@ TEST_F(EncodingEventSubscriberTest, PacketEvent) {
ASSERT_EQ(1u, packet_events_.size());
RtpTimestamp relative_rtp_timestamp = rtp_timestamp - first_rtp_timestamp_;
- PacketEventMap::iterator it = packet_events_.find(relative_rtp_timestamp);
- ASSERT_TRUE(it != packet_events_.end());
+ PacketEventList::iterator it = packet_events_.begin();
- linked_ptr<AggregatedPacketEvent> event = it->second;
+ linked_ptr<AggregatedPacketEvent> event = *it;
EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
@@ -371,10 +365,9 @@ TEST_F(EncodingEventSubscriberTest, MultiplePacketEventsForPacket) {
ASSERT_EQ(1u, packet_events_.size());
RtpTimestamp relative_rtp_timestamp = rtp_timestamp - first_rtp_timestamp_;
- PacketEventMap::iterator it = packet_events_.find(relative_rtp_timestamp);
- ASSERT_TRUE(it != packet_events_.end());
+ PacketEventList::iterator it = packet_events_.begin();
- linked_ptr<AggregatedPacketEvent> event = it->second;
+ linked_ptr<AggregatedPacketEvent> event = *it;
EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
@@ -421,10 +414,9 @@ TEST_F(EncodingEventSubscriberTest, MultiplePacketEventsForFrame) {
ASSERT_EQ(1u, packet_events_.size());
RtpTimestamp relative_rtp_timestamp = rtp_timestamp - first_rtp_timestamp_;
- PacketEventMap::iterator it = packet_events_.find(relative_rtp_timestamp);
- ASSERT_TRUE(it != packet_events_.end());
+ PacketEventList::iterator it = packet_events_.begin();
- linked_ptr<AggregatedPacketEvent> event = it->second;
+ linked_ptr<AggregatedPacketEvent> event = *it;
EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
@@ -477,10 +469,9 @@ TEST_F(EncodingEventSubscriberTest, MultiplePacketEvents) {
ASSERT_EQ(2u, packet_events_.size());
RtpTimestamp relative_rtp_timestamp = rtp_timestamp_1 - first_rtp_timestamp_;
- PacketEventMap::iterator it = packet_events_.find(relative_rtp_timestamp);
- ASSERT_TRUE(it != packet_events_.end());
+ PacketEventList::iterator it = packet_events_.begin();
- linked_ptr<AggregatedPacketEvent> event = it->second;
+ linked_ptr<AggregatedPacketEvent> event = *it;
EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
@@ -494,11 +485,10 @@ TEST_F(EncodingEventSubscriberTest, MultiplePacketEvents) {
EXPECT_EQ(InMilliseconds(now1), base_event.event_timestamp_ms(0));
relative_rtp_timestamp = rtp_timestamp_2 - first_rtp_timestamp_;
- it = packet_events_.find(relative_rtp_timestamp);
+ ++it;
ASSERT_TRUE(it != packet_events_.end());
- event = it->second;
-
+ event = *it;
EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
ASSERT_EQ(1, event->base_packet_event_size());
@@ -529,11 +519,13 @@ TEST_F(EncodingEventSubscriberTest, FirstRtpTimestamp) {
GetEventsAndReset();
EXPECT_EQ(rtp_timestamp, first_rtp_timestamp_);
- FrameEventMap::iterator it = frame_events_.find(0);
+ FrameEventList::iterator it = frame_events_.begin();
ASSERT_NE(frame_events_.end(), it);
+ EXPECT_EQ(0u, (*it)->relative_rtp_timestamp());
- it = frame_events_.find(30);
+ ++it;
ASSERT_NE(frame_events_.end(), it);
+ EXPECT_EQ(30u, (*it)->relative_rtp_timestamp());
rtp_timestamp = 67890;
@@ -564,11 +556,90 @@ TEST_F(EncodingEventSubscriberTest, RelativeRtpTimestampWrapAround) {
GetEventsAndReset();
- FrameEventMap::iterator it = frame_events_.find(0);
+ FrameEventList::iterator it = frame_events_.begin();
ASSERT_NE(frame_events_.end(), it);
+ EXPECT_EQ(0u, (*it)->relative_rtp_timestamp());
- it = frame_events_.find(30);
+ ++it;
ASSERT_NE(frame_events_.end(), it);
+ EXPECT_EQ(30u, (*it)->relative_rtp_timestamp());
+}
+
+TEST_F(EncodingEventSubscriberTest, MaxEventsPerProto) {
+ Init(VIDEO_EVENT);
+ RtpTimestamp rtp_timestamp = 100;
+ for (int i = 0; i < kMaxEventsPerProto + 1; i++) {
+ cast_environment_->Logging()->InsertFrameEvent(testing_clock_->NowTicks(),
+ kVideoAckReceived,
+ rtp_timestamp,
+ /*frame_id*/ 0);
+ testing_clock_->Advance(base::TimeDelta::FromMilliseconds(30));
+ }
+
+ GetEventsAndReset();
+
+ ASSERT_EQ(2u, frame_events_.size());
+ FrameEventList::iterator frame_it = frame_events_.begin();
+ ASSERT_TRUE(frame_it != frame_events_.end());
+
+ linked_ptr<AggregatedFrameEvent> frame_event = *frame_it;
+
+ EXPECT_EQ(kMaxEventsPerProto, frame_event->event_type_size());
+
+ for (int i = 0; i < kMaxPacketsPerFrame + 1; i++) {
+ cast_environment_->Logging()->InsertPacketEvent(
+ testing_clock_->NowTicks(),
+ kVideoPacketRetransmitted,
+ rtp_timestamp,
+ /*frame_id*/ 0,
+ i,
+ kMaxPacketsPerFrame,
+ 123);
+ testing_clock_->Advance(base::TimeDelta::FromMilliseconds(30));
+ }
+
+ GetEventsAndReset();
+
+ EXPECT_EQ(2u, packet_events_.size());
+
+ PacketEventList::iterator packet_it = packet_events_.begin();
+ ASSERT_TRUE(packet_it != packet_events_.end());
+
+ linked_ptr<AggregatedPacketEvent> packet_event = *packet_it;
+
+ EXPECT_EQ(kMaxPacketsPerFrame,
+ packet_event->base_packet_event_size());
+
+ ++packet_it;
+ packet_event = *packet_it;
+ EXPECT_EQ(1, packet_event->base_packet_event_size());
+
+ for (int j = 0; j < kMaxEventsPerProto + 1; j++) {
+ cast_environment_->Logging()->InsertPacketEvent(
+ testing_clock_->NowTicks(),
+ kVideoPacketRetransmitted,
+ rtp_timestamp,
+ /*frame_id*/ 0,
+ 0,
+ 0,
+ 123);
+ testing_clock_->Advance(base::TimeDelta::FromMilliseconds(30));
+ }
+
+ GetEventsAndReset();
+
+ EXPECT_EQ(2u, packet_events_.size());
+ packet_it = packet_events_.begin();
+ ASSERT_TRUE(packet_it != packet_events_.end());
+
+ packet_event = *packet_it;
+
+ EXPECT_EQ(kMaxEventsPerProto,
+ packet_event->base_packet_event(0).event_type_size());
+
+ ++packet_it;
+ packet_event = *packet_it;
+ EXPECT_EQ(1, packet_event->base_packet_event(0).event_type_size());
}
} // namespace cast
diff --git a/media/cast/logging/log_deserializer.cc b/media/cast/logging/log_deserializer.cc
index 997daa9..5621be0 100644
--- a/media/cast/logging/log_deserializer.cc
+++ b/media/cast/logging/log_deserializer.cc
@@ -8,6 +8,7 @@
#include <utility>
#include "base/big_endian.h"
+#include "base/memory/scoped_ptr.h"
#include "third_party/zlib/zlib.h"
using media::cast::FrameEventMap;
@@ -15,6 +16,7 @@ using media::cast::PacketEventMap;
using media::cast::RtpTimestamp;
using media::cast::proto::AggregatedFrameEvent;
using media::cast::proto::AggregatedPacketEvent;
+using media::cast::proto::BasePacketEvent;
using media::cast::proto::LogMetadata;
namespace {
@@ -25,6 +27,38 @@ namespace {
// Keep in sync with media/cast/logging/log_serializer.cc.
const int kMaxUncompressedBytes = 60 * 1000 * 1000;
+void MergePacketEvent(const AggregatedPacketEvent& from,
+ linked_ptr<AggregatedPacketEvent> to) {
+ for (int i = 0; i < from.base_packet_event_size(); i++) {
+ const BasePacketEvent& from_base_event = from.base_packet_event(i);
+ bool merged = false;
+ for (int j = 0; j < to->base_packet_event_size(); j++) {
+ BasePacketEvent* to_base_event = to->mutable_base_packet_event(i);
+ if (from_base_event.packet_id() == to_base_event->packet_id()) {
+ to_base_event->MergeFrom(from_base_event);
+ merged = true;
+ break;
+ }
+ }
+ if (!merged) {
+ BasePacketEvent* to_base_event = to->add_base_packet_event();
+ to_base_event->CopyFrom(from_base_event);
+ }
+ }
+}
+
+void MergeFrameEvent(const AggregatedFrameEvent& from,
+ linked_ptr<AggregatedFrameEvent> to) {
+ to->mutable_event_type()->MergeFrom(from.event_type());
+ to->mutable_event_timestamp_ms()->MergeFrom(from.event_timestamp_ms());
+ if (!to->has_encoded_frame_size())
+ to->set_encoded_frame_size(from.encoded_frame_size());
+ if (!to->has_delay_millis())
+ to->set_delay_millis(from.delay_millis());
+ if (!to->has_key_frame())
+ to->set_key_frame(from.key_frame());
+}
+
bool PopulateDeserializedLog(base::BigEndianReader* reader,
media::cast::DeserializedLog* log) {
FrameEventMap frame_event_map;
@@ -50,12 +84,15 @@ bool PopulateDeserializedLog(base::BigEndianReader* reader,
frame_event->relative_rtp_timestamp() + relative_rtp_timestamp);
relative_rtp_timestamp = frame_event->relative_rtp_timestamp();
- std::pair<FrameEventMap::iterator, bool> result = frame_event_map.insert(
- std::make_pair(frame_event->relative_rtp_timestamp(), frame_event));
- if (!result.second) {
- VLOG(1) << "Duplicate frame event entry detected: "
- << frame_event->relative_rtp_timestamp();
- return false;
+ FrameEventMap::iterator it = frame_event_map.find(
+ frame_event->relative_rtp_timestamp());
+ if (it == frame_event_map.end()) {
+ frame_event_map.insert(
+ std::make_pair(frame_event->relative_rtp_timestamp(), frame_event));
+ } else {
+ // Events for the same frame might have been split into more than one
+ // proto. Merge them.
+ MergeFrameEvent(*frame_event, it->second);
}
}
@@ -77,12 +114,15 @@ bool PopulateDeserializedLog(base::BigEndianReader* reader,
packet_event->relative_rtp_timestamp() + relative_rtp_timestamp);
relative_rtp_timestamp = packet_event->relative_rtp_timestamp();
- std::pair<PacketEventMap::iterator, bool> result = packet_event_map.insert(
- std::make_pair(packet_event->relative_rtp_timestamp(), packet_event));
- if (!result.second) {
- VLOG(1) << "Duplicate packet event entry detected: "
- << packet_event->relative_rtp_timestamp();
- return false;
+ PacketEventMap::iterator it = packet_event_map.find(
+ packet_event->relative_rtp_timestamp());
+ if (it == packet_event_map.end()) {
+ packet_event_map.insert(
+ std::make_pair(packet_event->relative_rtp_timestamp(), packet_event));
+ } else {
+ // Events for the same frame might have been split into more than one
+ // proto. Merge them.
+ MergePacketEvent(*packet_event, it->second);
}
}
diff --git a/media/cast/logging/log_deserializer.h b/media/cast/logging/log_deserializer.h
index 6087eec..01b6db7 100644
--- a/media/cast/logging/log_deserializer.h
+++ b/media/cast/logging/log_deserializer.h
@@ -5,14 +5,23 @@
#ifndef MEDIA_CAST_LOGGING_LOG_DESERIALIZER_H_
#define MEDIA_CAST_LOGGING_LOG_DESERIALIZER_H_
+#include <map>
#include <string>
-#include "base/memory/scoped_ptr.h"
-#include "media/cast/logging/encoding_event_subscriber.h"
+#include "base/memory/linked_ptr.h"
+#include "media/cast/logging/logging_defines.h"
+#include "media/cast/logging/proto/raw_events.pb.h"
namespace media {
namespace cast {
+typedef std::map<RtpTimestamp,
+ linked_ptr<media::cast::proto::AggregatedFrameEvent> >
+ FrameEventMap;
+typedef std::map<RtpTimestamp,
+ linked_ptr<media::cast::proto::AggregatedPacketEvent> >
+ PacketEventMap;
+
// Represents deserialized raw event logs for a particular stream.
struct DeserializedLog {
DeserializedLog();
diff --git a/media/cast/logging/log_serializer.cc b/media/cast/logging/log_serializer.cc
index 3452c90..afcf770 100644
--- a/media/cast/logging/log_serializer.cc
+++ b/media/cast/logging/log_serializer.cc
@@ -3,8 +3,8 @@
// found in the LICENSE file.
//
// The serialization format is as follows:
-// 8-bit integer describing |is_audio|.
-// 32-bit integer describing |first_rtp_timestamp|.
+// 16-bit integer describing the following LogMetadata proto size in bytes.
+// The LogMetadata proto.
// 32-bit integer describing number of frame events.
// (The following repeated for number of frame events):
// 16-bit integer describing the following AggregatedFrameEvent proto size
@@ -19,6 +19,8 @@
#include "media/cast/logging/log_serializer.h"
#include "base/big_endian.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
#include "third_party/zlib/zlib.h"
namespace media {
@@ -33,15 +35,18 @@ using media::cast::proto::LogMetadata;
// Use 30MB of temp buffer to hold uncompressed data if |compress| is true.
const int kMaxUncompressedBytes = 30 * 1000 * 1000;
+// The maximum allowed size per serialized proto.
+const int kMaxSerializedProtoBytes = (1 << 16) - 1;
bool DoSerializeEvents(const LogMetadata& metadata,
- const FrameEventMap& frame_events,
- const PacketEventMap& packet_events,
+ const FrameEventList& frame_events,
+ const PacketEventList& packet_events,
const int max_output_bytes,
char* output,
int* output_bytes) {
base::BigEndianWriter writer(output, max_output_bytes);
int proto_size = metadata.ByteSize();
+ DCHECK(proto_size <= kMaxSerializedProtoBytes);
if (!writer.WriteU16(proto_size))
return false;
if (!metadata.SerializeToArray(writer.ptr(), writer.remaining()))
@@ -50,19 +55,22 @@ bool DoSerializeEvents(const LogMetadata& metadata,
return false;
RtpTimestamp prev_rtp_timestamp = 0;
- for (media::cast::FrameEventMap::const_iterator it = frame_events.begin();
+ for (media::cast::FrameEventList::const_iterator it = frame_events.begin();
it != frame_events.end();
++it) {
- media::cast::proto::AggregatedFrameEvent frame_event(*(it->second));
+ media::cast::proto::AggregatedFrameEvent frame_event(**it);
// Adjust relative RTP timestamp so that it is relative to previous frame,
// rather than relative to first RTP timestamp.
// This is done to improve encoding size.
+ RtpTimestamp old_relative_rtp_timestamp =
+ frame_event.relative_rtp_timestamp();
frame_event.set_relative_rtp_timestamp(
- frame_event.relative_rtp_timestamp() - prev_rtp_timestamp);
- prev_rtp_timestamp = it->first;
+ old_relative_rtp_timestamp - prev_rtp_timestamp);
+ prev_rtp_timestamp = old_relative_rtp_timestamp;
proto_size = frame_event.ByteSize();
+ DCHECK(proto_size <= kMaxSerializedProtoBytes);
// Write size of the proto, then write the proto.
if (!writer.WriteU16(proto_size))
@@ -75,15 +83,18 @@ bool DoSerializeEvents(const LogMetadata& metadata,
// Write packet events.
prev_rtp_timestamp = 0;
- for (media::cast::PacketEventMap::const_iterator it = packet_events.begin();
+ for (media::cast::PacketEventList::const_iterator it = packet_events.begin();
it != packet_events.end();
++it) {
- media::cast::proto::AggregatedPacketEvent packet_event(*(it->second));
+ media::cast::proto::AggregatedPacketEvent packet_event(**it);
+ RtpTimestamp old_relative_rtp_timestamp =
+ packet_event.relative_rtp_timestamp();
packet_event.set_relative_rtp_timestamp(
- packet_event.relative_rtp_timestamp() - prev_rtp_timestamp);
- prev_rtp_timestamp = it->first;
+ old_relative_rtp_timestamp - prev_rtp_timestamp);
+ prev_rtp_timestamp = old_relative_rtp_timestamp;
proto_size = packet_event.ByteSize();
+ DCHECK(proto_size <= kMaxSerializedProtoBytes);
// Write size of the proto, then write the proto.
if (!writer.WriteU16(proto_size))
@@ -138,8 +149,8 @@ bool Compress(char* uncompressed_buffer,
} // namespace
bool SerializeEvents(const LogMetadata& log_metadata,
- const FrameEventMap& frame_events,
- const PacketEventMap& packet_events,
+ const FrameEventList& frame_events,
+ const PacketEventList& packet_events,
bool compress,
int max_output_bytes,
char* output,
diff --git a/media/cast/logging/log_serializer.h b/media/cast/logging/log_serializer.h
index 136932f..8aff54f 100644
--- a/media/cast/logging/log_serializer.h
+++ b/media/cast/logging/log_serializer.h
@@ -7,7 +7,6 @@
#include <string>
-#include "base/memory/scoped_ptr.h"
#include "media/cast/logging/encoding_event_subscriber.h"
namespace media {
@@ -25,8 +24,8 @@ namespace cast {
//
// See .cc file for format specification.
bool SerializeEvents(const media::cast::proto::LogMetadata& log_metadata,
- const FrameEventMap& frame_events,
- const PacketEventMap& packet_events,
+ const FrameEventList& frame_events,
+ const PacketEventList& packet_events,
bool compress,
int max_output_bytes,
char* output,
diff --git a/media/cast/logging/serialize_deserialize_test.cc b/media/cast/logging/serialize_deserialize_test.cc
index d4ecf46..8844727 100644
--- a/media/cast/logging/serialize_deserialize_test.cc
+++ b/media/cast/logging/serialize_deserialize_test.cc
@@ -5,6 +5,7 @@
// Joint LogSerializer and LogDeserializer testing to make sure they stay in
// sync.
+#include "base/memory/scoped_ptr.h"
#include "media/cast/logging/log_deserializer.h"
#include "media/cast/logging/log_serializer.h"
#include "media/cast/logging/logging_defines.h"
@@ -66,8 +67,7 @@ class SerializeDeserializeTest : public ::testing::Test {
kEncodedFrameSize[i % arraysize(kEncodedFrameSize)]);
frame_event->set_delay_millis(kDelayMillis[i % arraysize(kDelayMillis)]);
- frame_event_map_.insert(
- std::make_pair(frame_event->relative_rtp_timestamp(), frame_event));
+ frame_event_list_.push_back(frame_event);
}
event_time_ms = 0;
@@ -88,8 +88,7 @@ class SerializeDeserializeTest : public ::testing::Test {
event_time_ms += 256;
}
}
- packet_event_map_.insert(
- std::make_pair(packet_event->relative_rtp_timestamp(), packet_event));
+ packet_event_list_.push_back(packet_event);
}
}
@@ -102,39 +101,37 @@ class SerializeDeserializeTest : public ::testing::Test {
returned_metadata.SerializeAsString());
// Check that the returned map is equal to the original map.
- EXPECT_EQ(frame_event_map_.size(), returned_frame_events.size());
+ EXPECT_EQ(frame_event_list_.size(), returned_frame_events.size());
for (FrameEventMap::const_iterator frame_it = returned_frame_events.begin();
frame_it != returned_frame_events.end();
++frame_it) {
- FrameEventMap::iterator original_it =
- frame_event_map_.find(frame_it->first);
- ASSERT_NE(frame_event_map_.end(), original_it);
+ FrameEventList::iterator original_it = frame_event_list_.begin();
+ ASSERT_NE(frame_event_list_.end(), original_it);
// Compare protos by serializing and checking the bytes.
- EXPECT_EQ(original_it->second->SerializeAsString(),
+ EXPECT_EQ((*original_it)->SerializeAsString(),
frame_it->second->SerializeAsString());
- frame_event_map_.erase(original_it);
+ frame_event_list_.erase(frame_event_list_.begin());
}
- EXPECT_TRUE(frame_event_map_.empty());
+ EXPECT_TRUE(frame_event_list_.empty());
- EXPECT_EQ(packet_event_map_.size(), returned_packet_events.size());
+ EXPECT_EQ(packet_event_list_.size(), returned_packet_events.size());
for (PacketEventMap::const_iterator packet_it =
returned_packet_events.begin();
packet_it != returned_packet_events.end();
++packet_it) {
- PacketEventMap::iterator original_it =
- packet_event_map_.find(packet_it->first);
- ASSERT_NE(packet_event_map_.end(), original_it);
+ PacketEventList::iterator original_it = packet_event_list_.begin();
+ ASSERT_NE(packet_event_list_.end(), original_it);
// Compare protos by serializing and checking the bytes.
- EXPECT_EQ(original_it->second->SerializeAsString(),
+ EXPECT_EQ((*original_it)->SerializeAsString(),
packet_it->second->SerializeAsString());
- packet_event_map_.erase(original_it);
+ packet_event_list_.erase(packet_event_list_.begin());
}
- EXPECT_TRUE(packet_event_map_.empty());
+ EXPECT_TRUE(packet_event_list_.empty());
}
LogMetadata metadata_;
- FrameEventMap frame_event_map_;
- PacketEventMap packet_event_map_;
+ FrameEventList frame_event_list_;
+ PacketEventList packet_event_list_;
scoped_ptr<char[]> serialized_;
int output_bytes_;
};
@@ -144,8 +141,8 @@ TEST_F(SerializeDeserializeTest, Uncompressed) {
Init();
bool success = SerializeEvents(metadata_,
- frame_event_map_,
- packet_event_map_,
+ frame_event_list_,
+ packet_event_list_,
compressed,
kMaxSerializedBytes,
serialized_.get(),
@@ -167,8 +164,8 @@ TEST_F(SerializeDeserializeTest, UncompressedInsufficientSpace) {
Init();
serialized_.reset(new char[100]);
bool success = SerializeEvents(metadata_,
- frame_event_map_,
- packet_event_map_,
+ frame_event_list_,
+ packet_event_list_,
compressed,
100,
serialized_.get(),
@@ -181,8 +178,8 @@ TEST_F(SerializeDeserializeTest, Compressed) {
bool compressed = true;
Init();
bool success = SerializeEvents(metadata_,
- frame_event_map_,
- packet_event_map_,
+ frame_event_list_,
+ packet_event_list_,
compressed,
kMaxSerializedBytes,
serialized_.get(),
@@ -203,8 +200,8 @@ TEST_F(SerializeDeserializeTest, CompressedInsufficientSpace) {
Init();
serialized_.reset(new char[100]);
bool success = SerializeEvents(metadata_,
- frame_event_map_,
- packet_event_map_,
+ frame_event_list_,
+ packet_event_list_,
compressed,
100,
serialized_.get(),