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/renderer/media/cast_transport_sender_ipc.h"
7 #include "base/callback.h"
8 #include "base/id_map.h"
9 #include "chrome/common/cast_messages.h"
10 #include "chrome/renderer/media/cast_ipc_dispatcher.h"
11 #include "ipc/ipc_channel_proxy.h"
12 #include "media/cast/cast_sender.h"
14 CastTransportSenderIPC::CastTransportSenderIPC(
15 const net::IPEndPoint
& remote_end_point
,
16 const media::cast::CastTransportStatusCallback
& status_cb
,
17 const media::cast::BulkRawEventsCallback
& raw_events_cb
)
18 : status_callback_(status_cb
), raw_events_callback_(raw_events_cb
) {
19 if (CastIPCDispatcher::Get()) {
20 channel_id_
= CastIPCDispatcher::Get()->AddSender(this);
22 Send(new CastHostMsg_New(channel_id_
, remote_end_point
));
25 CastTransportSenderIPC::~CastTransportSenderIPC() {
26 Send(new CastHostMsg_Delete(channel_id_
));
27 if (CastIPCDispatcher::Get()) {
28 CastIPCDispatcher::Get()->RemoveSender(channel_id_
);
32 void CastTransportSenderIPC::SetPacketReceiver(
33 const media::cast::PacketReceiverCallback
& packet_callback
) {
34 packet_callback_
= packet_callback
;
37 void CastTransportSenderIPC::InitializeAudio(
38 const media::cast::CastTransportRtpConfig
& config
) {
39 Send(new CastHostMsg_InitializeAudio(channel_id_
, config
));
42 void CastTransportSenderIPC::InitializeVideo(
43 const media::cast::CastTransportRtpConfig
& config
) {
44 Send(new CastHostMsg_InitializeVideo(channel_id_
, config
));
47 void CastTransportSenderIPC::InsertCodedAudioFrame(
48 const media::cast::EncodedFrame
& audio_frame
) {
49 Send(new CastHostMsg_InsertCodedAudioFrame(channel_id_
, audio_frame
));
52 void CastTransportSenderIPC::InsertCodedVideoFrame(
53 const media::cast::EncodedFrame
& video_frame
) {
54 Send(new CastHostMsg_InsertCodedVideoFrame(channel_id_
, video_frame
));
57 void CastTransportSenderIPC::SendRtcpFromRtpSender(
58 uint32 packet_type_flags
,
62 const media::cast::RtcpDlrrReportBlock
& dlrr
,
64 const std::string
& c_name
) {
65 struct media::cast::SendRtcpFromRtpSenderData data
;
66 data
.packet_type_flags
= packet_type_flags
;
67 data
.sending_ssrc
= sending_ssrc
;
69 data
.ntp_seconds
= ntp_seconds
;
70 data
.ntp_fraction
= ntp_fraction
;
71 data
.rtp_timestamp
= rtp_timestamp
;
72 Send(new CastHostMsg_SendRtcpFromRtpSender(
78 void CastTransportSenderIPC::ResendPackets(
80 const media::cast::MissingFramesAndPacketsMap
& missing_packets
,
81 bool cancel_rtx_if_not_in_list
,
82 base::TimeDelta dedupe_window
) {
83 Send(new CastHostMsg_ResendPackets(channel_id_
,
86 cancel_rtx_if_not_in_list
,
90 void CastTransportSenderIPC::OnReceivedPacket(
91 const media::cast::Packet
& packet
) {
92 if (!packet_callback_
.is_null()) {
93 // TODO(hubbe): Perhaps an non-ownership-transferring cb here?
94 scoped_ptr
<media::cast::Packet
> packet_copy(
95 new media::cast::Packet(packet
));
96 packet_callback_
.Run(packet_copy
.Pass());
98 DVLOG(1) << "CastIPCDispatcher::OnReceivedPacket no packet callback yet.";
102 void CastTransportSenderIPC::OnNotifyStatusChange(
103 media::cast::CastTransportStatus status
) {
104 status_callback_
.Run(status
);
107 void CastTransportSenderIPC::OnRawEvents(
108 const std::vector
<media::cast::PacketEvent
>& packet_events
) {
109 raw_events_callback_
.Run(packet_events
);
112 void CastTransportSenderIPC::Send(IPC::Message
* message
) {
113 if (CastIPCDispatcher::Get()) {
114 CastIPCDispatcher::Get()->Send(message
);