Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1786)

Side by Side Diff: media/cast/net/rtcp/receiver_rtcp_event_subscriber.h

Issue 765643006: Cast: Make receiver use cast_transport (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix end2end test Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Counts how many events have been removed from rtcp_events_.
77 uint64 popped_events_;
78
79 // Events greater than send_ptrs_[0] have not been sent yet.
80 // Events greater than send_ptrs_[1] have been transmit once.
81 // Note that these counters use absolute numbers, so you need
82 // to subtract popped_events_ before looking up the events in
83 // rtcp_events_.
84 uint64 send_ptrs_[kNumResends];
85
86 // For each frame, we push how many events have been added to
87 // rtcp_events_ so far. We use this to make sure that
88 // send_ptrs_[N+1] is always at least kResendDelay frames behind
89 // send_ptrs_[N]. Old information is removed so that information
90 // for (kNumResends + 1) * kResendDelay frames remain.
91 std::deque<uint64> event_levels_for_past_frames_;
69 92
70 // Ensures methods are only called on the main thread. 93 // Ensures methods are only called on the main thread.
71 base::ThreadChecker thread_checker_; 94 base::ThreadChecker thread_checker_;
72 95
73 DISALLOW_COPY_AND_ASSIGN(ReceiverRtcpEventSubscriber); 96 DISALLOW_COPY_AND_ASSIGN(ReceiverRtcpEventSubscriber);
74 }; 97 };
75 98
76 } // namespace cast 99 } // namespace cast
77 } // namespace media 100 } // namespace media
78 101
79 #endif // MEDIA_CAST_RTCP_RECEIVER_RTCP_EVENT_SUBSCRIBER_H_ 102 #endif // MEDIA_CAST_RTCP_RECEIVER_RTCP_EVENT_SUBSCRIBER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698