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

Unified Diff: chrome/renderer/media/cast_ipc_dispatcher.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: fixed threading issues, fixed an asan bug in cast library, fixed 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
« no previous file with comments | « chrome/renderer/media/cast_ipc_dispatcher.h ('k') | chrome/renderer/media/cast_session.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/media/cast_ipc_dispatcher.cc
diff --git a/chrome/renderer/media/cast_ipc_dispatcher.cc b/chrome/renderer/media/cast_ipc_dispatcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..514ee5a040f2ba78ffcdc6f4dd8184fb404a0ceb
--- /dev/null
+++ b/chrome/renderer/media/cast_ipc_dispatcher.cc
@@ -0,0 +1,123 @@
+// Copyright 2014 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_ipc_dispatcher.h"
+
+#include "chrome/common/cast_messages.h"
+#include "chrome/renderer/media/cast_transport_sender_ipc.h"
+#include "ipc/ipc_message_macros.h"
+
+CastIPCDispatcher* CastIPCDispatcher::global_instance_ = NULL;
+
+CastIPCDispatcher::CastIPCDispatcher(
+ const scoped_refptr<base::MessageLoopProxy>& io_message_loop)
+ : channel_(NULL),
+ io_message_loop_(io_message_loop) {
+ DCHECK(io_message_loop_);
+ DCHECK(!global_instance_);
+}
+
+CastIPCDispatcher::~CastIPCDispatcher() {
+ if (io_message_loop_->BelongsToCurrentThread()) {
+ // Option 1: Last reference was freed from the IO thread, no problem.
+ global_instance_ = NULL;
+ } else {
+ // Option 2: Something went wrong before we got added as a filter, and
acolwell GONE FROM CHROMIUM 2014/02/14 20:45:20 How are we supposed to hit this case? The pointer
hubbe 2014/02/14 20:58:06 Actually, the more I think about it, the more I th
+ // the last reference was freed from some other thread.
+ DCHECK(!global_instance_);
+ global_instance_ = NULL;
acolwell GONE FROM CHROMIUM 2014/02/14 20:45:20 This still global pointer business still feels wro
hubbe 2014/02/14 20:58:06 I can do that, but I'm not sure that solves anythi
+ }
+}
+
+CastIPCDispatcher* CastIPCDispatcher::Get() {
+ return global_instance_;
+}
+
+void CastIPCDispatcher::Send(IPC::Message* message) {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ if (channel_) {
+ channel_->Send(message);
+ } else {
+ delete message;
+ }
+}
+
+int32 CastIPCDispatcher::AddSender(CastTransportSenderIPC* sender) {
+ return id_map_.Add(sender);
+}
+
+void CastIPCDispatcher::RemoveSender(int32 channel_id) {
+ return id_map_.Remove(channel_id);
+}
+
+bool CastIPCDispatcher::OnMessageReceived(const IPC::Message& message) {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(CastIPCDispatcher, message)
+ IPC_MESSAGE_HANDLER(CastMsg_ReceivedPacket, OnReceivedPacket)
+ IPC_MESSAGE_HANDLER(CastMsg_NotifyStatusChange, OnNotifyStatusChange)
+ IPC_MESSAGE_HANDLER(CastMsg_RtpStatistics, OnRtpStatistics)
+ IPC_MESSAGE_UNHANDLED(handled = false);
+ IPC_END_MESSAGE_MAP();
+ return handled;
+}
+
+void CastIPCDispatcher::OnFilterAdded(IPC::Channel* channel) {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ DCHECK(!global_instance_);
+ global_instance_ = this;
+ channel_ = channel;
+}
+
+void CastIPCDispatcher::OnFilterRemoved() {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ DCHECK_EQ(this, global_instance_);
+ global_instance_ = NULL;
+ channel_ = NULL;
+}
+
+void CastIPCDispatcher::OnChannelClosing() {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ DCHECK_EQ(this, global_instance_);
+ channel_ = NULL;
+}
+
+void CastIPCDispatcher::OnReceivedPacket(
+ int32 channel_id,
+ const media::cast::transport::Packet& packet) {
+ CastTransportSenderIPC* sender = id_map_.Lookup(channel_id);
+ if (sender) {
+ sender->OnReceivedPacket(packet);
+ } else {
+ LOG(ERROR) << "CastIPCDispatcher::OnReceivedPacket "
+ << "on non-existing channel.";
+ }
+}
+
+void CastIPCDispatcher::OnNotifyStatusChange(
+ int32 channel_id,
+ media::cast::transport::CastTransportStatus status) {
+ CastTransportSenderIPC* sender = id_map_.Lookup(channel_id);
+ if (sender) {
+ sender->OnNotifyStatusChange(status);
+ } else {
+ LOG(ERROR)
+ << "CastIPCDispatcher::OnNotifystatusChange on non-existing channel.";
+ }
+}
+
+void CastIPCDispatcher::OnRtpStatistics(
+ int32 channel_id,
+ bool audio,
+ const media::cast::transport::RtcpSenderInfo& sender_info,
+ base::TimeTicks time_sent,
+ uint32 rtp_timestamp) {
+ CastTransportSenderIPC* sender = id_map_.Lookup(channel_id);
+ if (sender) {
+ sender->OnRtpStatistics(audio, sender_info, time_sent, rtp_timestamp);
+ } else {
+ LOG(ERROR)
+ << "CastIPCDispatcher::OnNotifystatusChange on non-existing channel.";
+ }
+}
« no previous file with comments | « chrome/renderer/media/cast_ipc_dispatcher.h ('k') | chrome/renderer/media/cast_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698