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

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, 10 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 ProcessRtpPacket(scoped_ptr<media::cast::Packet> packet) final;
31
32 private:
33 const int32_t channel_id_;
34 cast::CastTransportHostFilter* const cast_transport_host_filter_;
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::ProcessRtpPacket(scoped_ptr<media::cast::Packet> packet) {
54 cast_transport_host_filter_->Send(
55 new CastMsg_ReceivedPacket(channel_id_, *packet));
56 }
57
58 } // namespace
59
21 namespace cast { 60 namespace cast {
22 61
23 CastTransportHostFilter::CastTransportHostFilter() 62 CastTransportHostFilter::CastTransportHostFilter()
24 : BrowserMessageFilter(CastMsgStart), 63 : BrowserMessageFilter(CastMsgStart),
25 weak_factory_(this) {} 64 weak_factory_(this) {}
26 65
27 CastTransportHostFilter::~CastTransportHostFilter() {} 66 CastTransportHostFilter::~CastTransportHostFilter() {}
28 67
68 void CastTransportHostFilter::OnStatusChanged(
69 int32_t channel_id,
70 media::cast::CastTransportStatus status) {
71 Send(new CastMsg_NotifyStatusChange(channel_id, status));
72 }
73
29 bool CastTransportHostFilter::OnMessageReceived(const IPC::Message& message) { 74 bool CastTransportHostFilter::OnMessageReceived(const IPC::Message& message) {
30 bool handled = true; 75 bool handled = true;
31 IPC_BEGIN_MESSAGE_MAP(CastTransportHostFilter, message) 76 IPC_BEGIN_MESSAGE_MAP(CastTransportHostFilter, message)
32 IPC_MESSAGE_HANDLER(CastHostMsg_New, OnNew) 77 IPC_MESSAGE_HANDLER(CastHostMsg_New, OnNew)
33 IPC_MESSAGE_HANDLER(CastHostMsg_Delete, OnDelete) 78 IPC_MESSAGE_HANDLER(CastHostMsg_Delete, OnDelete)
34 IPC_MESSAGE_HANDLER(CastHostMsg_InitializeAudio, OnInitializeAudio) 79 IPC_MESSAGE_HANDLER(CastHostMsg_InitializeAudio, OnInitializeAudio)
35 IPC_MESSAGE_HANDLER(CastHostMsg_InitializeVideo, OnInitializeVideo) 80 IPC_MESSAGE_HANDLER(CastHostMsg_InitializeVideo, OnInitializeVideo)
36 IPC_MESSAGE_HANDLER(CastHostMsg_InsertFrame, OnInsertFrame) 81 IPC_MESSAGE_HANDLER(CastHostMsg_InsertFrame, OnInsertFrame)
37 IPC_MESSAGE_HANDLER(CastHostMsg_SendSenderReport, 82 IPC_MESSAGE_HANDLER(CastHostMsg_SendSenderReport,
38 OnSendSenderReport) 83 OnSendSenderReport)
39 IPC_MESSAGE_HANDLER(CastHostMsg_ResendFrameForKickstart, 84 IPC_MESSAGE_HANDLER(CastHostMsg_ResendFrameForKickstart,
40 OnResendFrameForKickstart) 85 OnResendFrameForKickstart)
41 IPC_MESSAGE_HANDLER(CastHostMsg_CancelSendingFrames, 86 IPC_MESSAGE_HANDLER(CastHostMsg_CancelSendingFrames,
42 OnCancelSendingFrames) 87 OnCancelSendingFrames)
43 IPC_MESSAGE_HANDLER(CastHostMsg_AddValidSsrc, 88 IPC_MESSAGE_HANDLER(CastHostMsg_AddValidSsrc,
44 OnAddValidSsrc) 89 OnAddValidSsrc)
45 IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpReceiver, 90 IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpReceiver,
46 OnSendRtcpFromRtpReceiver) 91 OnSendRtcpFromRtpReceiver)
47 IPC_MESSAGE_UNHANDLED(handled = false) 92 IPC_MESSAGE_UNHANDLED(handled = false)
48 IPC_END_MESSAGE_MAP() 93 IPC_END_MESSAGE_MAP()
49 return handled; 94 return handled;
50 } 95 }
51 96
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, 97 void CastTransportHostFilter::SendRtt(int32_t channel_id,
74 uint32_t ssrc, 98 uint32_t ssrc,
75 base::TimeDelta rtt) { 99 base::TimeDelta rtt) {
76 Send(new CastMsg_Rtt(channel_id, ssrc, rtt)); 100 Send(new CastMsg_Rtt(channel_id, ssrc, rtt));
77 } 101 }
78 102
79 void CastTransportHostFilter::SendCastMessage( 103 void CastTransportHostFilter::SendCastMessage(
80 int32_t channel_id, 104 int32_t channel_id,
81 uint32_t ssrc, 105 uint32_t ssrc,
82 const media::cast::RtcpCastMessage& cast_message) { 106 const media::cast::RtcpCastMessage& cast_message) {
(...skipping 10 matching lines...) Expand all
93 power_save_blocker_ = content::PowerSaveBlocker::Create( 117 power_save_blocker_ = content::PowerSaveBlocker::Create(
94 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, 118 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
95 content::PowerSaveBlocker::kReasonOther, 119 content::PowerSaveBlocker::kReasonOther,
96 "Cast is streaming content to a remote receiver"); 120 "Cast is streaming content to a remote receiver");
97 } 121 }
98 122
99 if (id_map_.Lookup(channel_id)) { 123 if (id_map_.Lookup(channel_id)) {
100 id_map_.Remove(channel_id); 124 id_map_.Remove(channel_id);
101 } 125 }
102 126
127 scoped_ptr<media::cast::UdpTransport> udp_transport(
128 new media::cast::UdpTransport(
129 g_browser_process->net_log(), base::ThreadTaskRunnerHandle::Get(),
130 local_end_point, remote_end_point,
131 base::Bind(&CastTransportHostFilter::OnStatusChanged,
132 weak_factory_.GetWeakPtr(), channel_id)));
133 udp_transport->SetUdpOptions(options);
103 scoped_ptr<media::cast::CastTransportSender> sender = 134 scoped_ptr<media::cast::CastTransportSender> sender =
104 media::cast::CastTransportSender::Create( 135 media::cast::CastTransportSender::Create(
105 g_browser_process->net_log(), 136 &clock_, base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs),
106 &clock_, 137 make_scoped_ptr(new TransportClient(channel_id, this)),
107 local_end_point, 138 std::move(udp_transport), base::ThreadTaskRunnerHandle::Get());
108 remote_end_point, 139 sender->SetOptions(options);
109 make_scoped_ptr(options.DeepCopy()),
110 base::Bind(&CastTransportHostFilter::NotifyStatusChange,
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());
121 id_map_.AddWithID(sender.release(), channel_id); 140 id_map_.AddWithID(sender.release(), channel_id);
122 } 141 }
123 142
124 void CastTransportHostFilter::OnDelete(int32_t channel_id) { 143 void CastTransportHostFilter::OnDelete(int32_t channel_id) {
125 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); 144 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id);
126 if (sender) { 145 if (sender) {
127 id_map_.Remove(channel_id); 146 id_map_.Remove(channel_id);
128 } else { 147 } else {
129 DVLOG(1) << "CastTransportHostFilter::Delete called " 148 DVLOG(1) << "CastTransportHostFilter::Delete called "
130 << "on non-existing channel"; 149 << "on non-existing channel";
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 params.target_delay, 276 params.target_delay,
258 params.rtcp_events.get(), 277 params.rtcp_events.get(),
259 params.rtp_receiver_statistics.get()); 278 params.rtp_receiver_statistics.get());
260 } else { 279 } else {
261 DVLOG(1) 280 DVLOG(1)
262 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver " 281 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver "
263 << "on non-existing channel"; 282 << "on non-existing channel";
264 } 283 }
265 } 284 }
266 285
267
268 } // namespace cast 286 } // namespace cast
OLDNEW
« no previous file with comments | « chrome/browser/media/cast_transport_host_filter.h ('k') | chrome/renderer/media/cast_transport_sender_ipc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698