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

Unified Diff: chrome/renderer/media/cast_transport_sender_ipc.cc

Issue 138753004: Cast: IPC glue between cast library transport and encoders. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more tests Created 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/media/cast_transport_sender_ipc.cc
diff --git a/chrome/renderer/media/cast_transport_sender_ipc.cc b/chrome/renderer/media/cast_transport_sender_ipc.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2f33a95db66b3c621e9a9124296c3794ef4a244b
--- /dev/null
+++ b/chrome/renderer/media/cast_transport_sender_ipc.cc
@@ -0,0 +1,178 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/renderer/media/cast_transport_sender_ipc.h"
+
+namespace cast {
+
+CastIPCDispatcher* CastIPCDispatcher::global_instance_ = NULL;
+
+CastIPCDispatcher::CastIPCDispatcher(
+ const scoped_refptr<base::MessageLoopProxy>& io_message_loop)
+ : channel_(NULL),
+ io_message_loop_(io_message_loop) {
+ DCHECK(!global_instance_);
+ global_instance_ = this;
+}
+
+CastIPCDispatcher::~CastIPCDispatcher() {
+ global_instance_ = NULL;
+}
+
+bool CastIPCDispatcher::OnMessageReceived(const IPC::Message& message) {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ bool handled = true;
+ bool msg_is_good = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(CastIPCDispatcher, message, msg_is_good)
+ IPC_MESSAGE_HANDLER(CastMsg_ReceivedPacket, OnReceivedPacket)
+ IPC_MESSAGE_HANDLER(CastMsg_NotifyStatusChange, OnNotifyStatusChange)
+ IPC_MESSAGE_UNHANDLED(handled = false);
+ IPC_END_MESSAGE_MAP_EX();
+ if (!msg_is_good) {
+ LOG(ERROR) << "Failed to parse incoming message.";
+ }
+ return handled;
+}
+
+void CastIPCDispatcher::OnFilterAdded(IPC::Channel* channel) {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ channel_ = channel;
+}
+
+void CastIPCDispatcher::OnFilterRemoved() {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ channel_ = NULL;
+}
+
+void CastIPCDispatcher::OnChannelClosing() {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ channel_ = NULL;
+}
+
+
+void CastIPCDispatcher::OnReceivedPacket(
+ int32 channel_id,
+ const media::cast::transport::Packet& packet) {
+ CastTransportSenderIPC* ptr = id_map_.Lookup(channel_id);
+ if (ptr) {
+ if (!ptr->packet_callback_.is_null()) {
+ // TODO(hubbe): Perhaps an non-ownership-transferring cb would be better?
+ scoped_ptr<media::cast::transport::Packet> packet_copy(
+ new media::cast::transport::Packet(packet));
+ ptr->packet_callback_.Run(packet_copy.Pass());
+ } else {
+ LOG(ERROR) << "CastIPCDispatcher::OnReceivedPacket "
+ << "no packet callback yet.";
+ }
+ } else {
+ LOG(ERROR) << "CastIPCDispatcher::OnReceivedPacket "
+ << "on non-existing channel.";
+ }
+}
+
+void CastIPCDispatcher::OnNotifyStatusChange(
+ int32 channel_id,
+ media::cast::transport::CastTransportStatus status) {
+ CastTransportSenderIPC* ptr = id_map_.Lookup(channel_id);
+ if (ptr) {
+ ptr->status_callback_.Run(status);
+ } else {
+ LOG(ERROR)
+ << "CastIPCDispatcher::OnNotifystatusChange on non-existing channel.";
+ }
+}
+
+CastTransportSenderIPC::CastTransportSenderIPC(
+ const media::cast::transport::CastTransportConfig& config,
+ const media::cast::transport::CastTransportStatusCallback& status_cb)
+ : status_callback_(status_cb) {
+ channel_id_ = CastIPCDispatcher::global_instance_->id_map_.Add(this);
+ Send(new CastHostMsg_New(channel_id_, config));
+}
+
+CastTransportSenderIPC::~CastTransportSenderIPC() {
+ Send(new CastHostMsg_Delete(channel_id_));
+ if (CastIPCDispatcher::global_instance_) {
+ CastIPCDispatcher::global_instance_->id_map_.Remove(channel_id_);
+ }
+}
+
+bool CastTransportSenderIPC::Send(IPC::Message *message) {
+ if (CastIPCDispatcher::global_instance_ &&
+ CastIPCDispatcher::global_instance_->channel_) {
+ DCHECK(CastIPCDispatcher::global_instance_->io_message_loop_->
+ BelongsToCurrentThread());
+ return CastIPCDispatcher::global_instance_->channel_->Send(message);
+ } else {
+ // TODO(Hubbe): Notify caller that send failed and close channel.
+ delete message;
+ return false;
+ }
+}
+
+void CastTransportSenderIPC::SetPacketReceiver(
+ const media::cast::transport::PacketReceiverCallback& packet_callback) {
+ packet_callback_ = packet_callback;
+}
+
+void CastTransportSenderIPC::InsertCodedAudioFrame(
+ const media::cast::transport::EncodedAudioFrame* audio_frame,
+ const base::TimeTicks& recorded_time) {
+ Send(new CastHostMsg_InsertCodedAudioFrame(channel_id_,
+ *audio_frame,
+ recorded_time));
+}
+
+void CastTransportSenderIPC::InsertCodedVideoFrame(
+ const media::cast::transport::EncodedVideoFrame* video_frame,
+ const base::TimeTicks& capture_time) {
+ Send(new CastHostMsg_InsertCodedVideoFrame(channel_id_,
+ *video_frame,
+ capture_time));
+}
+
+void CastTransportSenderIPC::SendRtcpFromRtpSender(
+ uint32 packet_type_flags,
+ const media::cast::transport::RtcpSenderInfo& sender_info,
+ const media::cast::transport::RtcpDlrrReportBlock& dlrr,
+ const media::cast::transport::RtcpSenderLogMessage& sender_log,
+ uint32 sending_ssrc,
+ const std::string& c_name) {
+ struct media::cast::transport::SendRtcpFromRtpSenderData data;
+ data.packet_type_flags = packet_type_flags;
+ data.sending_ssrc = sending_ssrc;
+ data.c_name = data.c_name;
+ Send(new CastHostMsg_SendRtcpFromRtpSender(
+ channel_id_,
+ data,
+ sender_info,
+ dlrr,
+ sender_log));
+}
+
+void CastTransportSenderIPC::ResendPackets(
+ bool is_audio,
+ const media::cast::MissingFramesAndPacketsMap& missing_packets) {
+ Send(new CastHostMsg_ResendPackets(channel_id_,
+ is_audio,
+ missing_packets));
+}
+
+void CastTransportSenderIPC::RtpAudioStatistics(
+ const base::TimeTicks& now,
+ media::cast::transport::RtcpSenderInfo* sender_info) {
+ // TODO(hubbe): Not yet implemented
+}
+
+// Retrieves video RTP statistics.
+void CastTransportSenderIPC::RtpVideoStatistics(
+ const base::TimeTicks& now,
+ media::cast::transport::RtcpSenderInfo* sender_info) {
+ // TODO(hubbe): Not yet implemented
+}
+
+
+
+
+} // namespace cast

Powered by Google App Engine
This is Rietveld 408576698