NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / renderer / media / cast_transport_sender_ipc.cc
blobb3f4bbdab7268130ec85ce1ff024d36ae66ee9a1
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 media::cast::transport::CastTransportConfig& config,
17 const media::cast::transport::CastTransportStatusCallback& status_cb)
18 : status_callback_(status_cb) {
19 if (CastIPCDispatcher::Get()) {
20 channel_id_ = CastIPCDispatcher::Get()->AddSender(this);
22 Send(new CastHostMsg_New(channel_id_, config));
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::transport::PacketReceiverCallback& packet_callback) {
34 packet_callback_ = packet_callback;
37 void CastTransportSenderIPC::InsertCodedAudioFrame(
38 const media::cast::transport::EncodedAudioFrame* audio_frame,
39 const base::TimeTicks& recorded_time) {
40 Send(new CastHostMsg_InsertCodedAudioFrame(channel_id_,
41 *audio_frame,
42 recorded_time));
45 void CastTransportSenderIPC::InsertCodedVideoFrame(
46 const media::cast::transport::EncodedVideoFrame* video_frame,
47 const base::TimeTicks& capture_time) {
48 Send(new CastHostMsg_InsertCodedVideoFrame(channel_id_,
49 *video_frame,
50 capture_time));
53 void CastTransportSenderIPC::SendRtcpFromRtpSender(
54 uint32 packet_type_flags,
55 const media::cast::transport::RtcpSenderInfo& sender_info,
56 const media::cast::transport::RtcpDlrrReportBlock& dlrr,
57 const media::cast::transport::RtcpSenderLogMessage& sender_log,
58 uint32 sending_ssrc,
59 const std::string& c_name) {
60 struct media::cast::transport::SendRtcpFromRtpSenderData data;
61 data.packet_type_flags = packet_type_flags;
62 data.sending_ssrc = sending_ssrc;
63 data.c_name = c_name;
64 Send(new CastHostMsg_SendRtcpFromRtpSender(
65 channel_id_,
66 data,
67 sender_info,
68 dlrr,
69 sender_log));
72 void CastTransportSenderIPC::ResendPackets(
73 bool is_audio,
74 const media::cast::MissingFramesAndPacketsMap& missing_packets) {
75 Send(new CastHostMsg_ResendPackets(channel_id_,
76 is_audio,
77 missing_packets));
80 void CastTransportSenderIPC::SubscribeAudioRtpStatsCallback(
81 const media::cast::transport::CastTransportRtpStatistics& callback) {
82 audio_rtp_callback_ = callback;
85 void CastTransportSenderIPC::SubscribeVideoRtpStatsCallback(
86 const media::cast::transport::CastTransportRtpStatistics& callback) {
87 video_rtp_callback_ = callback;
91 void CastTransportSenderIPC::OnReceivedPacket(
92 const media::cast::Packet& packet) {
93 if (!packet_callback_.is_null()) {
94 // TODO(hubbe): Perhaps an non-ownership-transferring cb here?
95 scoped_ptr<media::cast::transport::Packet> packet_copy(
96 new media::cast::transport::Packet(packet));
97 packet_callback_.Run(packet_copy.Pass());
98 } else {
99 LOG(ERROR) << "CastIPCDispatcher::OnReceivedPacket "
100 << "no packet callback yet.";
104 void CastTransportSenderIPC::OnNotifyStatusChange(
105 media::cast::transport::CastTransportStatus status) {
106 status_callback_.Run(status);
109 void CastTransportSenderIPC::OnRtpStatistics(
110 bool audio,
111 const media::cast::transport::RtcpSenderInfo& sender_info,
112 base::TimeTicks time_sent,
113 uint32 rtp_timestamp) {
114 const media::cast::transport::CastTransportRtpStatistics& callback =
115 audio ? audio_rtp_callback_ : video_rtp_callback_;
116 callback.Run(sender_info, time_sent, rtp_timestamp);
119 void CastTransportSenderIPC::Send(IPC::Message* message) {
120 if (CastIPCDispatcher::Get()) {
121 CastIPCDispatcher::Get()->Send(message);
122 } else {
123 delete message;