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

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

Issue 1515023002: Simplify interface for media/cast: CastTransportSenderImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
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 "base/thread_task_runner_handle.h" 7 #include "base/thread_task_runner_handle.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/common/cast_messages.h" 9 #include "chrome/common/cast_messages.h"
10 #include "components/net_log/chrome_net_log.h" 10 #include "components/net_log/chrome_net_log.h"
11 #include "content/public/browser/power_save_blocker.h" 11 #include "content/public/browser/power_save_blocker.h"
12 #include "media/cast/net/cast_transport_sender.h" 12 #include "media/cast/net/cast_transport_sender.h"
13 13
14 namespace { 14 namespace {
15 15
16 // How often to send raw events. 16 // How often to send raw events.
17 const int kSendRawEventsIntervalSecs = 1; 17 const int kSendRawEventsIntervalSecs = 1;
18 18
19 class TransportClient : public media::cast::CastTransportSender::Client {
20 public:
21 TransportClient(int32_t channel_id,
22 cast::CastTransportHostFilter* cast_transport_host_filter)
23 : channel_id_(channel_id),
24 cast_transport_host_filter_(cast_transport_host_filter) {}
25
26 void OnStatusChanged(media::cast::CastTransportStatus status) final;
27 void OnLoggingEventsReceived(
28 scoped_ptr<std::vector<media::cast::FrameEvent>> frame_events,
29 scoped_ptr<std::vector<media::cast::PacketEvent>> packet_events) final;
30 void OnPacketsReceived(scoped_ptr<media::cast::Packet> packet) final;
31
32 private:
33 const int32_t channel_id_;
34 cast::CastTransportHostFilter* cast_transport_host_filter_;
miu 2016/01/16 02:28:42 nit (add const): cast::CastTransportHostFilter* co
xjz 2016/01/21 19:16:27 Done.
35
36 DISALLOW_COPY_AND_ASSIGN(TransportClient);
37 };
38
39 void TransportClient::OnStatusChanged(media::cast::CastTransportStatus status) {
40 cast_transport_host_filter_->Send(
41 new CastMsg_NotifyStatusChange(channel_id_, status));
19 } 42 }
20 43
44 void TransportClient::OnLoggingEventsReceived(
45 scoped_ptr<std::vector<media::cast::FrameEvent>> frame_events,
46 scoped_ptr<std::vector<media::cast::PacketEvent>> packet_events) {
47 if (frame_events->empty() && packet_events->empty())
48 return;
49 cast_transport_host_filter_->Send(
50 new CastMsg_RawEvents(channel_id_, *packet_events, *frame_events));
51 }
52
53 void TransportClient::OnPacketsReceived(
54 scoped_ptr<media::cast::Packet> packet) {
55 cast_transport_host_filter_->Send(
56 new CastMsg_ReceivedPacket(channel_id_, *packet));
57 }
58
59 } // namespace
60
21 namespace cast { 61 namespace cast {
22 62
23 CastTransportHostFilter::CastTransportHostFilter() 63 CastTransportHostFilter::CastTransportHostFilter()
24 : BrowserMessageFilter(CastMsgStart), 64 : BrowserMessageFilter(CastMsgStart),
25 weak_factory_(this) {} 65 weak_factory_(this) {}
26 66
27 CastTransportHostFilter::~CastTransportHostFilter() {} 67 CastTransportHostFilter::~CastTransportHostFilter() {}
28 68
29 bool CastTransportHostFilter::OnMessageReceived(const IPC::Message& message) { 69 bool CastTransportHostFilter::OnMessageReceived(const IPC::Message& message) {
30 bool handled = true; 70 bool handled = true;
(...skipping 11 matching lines...) Expand all
42 OnCancelSendingFrames) 82 OnCancelSendingFrames)
43 IPC_MESSAGE_HANDLER(CastHostMsg_AddValidSsrc, 83 IPC_MESSAGE_HANDLER(CastHostMsg_AddValidSsrc,
44 OnAddValidSsrc) 84 OnAddValidSsrc)
45 IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpReceiver, 85 IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpReceiver,
46 OnSendRtcpFromRtpReceiver) 86 OnSendRtcpFromRtpReceiver)
47 IPC_MESSAGE_UNHANDLED(handled = false); 87 IPC_MESSAGE_UNHANDLED(handled = false);
48 IPC_END_MESSAGE_MAP(); 88 IPC_END_MESSAGE_MAP();
49 return handled; 89 return handled;
50 } 90 }
51 91
52 void CastTransportHostFilter::ReceivedPacket(
53 int32_t channel_id,
54 scoped_ptr<media::cast::Packet> packet) {
55 Send(new CastMsg_ReceivedPacket(channel_id, *packet));
56 }
57
58 void CastTransportHostFilter::NotifyStatusChange(
59 int32_t channel_id,
60 media::cast::CastTransportStatus status) {
61 Send(new CastMsg_NotifyStatusChange(channel_id, status));
62 }
63
64 void CastTransportHostFilter::SendRawEvents(
65 int32_t channel_id,
66 scoped_ptr<std::vector<media::cast::FrameEvent>> frame_events,
67 scoped_ptr<std::vector<media::cast::PacketEvent>> packet_events) {
68 if (frame_events->empty() && packet_events->empty())
69 return;
70 Send(new CastMsg_RawEvents(channel_id, *packet_events, *frame_events));
71 }
72
73 void CastTransportHostFilter::SendRtt(int32_t channel_id, 92 void CastTransportHostFilter::SendRtt(int32_t channel_id,
74 uint32_t ssrc, 93 uint32_t ssrc,
75 base::TimeDelta rtt) { 94 base::TimeDelta rtt) {
76 Send(new CastMsg_Rtt(channel_id, ssrc, rtt)); 95 Send(new CastMsg_Rtt(channel_id, ssrc, rtt));
77 } 96 }
78 97
79 void CastTransportHostFilter::SendCastMessage( 98 void CastTransportHostFilter::SendCastMessage(
80 int32_t channel_id, 99 int32_t channel_id,
81 uint32_t ssrc, 100 uint32_t ssrc,
82 const media::cast::RtcpCastMessage& cast_message) { 101 const media::cast::RtcpCastMessage& cast_message) {
(...skipping 10 matching lines...) Expand all
93 power_save_blocker_ = content::PowerSaveBlocker::Create( 112 power_save_blocker_ = content::PowerSaveBlocker::Create(
94 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, 113 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
95 content::PowerSaveBlocker::kReasonOther, 114 content::PowerSaveBlocker::kReasonOther,
96 "Cast is streaming content to a remote receiver"); 115 "Cast is streaming content to a remote receiver");
97 } 116 }
98 117
99 if (id_map_.Lookup(channel_id)) { 118 if (id_map_.Lookup(channel_id)) {
100 id_map_.Remove(channel_id); 119 id_map_.Remove(channel_id);
101 } 120 }
102 121
122 media::cast::CastTransportSender::UdpTransportParams udp_transport_params(
123 g_browser_process->net_log(), local_end_point, remote_end_point);
103 scoped_ptr<media::cast::CastTransportSender> sender = 124 scoped_ptr<media::cast::CastTransportSender> sender =
104 media::cast::CastTransportSender::Create( 125 media::cast::CastTransportSender::Create(
105 g_browser_process->net_log(), 126 &clock_, udp_transport_params,
106 &clock_, 127 base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs),
107 local_end_point,
108 remote_end_point,
109 make_scoped_ptr(options.DeepCopy()), 128 make_scoped_ptr(options.DeepCopy()),
110 base::Bind(&CastTransportHostFilter::NotifyStatusChange, 129 make_scoped_ptr(new TransportClient(channel_id, this)),
111 weak_factory_.GetWeakPtr(),
112 channel_id),
113 base::Bind(&CastTransportHostFilter::SendRawEvents,
114 weak_factory_.GetWeakPtr(),
115 channel_id),
116 base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs),
117 base::Bind(&CastTransportHostFilter::ReceivedPacket,
118 weak_factory_.GetWeakPtr(),
119 channel_id),
120 base::ThreadTaskRunnerHandle::Get()); 130 base::ThreadTaskRunnerHandle::Get());
121 id_map_.AddWithID(sender.release(), channel_id); 131 id_map_.AddWithID(sender.release(), channel_id);
122 } 132 }
123 133
124 void CastTransportHostFilter::OnDelete(int32_t channel_id) { 134 void CastTransportHostFilter::OnDelete(int32_t channel_id) {
125 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); 135 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id);
126 if (sender) { 136 if (sender) {
127 id_map_.Remove(channel_id); 137 id_map_.Remove(channel_id);
128 } else { 138 } else {
129 DVLOG(1) << "CastTransportHostFilter::Delete called " 139 DVLOG(1) << "CastTransportHostFilter::Delete called "
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 params.rtp_receiver_statistics.get()); 269 params.rtp_receiver_statistics.get());
260 } else { 270 } else {
261 DVLOG(1) 271 DVLOG(1)
262 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver " 272 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver "
263 << "on non-existing channel"; 273 << "on non-existing channel";
264 } 274 }
265 } 275 }
266 276
267 277
268 } // namespace cast 278 } // namespace cast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698