OLD | NEW |
---|---|
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/proto/raw_events.pb.h" | 13 #include "media/cast/logging/proto/raw_events.pb.h" |
13 #include "media/cast/logging/raw_event_subscriber.h" | 14 #include "media/cast/logging/raw_event_subscriber.h" |
14 | 15 |
15 namespace media { | 16 namespace media { |
16 namespace cast { | 17 namespace cast { |
17 | 18 |
18 typedef std::map<RtpTimestamp, | 19 typedef std::map<RtpTimestamp, |
19 linked_ptr<media::cast::proto::AggregatedFrameEvent> > | 20 linked_ptr<media::cast::proto::AggregatedFrameEvent> > |
20 FrameEventMap; | 21 FrameEventMap; |
21 typedef std::map<RtpTimestamp, | 22 typedef std::map<RtpTimestamp, |
22 linked_ptr<media::cast::proto::AggregatedPacketEvent> > | 23 linked_ptr<media::cast::proto::AggregatedPacketEvent> > |
23 PacketEventMap; | 24 PacketEventMap; |
24 typedef std::map<CastLoggingEvent, | 25 typedef std::map<CastLoggingEvent, |
25 linked_ptr<media::cast::proto::AggregatedGenericEvent> > | 26 linked_ptr<media::cast::proto::AggregatedGenericEvent> > |
26 GenericEventMap; | 27 GenericEventMap; |
27 | 28 |
29 // This struct is passed into EncodingEventSubscriber's constructor. | |
30 struct EncodingEventSubscriberConfig { | |
Alpha Left Google
2014/02/14 18:42:39
Why not give the arguments directly to the constru
imcheng
2014/02/14 20:24:17
I was thinking that with 3 parameters it's better
| |
31 // The subscriber will only process events that belong in |event_media_type|. | |
Alpha Left Google
2014/02/14 18:42:39
nit: that corresponds to |event_media_type|.
imcheng
2014/02/14 20:24:17
Done.
| |
32 EventMediaType event_media_type; | |
33 | |
34 // How many events to keep in the frame / packet map. | |
35 // This helps keep memory usage bounded. | |
36 // Every time one of |OnReceive[Frame,Packet]Event()| is | |
37 // called, it will check if the respective map size has exceeded |max_frames|. | |
38 // If so, it will remove the oldest aggregated entry (ordered by RTP | |
39 // timestamp). | |
40 // Note that there is no active process to remove old events periodically. | |
Alpha Left Google
2014/02/14 18:42:39
What does this mean?
imcheng
2014/02/14 20:24:17
Removing this. I was implementing windowing based
| |
41 size_t max_frames; | |
42 | |
43 // How many time-value pairs to keep per generic event. | |
Alpha Left Google
2014/02/14 18:42:39
I'm not sure we care about the generic events.
imcheng
2014/02/14 20:24:17
These are the generic events currently:
kRttMs, k
| |
44 // This helps keep memory usage bounded. | |
45 // Every time OnReceiveEvent() is called, it will check if the number of | |
46 // time-value pairs have exceeded the |max_generic_event_values|. If so, | |
47 // the oldest pair will be removed. Note that the time here refers to the | |
48 // event time as opposed to RTP timestamp. | |
49 // Note that there is no active process to remove old events periodically. | |
50 int max_generic_event_values; | |
51 }; | |
52 | |
28 // A RawEventSubscriber implementation that subscribes to events, | 53 // A RawEventSubscriber implementation that subscribes to events, |
29 // encodes them in protocol buffer format, and aggregates them into a more | 54 // encodes them in protocol buffer format, and aggregates them into a more |
30 // compact structure. | 55 // compact structure. |
31 // TODO(imcheng): Implement event filtering and windowing based on size. | |
32 class EncodingEventSubscriber : public RawEventSubscriber { | 56 class EncodingEventSubscriber : public RawEventSubscriber { |
33 public: | 57 public: |
34 EncodingEventSubscriber(); | 58 EncodingEventSubscriber(EncodingEventSubscriberConfig config); |
35 | 59 |
36 virtual ~EncodingEventSubscriber(); | 60 virtual ~EncodingEventSubscriber(); |
37 | 61 |
38 // RawReventSubscriber implementations. | 62 // RawReventSubscriber implementations. |
39 virtual void OnReceiveFrameEvent(const FrameEvent& frame_event) OVERRIDE; | 63 virtual void OnReceiveFrameEvent(const FrameEvent& frame_event) OVERRIDE; |
40 virtual void OnReceivePacketEvent(const PacketEvent& packet_event) OVERRIDE; | 64 virtual void OnReceivePacketEvent(const PacketEvent& packet_event) OVERRIDE; |
41 virtual void OnReceiveGenericEvent(const GenericEvent& generic_event) | 65 virtual void OnReceiveGenericEvent(const GenericEvent& generic_event) |
42 OVERRIDE; | 66 OVERRIDE; |
43 | 67 |
44 // Assigns frame events received so far to |frame_events| and clears them | 68 // Assigns frame events received so far to |frame_events| and clears them |
45 // from this object. | 69 // from this object. |
46 void GetFrameEventsAndReset(FrameEventMap* frame_events); | 70 void GetFrameEventsAndReset(FrameEventMap* frame_events); |
47 | 71 |
48 // Assigns packet events received so far to |packet_events| and clears them | 72 // Assigns packet events received so far to |packet_events| and clears them |
49 // from this object. | 73 // from this object. |
50 void GetPacketEventsAndReset(PacketEventMap* packet_events); | 74 void GetPacketEventsAndReset(PacketEventMap* packet_events); |
51 | 75 |
52 // Assigns generic events received so far to |generic_events| and clears them | 76 // Assigns generic events received so far to |generic_events| and clears them |
53 // from this object. | 77 // from this object. |
54 void GetGenericEventsAndReset(GenericEventMap* generic_events); | 78 void GetGenericEventsAndReset(GenericEventMap* generic_events); |
55 | 79 |
56 private: | 80 private: |
81 bool ShouldProcessEvent(CastLoggingEvent event); | |
82 | |
83 // Removes oldest entry from |frame_event_map_| (ordered by RTP timestamp). | |
84 void TruncateFrameEventMapIfNeeded(); | |
85 | |
86 // Removes oldest entry from |packet_event_map_| (ordered by RTP timestamp). | |
87 void TruncatePacketEventMapIfNeeded(); | |
88 | |
89 const EncodingEventSubscriberConfig config_; | |
57 FrameEventMap frame_event_map_; | 90 FrameEventMap frame_event_map_; |
58 PacketEventMap packet_event_map_; | 91 PacketEventMap packet_event_map_; |
59 GenericEventMap generic_event_map_; | 92 GenericEventMap generic_event_map_; |
60 | 93 |
94 // Used internally to keep track of next index to write the next time-value | |
95 // pair to for a particular generic event type. | |
96 int next_write_index_[kNumOfLoggingEvents]; | |
97 | |
61 // All functions must be called on the main thread. | 98 // All functions must be called on the main thread. |
62 base::ThreadChecker thread_checker_; | 99 base::ThreadChecker thread_checker_; |
63 | 100 |
64 DISALLOW_COPY_AND_ASSIGN(EncodingEventSubscriber); | 101 DISALLOW_COPY_AND_ASSIGN(EncodingEventSubscriber); |
65 }; | 102 }; |
66 | 103 |
67 } // namespace cast | 104 } // namespace cast |
68 } // namespace media | 105 } // namespace media |
69 | 106 |
70 #endif // MEDIA_CAST_LOGGING_ENCODING_EVENT_SUBSCRIBER_H_ | 107 #endif // MEDIA_CAST_LOGGING_ENCODING_EVENT_SUBSCRIBER_H_ |
OLD | NEW |