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_
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"
16 class SingleThreadTaskRunner
;
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
{
33 // Identifies whether the subscriber will process audio or video related
36 kAudioEventSubscriber
, // Only processes audio events
37 kVideoEventSubscriber
// Only processes video events
40 // |max_size_to_retain|: The object will keep up to |max_size_to_retain|
42 // in the map. Once threshold has been reached, an event with the smallest
43 // RTP timestamp will be removed.
44 // |type|: Determines whether the subscriber will process only audio or video
46 ReceiverRtcpEventSubscriber(const size_t max_size_to_retain
, Type type
);
48 virtual ~ReceiverRtcpEventSubscriber();
50 // RawEventSubscriber implementation.
51 virtual void OnReceiveFrameEvent(const FrameEvent
& frame_event
) OVERRIDE
;
52 virtual void OnReceivePacketEvent(const PacketEvent
& packet_event
) OVERRIDE
;
53 virtual void OnReceiveGenericEvent(const GenericEvent
& generic_event
)
56 // Converts all collected events since last invocation into
57 // a RtcpReceiverFrameLogMessage, assigns it to |receiver_log|, and clears
59 void GetReceiverLogMessageAndReset(RtcpReceiverLogMessage
* receiver_log
);
62 // If |rtcp_events_.size()| exceeds |max_size_to_retain_|, remove an oldest
63 // entry (determined by RTP timestamp) so its size no greater than
64 // |max_size_to_retain_|.
65 void TruncateMapIfNeeded();
67 // Returns |true| if events of |event_type| should be processed.
68 bool ShouldProcessEvent(CastLoggingEvent event_type
);
70 const size_t max_size_to_retain_
;
73 // The key should really be something more than just a RTP timestamp in order
74 // to differentiate between video and audio frames, but since the
75 // implementation doesn't mix audio and video frame events, RTP timestamp
76 // only as key is fine.
77 std::multimap
<RtpTimestamp
, RtcpEvent
> rtcp_events_
;
79 // Ensures methods are only called on the main thread.
80 base::ThreadChecker thread_checker_
;
82 DISALLOW_COPY_AND_ASSIGN(ReceiverRtcpEventSubscriber
);
88 #endif // MEDIA_CAST_RTCP_RECEIVER_RTCP_EVENT_SUBSCRIBER_H_