Revert safe-browsing PrefixSet size_t handling.
[chromium-blink-merge.git] / media / cast / rtcp / receiver_rtcp_event_subscriber.h
blob4a987351462e4feefb7bbe5803bbb38bbdf9583c
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.
5 #ifndef MEDIA_CAST_RTCP_RECEIVER_RTCP_EVENT_SUBSCRIBER_H_
6 #define MEDIA_CAST_RTCP_RECEIVER_RTCP_EVENT_SUBSCRIBER_H_
8 #include <map>
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"
15 namespace base {
16 class SingleThreadTaskRunner;
19 namespace media {
20 namespace cast {
22 // A RawEventSubscriber implementation with the following properties:
23 // - Only processes raw event types that are relevant for sending from cast
24 // receiver to cast sender via RTCP.
25 // - Captures information to be sent over to RTCP from raw event logs into the
26 // more compact RtcpEvent struct.
27 // - Orders events by RTP timestamp with a multimap.
28 // - Internally, the map is capped at a maximum size configurable by the caller.
29 // The subscriber only keeps the most recent events (determined by RTP
30 // timestamp) up to the size limit.
31 class ReceiverRtcpEventSubscriber : public RawEventSubscriber {
32 public:
33 typedef std::multimap<RtpTimestamp, RtcpEvent> RtcpEventMultiMap;
35 // Identifies whether the subscriber will process audio or video related
36 // frame events.
37 enum Type {
38 kAudioEventSubscriber, // Only processes audio events
39 kVideoEventSubscriber // Only processes video events
42 // |max_size_to_retain|: The object will keep up to |max_size_to_retain|
43 // events
44 // in the map. Once threshold has been reached, an event with the smallest
45 // RTP timestamp will be removed.
46 // |type|: Determines whether the subscriber will process only audio or video
47 // events.
48 ReceiverRtcpEventSubscriber(const size_t max_size_to_retain, Type type);
50 virtual ~ReceiverRtcpEventSubscriber();
52 // RawEventSubscriber implementation.
53 virtual void OnReceiveFrameEvent(const FrameEvent& frame_event) OVERRIDE;
54 virtual void OnReceivePacketEvent(const PacketEvent& packet_event) OVERRIDE;
55 virtual void OnReceiveGenericEvent(const GenericEvent& generic_event)
56 OVERRIDE;
58 const RtcpEventMultiMap& get_rtcp_events() const { return rtcp_events_; }
60 private:
61 // If |rtcp_events_.size()| exceeds |max_size_to_retain_|, remove an oldest
62 // entry (determined by RTP timestamp) so its size no greater than
63 // |max_size_to_retain_|.
64 void TruncateMapIfNeeded();
66 // Returns |true| if events of |event_type| should be processed.
67 bool ShouldProcessEvent(CastLoggingEvent event_type);
69 const size_t max_size_to_retain_;
70 Type type_;
72 // The key should really be something more than just a RTP timestamp in order
73 // to differentiate between video and audio frames, but since the
74 // implementation doesn't mix audio and video frame events, RTP timestamp
75 // only as key is fine.
76 RtcpEventMultiMap rtcp_events_;
78 // Ensures methods are only called on the main thread.
79 base::ThreadChecker thread_checker_;
81 DISALLOW_COPY_AND_ASSIGN(ReceiverRtcpEventSubscriber);
84 } // namespace cast
85 } // namespace media
87 #endif // MEDIA_CAST_RTCP_RECEIVER_RTCP_EVENT_SUBSCRIBER_H_