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

Side by Side Diff: chrome/browser/media/cast_transport_host_filter.cc

Issue 387933005: Cast: Refactor RTCP handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 6 years, 5 months 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 | Annotate | Revision Log
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 #include "chrome/browser/media/cast_transport_host_filter.h" 5 #include "chrome/browser/media/cast_transport_host_filter.h"
6 6
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/net/chrome_net_log.h" 8 #include "chrome/browser/net/chrome_net_log.h"
9 #include "media/cast/net/cast_transport_sender.h" 9 #include "media/cast/net/cast_transport_sender.h"
10 10
11 namespace { 11 namespace {
12 12
13 // How often to send raw events. 13 // How often to send raw events.
14 const int kSendRawEventsIntervalSecs = 1; 14 const int kSendRawEventsIntervalSecs = 1;
15 15
16 } 16 }
17 17
18 namespace cast { 18 namespace cast {
19 19
20 CastTransportHostFilter::CastTransportHostFilter() 20 CastTransportHostFilter::CastTransportHostFilter()
21 : BrowserMessageFilter(CastMsgStart) {} 21 : BrowserMessageFilter(CastMsgStart),
22 weak_factory_(this) {}
22 23
23 CastTransportHostFilter::~CastTransportHostFilter() {} 24 CastTransportHostFilter::~CastTransportHostFilter() {}
24 25
25 bool CastTransportHostFilter::OnMessageReceived(const IPC::Message& message) { 26 bool CastTransportHostFilter::OnMessageReceived(const IPC::Message& message) {
26 bool handled = true; 27 bool handled = true;
27 IPC_BEGIN_MESSAGE_MAP(CastTransportHostFilter, message) 28 IPC_BEGIN_MESSAGE_MAP(CastTransportHostFilter, message)
28 IPC_MESSAGE_HANDLER(CastHostMsg_New, OnNew) 29 IPC_MESSAGE_HANDLER(CastHostMsg_New, OnNew)
29 IPC_MESSAGE_HANDLER(CastHostMsg_Delete, OnDelete) 30 IPC_MESSAGE_HANDLER(CastHostMsg_Delete, OnDelete)
30 IPC_MESSAGE_HANDLER(CastHostMsg_InitializeAudio, OnInitializeAudio) 31 IPC_MESSAGE_HANDLER(CastHostMsg_InitializeAudio, OnInitializeAudio)
31 IPC_MESSAGE_HANDLER(CastHostMsg_InitializeVideo, OnInitializeVideo) 32 IPC_MESSAGE_HANDLER(CastHostMsg_InitializeVideo, OnInitializeVideo)
32 IPC_MESSAGE_HANDLER(CastHostMsg_InsertCodedAudioFrame, 33 IPC_MESSAGE_HANDLER(CastHostMsg_InsertCodedAudioFrame,
33 OnInsertCodedAudioFrame) 34 OnInsertCodedAudioFrame)
34 IPC_MESSAGE_HANDLER(CastHostMsg_InsertCodedVideoFrame, 35 IPC_MESSAGE_HANDLER(CastHostMsg_InsertCodedVideoFrame,
35 OnInsertCodedVideoFrame) 36 OnInsertCodedVideoFrame)
36 IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpSender, 37 IPC_MESSAGE_HANDLER(CastHostMsg_SendSenderReport,
37 OnSendRtcpFromRtpSender) 38 OnSendSenderReport)
38 IPC_MESSAGE_HANDLER(CastHostMsg_ResendPackets, 39 IPC_MESSAGE_HANDLER(CastHostMsg_ResendPackets,
39 OnResendPackets) 40 OnResendPackets)
40 IPC_MESSAGE_UNHANDLED(handled = false); 41 IPC_MESSAGE_UNHANDLED(handled = false);
41 IPC_END_MESSAGE_MAP(); 42 IPC_END_MESSAGE_MAP();
42 return handled; 43 return handled;
43 } 44 }
44 45
45 void CastTransportHostFilter::NotifyStatusChange( 46 void CastTransportHostFilter::NotifyStatusChange(
46 int32 channel_id, 47 int32 channel_id,
47 media::cast::CastTransportStatus status) { 48 media::cast::CastTransportStatus status) {
48 Send(new CastMsg_NotifyStatusChange(channel_id, status)); 49 Send(new CastMsg_NotifyStatusChange(channel_id, status));
49 } 50 }
50 51
51 void CastTransportHostFilter::ReceivedPacket( 52 void CastTransportHostFilter::SendRawEvents(
52 int32 channel_id, 53 int32 channel_id,
53 scoped_ptr<media::cast::Packet> packet) { 54 const std::vector<media::cast::PacketEvent>& packet_events,
54 Send(new CastMsg_ReceivedPacket(channel_id, *packet)); 55 const std::vector<media::cast::FrameEvent>& frame_events) {
56 if (!packet_events.empty())
57 Send(new CastMsg_RawEvents(channel_id,
58 packet_events,
59 frame_events));
55 } 60 }
56 61
57 void CastTransportHostFilter::RawEvents( 62 void CastTransportHostFilter::SendRtt(int32 channel_id,
63 uint32 ssrc,
64 base::TimeDelta rtt,
65 base::TimeDelta avg_rtt,
66 base::TimeDelta min_rtt,
67 base::TimeDelta max_rtt) {
68 media::cast::RtcpRttReport report;
69 report.rtt = rtt;
70 report.avg_rtt = avg_rtt;
71 report.min_rtt = min_rtt;
72 report.max_rtt = max_rtt;
73 Send(new CastMsg_Rtt(channel_id, ssrc, report));
74 }
75
76 void CastTransportHostFilter::SendCastMessage(
58 int32 channel_id, 77 int32 channel_id,
59 const std::vector<media::cast::PacketEvent>& packet_events) { 78 uint32 ssrc,
60 if (!packet_events.empty()) 79 const media::cast::RtcpCastMessage& cast_message) {
61 Send(new CastMsg_RawEvents(channel_id, packet_events)); 80 Send(new CastMsg_RtcpCastMessage(channel_id, ssrc, cast_message));
62 } 81 }
63 82
64 void CastTransportHostFilter::OnNew( 83 void CastTransportHostFilter::OnNew(
65 int32 channel_id, 84 int32 channel_id,
66 const net::IPEndPoint& remote_end_point) { 85 const net::IPEndPoint& remote_end_point) {
67 if (id_map_.Lookup(channel_id)) { 86 if (id_map_.Lookup(channel_id)) {
68 id_map_.Remove(channel_id); 87 id_map_.Remove(channel_id);
69 } 88 }
70 89
71 scoped_ptr<media::cast::CastTransportSender> sender = 90 scoped_ptr<media::cast::CastTransportSender> sender =
72 media::cast::CastTransportSender::Create( 91 media::cast::CastTransportSender::Create(
73 g_browser_process->net_log(), 92 g_browser_process->net_log(),
74 &clock_, 93 &clock_,
75 remote_end_point, 94 remote_end_point,
76 base::Bind(&CastTransportHostFilter::NotifyStatusChange, 95 base::Bind(&CastTransportHostFilter::NotifyStatusChange,
77 base::Unretained(this), 96 weak_factory_.GetWeakPtr(),
78 channel_id), 97 channel_id),
79 base::Bind(&CastTransportHostFilter::RawEvents, 98 base::Bind(&CastTransportHostFilter::SendRawEvents,
80 base::Unretained(this), 99 weak_factory_.GetWeakPtr(),
81 channel_id), 100 channel_id),
82 base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs), 101 base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs),
83 base::MessageLoopProxy::current()); 102 base::MessageLoopProxy::current());
84
85 sender->SetPacketReceiver(base::Bind(&CastTransportHostFilter::ReceivedPacket,
86 base::Unretained(this),
87 channel_id));
88
89 id_map_.AddWithID(sender.release(), channel_id); 103 id_map_.AddWithID(sender.release(), channel_id);
90 } 104 }
91 105
92 void CastTransportHostFilter::OnDelete(int32 channel_id) { 106 void CastTransportHostFilter::OnDelete(int32 channel_id) {
93 media::cast::CastTransportSender* sender = 107 media::cast::CastTransportSender* sender =
94 id_map_.Lookup(channel_id); 108 id_map_.Lookup(channel_id);
95 if (sender) { 109 if (sender) {
96 id_map_.Remove(channel_id); 110 id_map_.Remove(channel_id);
97 } else { 111 } else {
98 DVLOG(1) << "CastTransportHostFilter::Delete called " 112 DVLOG(1) << "CastTransportHostFilter::Delete called "
99 << "on non-existing channel"; 113 << "on non-existing channel";
100 } 114 }
101 } 115 }
102 116
103 void CastTransportHostFilter::OnInitializeAudio( 117 void CastTransportHostFilter::OnInitializeAudio(
104 int32 channel_id, 118 int32 channel_id,
105 const media::cast::CastTransportRtpConfig& config) { 119 const media::cast::CastTransportRtpConfig& config) {
106 media::cast::CastTransportSender* sender = 120 media::cast::CastTransportSender* sender =
107 id_map_.Lookup(channel_id); 121 id_map_.Lookup(channel_id);
108 if (sender) { 122 if (sender) {
109 sender->InitializeAudio(config); 123 sender->InitializeAudio(
124 config,
125 base::Bind(&CastTransportHostFilter::SendCastMessage,
126 weak_factory_.GetWeakPtr(),
127 channel_id, config.ssrc),
128 base::Bind(&CastTransportHostFilter::SendRtt,
129 weak_factory_.GetWeakPtr(),
130 channel_id, config.ssrc));
110 } else { 131 } else {
111 DVLOG(1) 132 DVLOG(1)
112 << "CastTransportHostFilter::OnInitializeAudio on non-existing channel"; 133 << "CastTransportHostFilter::OnInitializeAudio on non-existing channel";
113 } 134 }
114 } 135 }
115 136
116 void CastTransportHostFilter::OnInitializeVideo( 137 void CastTransportHostFilter::OnInitializeVideo(
117 int32 channel_id, 138 int32 channel_id,
118 const media::cast::CastTransportRtpConfig& config) { 139 const media::cast::CastTransportRtpConfig& config) {
119 media::cast::CastTransportSender* sender = 140 media::cast::CastTransportSender* sender =
120 id_map_.Lookup(channel_id); 141 id_map_.Lookup(channel_id);
121 if (sender) { 142 if (sender) {
122 sender->InitializeVideo(config); 143 sender->InitializeVideo(
144 config,
145 base::Bind(&CastTransportHostFilter::SendCastMessage,
146 weak_factory_.GetWeakPtr(),
147 channel_id, config.ssrc),
148 base::Bind(&CastTransportHostFilter::SendRtt,
149 weak_factory_.GetWeakPtr(),
150 channel_id, config.ssrc));
123 } else { 151 } else {
124 DVLOG(1) 152 DVLOG(1)
125 << "CastTransportHostFilter::OnInitializeVideo on non-existing channel"; 153 << "CastTransportHostFilter::OnInitializeVideo on non-existing channel";
126 } 154 }
127 } 155 }
128 156
129 void CastTransportHostFilter::OnInsertCodedAudioFrame( 157 void CastTransportHostFilter::OnInsertCodedAudioFrame(
130 int32 channel_id, 158 int32 channel_id,
131 const media::cast::EncodedFrame& audio_frame) { 159 const media::cast::EncodedFrame& audio_frame) {
132 media::cast::CastTransportSender* sender = 160 media::cast::CastTransportSender* sender =
(...skipping 14 matching lines...) Expand all
147 id_map_.Lookup(channel_id); 175 id_map_.Lookup(channel_id);
148 if (sender) { 176 if (sender) {
149 sender->InsertCodedVideoFrame(video_frame); 177 sender->InsertCodedVideoFrame(video_frame);
150 } else { 178 } else {
151 DVLOG(1) 179 DVLOG(1)
152 << "CastTransportHostFilter::OnInsertCodedVideoFrame " 180 << "CastTransportHostFilter::OnInsertCodedVideoFrame "
153 << "on non-existing channel"; 181 << "on non-existing channel";
154 } 182 }
155 } 183 }
156 184
157 void CastTransportHostFilter::OnSendRtcpFromRtpSender( 185 void CastTransportHostFilter::OnSendSenderReport(
158 int32 channel_id, 186 int32 channel_id,
159 const media::cast::SendRtcpFromRtpSenderData& data, 187 uint32 ssrc,
160 const media::cast::RtcpDlrrReportBlock& dlrr) { 188 base::TimeTicks current_time,
189 uint32 current_time_as_rtp_timestamp) {
161 media::cast::CastTransportSender* sender = 190 media::cast::CastTransportSender* sender =
162 id_map_.Lookup(channel_id); 191 id_map_.Lookup(channel_id);
163 if (sender) { 192 if (sender) {
164 sender->SendRtcpFromRtpSender(data.packet_type_flags, 193 sender->SendSenderReport(ssrc,
165 data.ntp_seconds, 194 current_time,
166 data.ntp_fraction, 195 current_time_as_rtp_timestamp);
167 data.rtp_timestamp,
168 dlrr,
169 data.sending_ssrc,
170 data.c_name);
171 } else { 196 } else {
172 DVLOG(1) 197 DVLOG(1)
173 << "CastTransportHostFilter::OnSendRtcpFromRtpSender " 198 << "CastTransportHostFilter::OnSendSenderReport "
174 << "on non-existing channel"; 199 << "on non-existing channel";
175 } 200 }
176 } 201 }
177 202
178 void CastTransportHostFilter::OnResendPackets( 203 void CastTransportHostFilter::OnResendPackets(
179 int32 channel_id, 204 int32 channel_id,
180 bool is_audio, 205 bool is_audio,
181 const media::cast::MissingFramesAndPacketsMap& missing_packets, 206 const media::cast::MissingFramesAndPacketsMap& missing_packets,
182 bool cancel_rtx_if_not_in_list, 207 bool cancel_rtx_if_not_in_list,
183 base::TimeDelta dedupe_window) { 208 base::TimeDelta dedupe_window) {
184 media::cast::CastTransportSender* sender = 209 media::cast::CastTransportSender* sender =
185 id_map_.Lookup(channel_id); 210 id_map_.Lookup(channel_id);
186 if (sender) { 211 if (sender) {
187 sender->ResendPackets( 212 sender->ResendPackets(
188 is_audio, missing_packets, cancel_rtx_if_not_in_list, dedupe_window); 213 is_audio, missing_packets, cancel_rtx_if_not_in_list, dedupe_window);
189 } else { 214 } else {
190 DVLOG(1) 215 DVLOG(1)
191 << "CastTransportHostFilter::OnResendPackets on non-existing channel"; 216 << "CastTransportHostFilter::OnResendPackets on non-existing channel";
192 } 217 }
193 } 218 }
194 219
195 } // namespace cast 220 } // namespace cast
OLDNEW
« no previous file with comments | « chrome/browser/media/cast_transport_host_filter.h ('k') | chrome/browser/media/cast_transport_host_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698