OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef MEDIA_CAST_RTCP_RECEIVER_RTCP_EVENT_SUBSCRIBER_H_ | |
6 #define MEDIA_CAST_RTCP_RECEIVER_RTCP_EVENT_SUBSCRIBER_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/threading/thread_checker.h" | |
11 #include "media/cast/logging/logging_defines.h" | |
12 #include "media/cast/logging/raw_event_subscriber.h" | |
13 #include "media/cast/rtcp/rtcp_defines.h" | |
14 | |
15 namespace media { | |
16 namespace cast { | |
17 | |
18 // A RawEventSubscriber implementation with the following properties: | |
19 // - Only processes raw event types that are relevant for sending from cast | |
20 // receiver to cast sender via RTCP. | |
21 // - Captures information to be sent over to RTCP from raw event logs into the | |
22 // more compact RtcpEvent struct. | |
23 // - Orders events by RTP timestamp with a multimap. | |
24 // - Internally, the map is capped at a maximum size configurable by the caller. | |
25 // The subscriber only keeps the most recent events (determined by RTP | |
26 // timestamp) up to the size limit. | |
27 class ReceiverRtcpEventSubscriber : public RawEventSubscriber { | |
28 public: | |
29 typedef std::multimap<RtpTimestamp, RtcpEvent> RtcpEventMultiMap; | |
30 | |
31 // |max_size_to_retain|: The object will keep up to |max_size_to_retain| | |
32 // events | |
33 // in the map. Once threshold has been reached, an event with the smallest | |
34 // RTP timestamp will be removed. | |
35 // |type|: Determines whether the subscriber will process only audio or video | |
36 // events. | |
37 ReceiverRtcpEventSubscriber(const size_t max_size_to_retain, | |
38 EventMediaType type); | |
39 | |
40 virtual ~ReceiverRtcpEventSubscriber(); | |
41 | |
42 // RawEventSubscriber implementation. | |
43 virtual void OnReceiveFrameEvent(const FrameEvent& frame_event) OVERRIDE; | |
44 virtual void OnReceivePacketEvent(const PacketEvent& packet_event) OVERRIDE; | |
45 | |
46 // Assigns events collected to |rtcp_events| and clears them from this | |
47 // object. | |
48 void GetRtcpEventsAndReset(RtcpEventMultiMap* rtcp_events); | |
49 | |
50 private: | |
51 // If |rtcp_events_.size()| exceeds |max_size_to_retain_|, remove an oldest | |
52 // entry (determined by RTP timestamp) so its size no greater than | |
53 // |max_size_to_retain_|. | |
54 void TruncateMapIfNeeded(); | |
55 | |
56 // Returns |true| if events of |event_type| and |media_type| | |
57 // should be processed. | |
58 bool ShouldProcessEvent(CastLoggingEvent event_type, | |
59 EventMediaType media_type); | |
60 | |
61 const size_t max_size_to_retain_; | |
62 EventMediaType type_; | |
63 | |
64 // The key should really be something more than just a RTP timestamp in order | |
65 // to differentiate between video and audio frames, but since the | |
66 // implementation doesn't mix audio and video frame events, RTP timestamp | |
67 // only as key is fine. | |
68 RtcpEventMultiMap rtcp_events_; | |
69 | |
70 // Ensures methods are only called on the main thread. | |
71 base::ThreadChecker thread_checker_; | |
72 | |
73 DISALLOW_COPY_AND_ASSIGN(ReceiverRtcpEventSubscriber); | |
74 }; | |
75 | |
76 } // namespace cast | |
77 } // namespace media | |
78 | |
79 #endif // MEDIA_CAST_RTCP_RECEIVER_RTCP_EVENT_SUBSCRIBER_H_ | |
OLD | NEW |