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

Side by Side Diff: media/cast/logging/encoding_event_subscriber.h

Issue 241833002: Cast: Limit number of events/packets in EncodingEventSubscriber protos. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix merge Created 6 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_CAST_LOGGING_ENCODING_EVENT_SUBSCRIBER_H_ 5 #ifndef MEDIA_CAST_LOGGING_ENCODING_EVENT_SUBSCRIBER_H_
6 #define MEDIA_CAST_LOGGING_ENCODING_EVENT_SUBSCRIBER_H_ 6 #define MEDIA_CAST_LOGGING_ENCODING_EVENT_SUBSCRIBER_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/memory/linked_ptr.h" 10 #include "base/memory/linked_ptr.h"
11 #include "base/threading/thread_checker.h" 11 #include "base/threading/thread_checker.h"
12 #include "media/cast/logging/logging_defines.h" 12 #include "media/cast/logging/logging_defines.h"
13 #include "media/cast/logging/proto/raw_events.pb.h" 13 #include "media/cast/logging/proto/raw_events.pb.h"
14 #include "media/cast/logging/raw_event_subscriber.h" 14 #include "media/cast/logging/raw_event_subscriber.h"
15 15
16 namespace media { 16 namespace media {
17 namespace cast { 17 namespace cast {
18 18
19 typedef std::map<RtpTimestamp, 19 // Number of packets per frame recorded by the subscriber.
20 linked_ptr<media::cast::proto::AggregatedFrameEvent> > 20 // Once the max number of packets has been reached, a new aggregated proto
21 FrameEventMap; 21 // will be created.
22 typedef std::map<RtpTimestamp, 22 static const int kMaxPacketsPerFrame = 64;
23 linked_ptr<media::cast::proto::AggregatedPacketEvent> > 23 // Number of events per proto recorded by the subscriber.
24 PacketEventMap; 24 // Once the max number of events has been reached, a new aggregated proto
25 // will be created.
26 static const int kMaxEventsPerProto = 16;
27
28 typedef std::vector<linked_ptr<media::cast::proto::AggregatedFrameEvent> >
29 FrameEventList;
30 typedef std::vector<linked_ptr<media::cast::proto::AggregatedPacketEvent> >
31 PacketEventList;
25 32
26 // A RawEventSubscriber implementation that subscribes to events, 33 // A RawEventSubscriber implementation that subscribes to events,
27 // encodes them in protocol buffer format, and aggregates them into a more 34 // encodes them in protocol buffer format, and aggregates them into a more
28 // compact structure. 35 // compact structure. Aggregation is per-frame, and uses a map with RTP
36 // timestamp as key. Periodically, old entries in the map will be transferred
37 // to a storage vector. This helps keep the size of the map small and
38 // lookup times fast. The storage itself is a circular buffer that will
39 // overwrite old entries once it has reached the size configured by user.
29 class EncodingEventSubscriber : public RawEventSubscriber { 40 class EncodingEventSubscriber : public RawEventSubscriber {
30 public: 41 public:
31 // |event_media_type|: The subscriber will only process events that 42 // |event_media_type|: The subscriber will only process events that
32 // corresponds to this type. 43 // corresponds to this type.
33 // |max_frames|: How many events to keep in the frame / packet map. 44 // |max_frames|: How many events to keep in the frame / packet storage.
34 // This helps keep memory usage bounded. 45 // This helps keep memory usage bounded.
35 // Every time one of |OnReceive[Frame,Packet]Event()| is 46 // Every time one of |OnReceive[Frame,Packet]Event()| is
36 // called, it will check if the respective map size has exceeded |max_frames|. 47 // called, it will check if the respective map size has exceeded |max_frames|.
37 // If so, it will remove the oldest aggregated entry (ordered by RTP 48 // If so, it will remove the oldest aggregated entry (ordered by RTP
38 // timestamp). 49 // timestamp).
39 EncodingEventSubscriber(EventMediaType event_media_type, size_t max_frames); 50 EncodingEventSubscriber(EventMediaType event_media_type, size_t max_frames);
40 51
41 virtual ~EncodingEventSubscriber(); 52 virtual ~EncodingEventSubscriber();
42 53
43 // RawReventSubscriber implementations. 54 // RawReventSubscriber implementations.
44 virtual void OnReceiveFrameEvent(const FrameEvent& frame_event) OVERRIDE; 55 virtual void OnReceiveFrameEvent(const FrameEvent& frame_event) OVERRIDE;
45 virtual void OnReceivePacketEvent(const PacketEvent& packet_event) OVERRIDE; 56 virtual void OnReceivePacketEvent(const PacketEvent& packet_event) OVERRIDE;
46 57
47 // Assigns frame events and packet events received so far to |frame_events| 58 // Assigns frame events and packet events received so far to |frame_events|
48 // and |packet_events| and resets the internal state. 59 // and |packet_events| and resets the internal state.
49 // In addition, assign metadata associated with these events to |metadata|. 60 // In addition, assign metadata associated with these events to |metadata|.
61 // The protos in |frame_events| and |packets_events| are sorted in
62 // ascending RTP timestamp order.
50 void GetEventsAndReset(media::cast::proto::LogMetadata* metadata, 63 void GetEventsAndReset(media::cast::proto::LogMetadata* metadata,
51 FrameEventMap* frame_events, 64 FrameEventList* frame_events,
52 PacketEventMap* packet_events); 65 PacketEventList* packet_events);
53 66
54 private: 67 private:
68 typedef std::map<RtpTimestamp,
69 linked_ptr<media::cast::proto::AggregatedFrameEvent> >
70 FrameEventMap;
71 typedef std::map<RtpTimestamp,
72 linked_ptr<media::cast::proto::AggregatedPacketEvent> >
73 PacketEventMap;
74
55 bool ShouldProcessEvent(CastLoggingEvent event); 75 bool ShouldProcessEvent(CastLoggingEvent event);
56 76
57 // Removes oldest entry from |frame_event_map_| (ordered by RTP timestamp). 77 // Transfer up to |max_num_entries| smallest entries from |frame_event_map_|
58 void TruncateFrameEventMapIfNeeded(); 78 // to |frame_event_storage_|. This helps keep size of |frame_event_map_| small
79 // and lookup speed fast.
80 void TransferFrameEvents(size_t max_num_entries);
81 // See above.
82 void TransferPacketEvents(size_t max_num_entries);
59 83
60 // Removes oldest entry from |packet_event_map_| (ordered by RTP timestamp). 84 void AddFrameEventToStorage(
61 void TruncatePacketEventMapIfNeeded(); 85 const linked_ptr<media::cast::proto::AggregatedFrameEvent>&
86 frame_event_proto);
87 void AddPacketEventToStorage(
88 const linked_ptr<media::cast::proto::AggregatedPacketEvent>&
89 packet_event_proto);
62 90
63 // Returns the difference between |rtp_timestamp| and |first_rtp_timestamp_|. 91 // Returns the difference between |rtp_timestamp| and |first_rtp_timestamp_|.
64 // Sets |first_rtp_timestamp_| if it is not already set. 92 // Sets |first_rtp_timestamp_| if it is not already set.
65 RtpTimestamp GetRelativeRtpTimestamp(RtpTimestamp rtp_timestamp); 93 RtpTimestamp GetRelativeRtpTimestamp(RtpTimestamp rtp_timestamp);
66 94
67 // Clears the maps and first RTP timestamp seen. 95 // Clears the maps and first RTP timestamp seen.
68 void Reset(); 96 void Reset();
69 97
70 const EventMediaType event_media_type_; 98 const EventMediaType event_media_type_;
71 const size_t max_frames_; 99 const size_t max_frames_;
72 100
73 FrameEventMap frame_event_map_; 101 FrameEventMap frame_event_map_;
102 FrameEventList frame_event_storage_;
103 int frame_event_storage_index_;
104
74 PacketEventMap packet_event_map_; 105 PacketEventMap packet_event_map_;
106 PacketEventList packet_event_storage_;
107 int packet_event_storage_index_;
75 108
76 // All functions must be called on the main thread. 109 // All functions must be called on the main thread.
77 base::ThreadChecker thread_checker_; 110 base::ThreadChecker thread_checker_;
78 111
79 // Set to true on first event encountered after a |Reset()|. 112 // Set to true on first event encountered after a |Reset()|.
80 bool seen_first_rtp_timestamp_; 113 bool seen_first_rtp_timestamp_;
81 114
82 // Set to RTP timestamp of first event encountered after a |Reset()|. 115 // Set to RTP timestamp of first event encountered after a |Reset()|.
83 RtpTimestamp first_rtp_timestamp_; 116 RtpTimestamp first_rtp_timestamp_;
84 117
85 DISALLOW_COPY_AND_ASSIGN(EncodingEventSubscriber); 118 DISALLOW_COPY_AND_ASSIGN(EncodingEventSubscriber);
86 }; 119 };
87 120
88 } // namespace cast 121 } // namespace cast
89 } // namespace media 122 } // namespace media
90 123
91 #endif // MEDIA_CAST_LOGGING_ENCODING_EVENT_SUBSCRIBER_H_ 124 #endif // MEDIA_CAST_LOGGING_ENCODING_EVENT_SUBSCRIBER_H_
OLDNEW
« no previous file with comments | « chrome/renderer/media/cast_session_delegate.cc ('k') | media/cast/logging/encoding_event_subscriber.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698