Index: media/cast/logging/encoding_event_subscriber.h |
diff --git a/media/cast/logging/encoding_event_subscriber.h b/media/cast/logging/encoding_event_subscriber.h |
index ba9969bd2c986e245a20a2e55829465db6e250f5..802780634d6a9b11d5a48998b3289a958c8531ae 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|. |
@@ -49,18 +60,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 |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 num_entries); |
+ // See above. |
+ void TransferPacketEvents(size_t 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. |
@@ -73,7 +101,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_; |