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"
13 #include "media/cast/transport/cast_transport_sender.h"
15 CastTransportSenderIPC::CastTransportSenderIPC(
16 const net::IPEndPoint
& remote_end_point
,
17 const media::cast::transport::CastTransportStatusCallback
& status_cb
,
18 const media::cast::transport::BulkRawEventsCallback
& raw_events_cb
)
19 : status_callback_(status_cb
), raw_events_callback_(raw_events_cb
) {
20 if (CastIPCDispatcher::Get()) {
21 channel_id_
= CastIPCDispatcher::Get()->AddSender(this);
23 Send(new CastHostMsg_New(channel_id_
, remote_end_point
));
26 CastTransportSenderIPC::~CastTransportSenderIPC() {
27 Send(new CastHostMsg_Delete(channel_id_
));
28 if (CastIPCDispatcher::Get()) {
29 CastIPCDispatcher::Get()->RemoveSender(channel_id_
);
33 void CastTransportSenderIPC::SetPacketReceiver(
34 const media::cast::transport::PacketReceiverCallback
& packet_callback
) {
35 packet_callback_
= packet_callback
;
38 void CastTransportSenderIPC::InitializeAudio(
39 const media::cast::transport::CastTransportAudioConfig
& config
) {
40 Send(new CastHostMsg_InitializeAudio(channel_id_
, config
));
43 void CastTransportSenderIPC::InitializeVideo(
44 const media::cast::transport::CastTransportVideoConfig
& config
) {
45 Send(new CastHostMsg_InitializeVideo(channel_id_
, config
));
48 void CastTransportSenderIPC::InsertCodedAudioFrame(
49 const media::cast::transport::EncodedAudioFrame
* audio_frame
,
50 const base::TimeTicks
& recorded_time
) {
51 Send(new CastHostMsg_InsertCodedAudioFrame(channel_id_
,
56 void CastTransportSenderIPC::InsertCodedVideoFrame(
57 const media::cast::transport::EncodedVideoFrame
* video_frame
,
58 const base::TimeTicks
& capture_time
) {
59 Send(new CastHostMsg_InsertCodedVideoFrame(channel_id_
,
64 void CastTransportSenderIPC::SendRtcpFromRtpSender(
65 uint32 packet_type_flags
,
66 const media::cast::transport::RtcpSenderInfo
& sender_info
,
67 const media::cast::transport::RtcpDlrrReportBlock
& dlrr
,
68 const media::cast::transport::RtcpSenderLogMessage
& sender_log
,
70 const std::string
& c_name
) {
71 struct media::cast::transport::SendRtcpFromRtpSenderData data
;
72 data
.packet_type_flags
= packet_type_flags
;
73 data
.sending_ssrc
= sending_ssrc
;
75 Send(new CastHostMsg_SendRtcpFromRtpSender(
83 void CastTransportSenderIPC::ResendPackets(
85 const media::cast::MissingFramesAndPacketsMap
& missing_packets
) {
86 Send(new CastHostMsg_ResendPackets(channel_id_
,
91 void CastTransportSenderIPC::SubscribeAudioRtpStatsCallback(
92 const media::cast::transport::CastTransportRtpStatistics
& callback
) {
93 audio_rtp_callback_
= callback
;
96 void CastTransportSenderIPC::SubscribeVideoRtpStatsCallback(
97 const media::cast::transport::CastTransportRtpStatistics
& callback
) {
98 video_rtp_callback_
= callback
;
102 void CastTransportSenderIPC::OnReceivedPacket(
103 const media::cast::Packet
& packet
) {
104 if (!packet_callback_
.is_null()) {
105 // TODO(hubbe): Perhaps an non-ownership-transferring cb here?
106 scoped_ptr
<media::cast::transport::Packet
> packet_copy(
107 new media::cast::transport::Packet(packet
));
108 packet_callback_
.Run(packet_copy
.Pass());
110 DVLOG(1) << "CastIPCDispatcher::OnReceivedPacket no packet callback yet.";
114 void CastTransportSenderIPC::OnNotifyStatusChange(
115 media::cast::transport::CastTransportStatus status
) {
116 status_callback_
.Run(status
);
119 void CastTransportSenderIPC::OnRtpStatistics(
121 const media::cast::transport::RtcpSenderInfo
& sender_info
,
122 base::TimeTicks time_sent
,
123 uint32 rtp_timestamp
) {
124 const media::cast::transport::CastTransportRtpStatistics
& callback
=
125 audio
? audio_rtp_callback_
: video_rtp_callback_
;
126 callback
.Run(sender_info
, time_sent
, rtp_timestamp
);
129 void CastTransportSenderIPC::OnRawEvents(
130 const std::vector
<media::cast::PacketEvent
>& packet_events
) {
131 raw_events_callback_
.Run(packet_events
);
134 void CastTransportSenderIPC::Send(IPC::Message
* message
) {
135 if (CastIPCDispatcher::Get()) {
136 CastIPCDispatcher::Get()->Send(message
);