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