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
3 // found in the LICENSE file.
5 #include "chrome/browser/media/cast_transport_host_filter.h"
6 #include "media/cast/transport/cast_transport_sender.h"
10 CastTransportHostFilter::CastTransportHostFilter() {
13 CastTransportHostFilter::~CastTransportHostFilter() {
16 bool CastTransportHostFilter::OnMessageReceived(const IPC::Message& message,
17 bool* message_was_ok) {
19 IPC_BEGIN_MESSAGE_MAP_EX(CastTransportHostFilter, message, *message_was_ok)
20 IPC_MESSAGE_HANDLER(CastHostMsg_New, OnNew)
21 IPC_MESSAGE_HANDLER(CastHostMsg_Delete, OnDelete)
22 IPC_MESSAGE_HANDLER(CastHostMsg_InsertCodedAudioFrame,
23 OnInsertCodedAudioFrame)
24 IPC_MESSAGE_HANDLER(CastHostMsg_InsertCodedVideoFrame,
25 OnInsertCodedVideoFrame)
26 IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpSender,
27 OnSendRtcpFromRtpSender);
28 IPC_MESSAGE_HANDLER(CastHostMsg_ResendPackets,
30 IPC_MESSAGE_UNHANDLED(handled = false);
31 IPC_END_MESSAGE_MAP_EX();
35 void CastTransportHostFilter::NotifyStatusChange(
37 media::cast::transport::CastTransportStatus status) {
38 Send(new CastMsg_NotifyStatusChange(channel_id, status));
41 void CastTransportHostFilter::ReceivedPacket(
43 scoped_ptr<media::cast::transport::Packet> packet) {
44 Send(new CastMsg_ReceivedPacket(channel_id, *packet));
47 void CastTransportHostFilter::ReceivedRtpStatistics(
50 const media::cast::transport::RtcpSenderInfo& sender_info,
51 base::TimeTicks time_sent,
52 uint32 rtp_timestamp) {
53 Send(new CastMsg_RtpStatistics(channel_id,
60 void CastTransportHostFilter::OnNew(
62 const media::cast::transport::CastTransportConfig& config) {
63 media::cast::transport::CastTransportSender* sender =
64 id_map_.Lookup(channel_id);
66 id_map_.Remove(channel_id);
69 sender = media::cast::transport::CastTransportSender::
70 CreateCastTransportSender(
73 base::Bind(&CastTransportHostFilter::NotifyStatusChange,
74 base::Unretained(this),
76 base::MessageLoopProxy::current());
77 sender->SetPacketReceiver(
78 base::Bind(&CastTransportHostFilter::ReceivedPacket,
79 base::Unretained(this),
81 sender->SubscribeAudioRtpStatsCallback(
82 base::Bind(&CastTransportHostFilter::ReceivedRtpStatistics,
83 base::Unretained(this),
86 sender->SubscribeVideoRtpStatsCallback(
87 base::Bind(&CastTransportHostFilter::ReceivedRtpStatistics,
88 base::Unretained(this),
90 false /* not audio */));
92 id_map_.AddWithID(sender, channel_id);
95 void CastTransportHostFilter::OnDelete(int32 channel_id) {
96 media::cast::transport::CastTransportSender* sender =
97 id_map_.Lookup(channel_id);
99 id_map_.Remove(channel_id);
101 DVLOG(1) << "CastTransportHostFilter::Delete called "
102 << "on non-existing channel";
106 void CastTransportHostFilter::OnInsertCodedAudioFrame(
108 const media::cast::transport::EncodedAudioFrame& audio_frame,
109 base::TimeTicks recorded_time) {
110 media::cast::transport::CastTransportSender* sender =
111 id_map_.Lookup(channel_id);
113 sender->InsertCodedAudioFrame(&audio_frame, recorded_time);
116 << "CastTransportHostFilter::OnInsertCodedAudioFrame "
117 << "on non-existing channel";
121 void CastTransportHostFilter::OnInsertCodedVideoFrame(
123 const media::cast::transport::EncodedVideoFrame& video_frame,
124 base::TimeTicks capture_time) {
125 media::cast::transport::CastTransportSender* sender =
126 id_map_.Lookup(channel_id);
128 sender->InsertCodedVideoFrame(&video_frame, capture_time);
131 << "CastTransportHostFilter::OnInsertCodedVideoFrame "
132 << "on non-existing channel";
136 void CastTransportHostFilter::OnSendRtcpFromRtpSender(
138 const media::cast::transport::SendRtcpFromRtpSenderData& data,
139 const media::cast::transport::RtcpSenderInfo& sender_info,
140 const media::cast::transport::RtcpDlrrReportBlock& dlrr,
141 const media::cast::transport::RtcpSenderLogMessage& sender_log) {
142 media::cast::transport::CastTransportSender* sender =
143 id_map_.Lookup(channel_id);
145 sender->SendRtcpFromRtpSender(data.packet_type_flags,
153 << "CastTransportHostFilter::OnSendRtcpFromRtpSender "
154 << "on non-existing channel";
158 void CastTransportHostFilter::OnResendPackets(
161 const media::cast::MissingFramesAndPacketsMap& missing_packets) {
162 media::cast::transport::CastTransportSender* sender =
163 id_map_.Lookup(channel_id);
165 sender->ResendPackets(is_audio, missing_packets);
168 << "CastTransportHostFilter::OnResendPackets on non-existing channel";