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

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

Issue 66293003: P2P <-> cast library integration v0.1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: adding missing class export Created 7 years 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_session_delegate.cc
diff --git a/chrome/renderer/media/cast_session_delegate.cc b/chrome/renderer/media/cast_session_delegate.cc
index 744033ae794f446891e80d95f30a4f31cc6c79fb..0c6794bdd583386735d49cf19a1460a0f35ee185 100644
--- a/chrome/renderer/media/cast_session_delegate.cc
+++ b/chrome/renderer/media/cast_session_delegate.cc
@@ -6,7 +6,9 @@
#include "base/logging.h"
#include "base/message_loop/message_loop_proxy.h"
+#include "content/public/renderer/p2p_socket_client.h"
#include "content/public/renderer/render_thread.h"
+#include "media/cast/cast_config.h"
#include "media/cast/cast_environment.h"
#include "media/cast/cast_sender.h"
#include "media/cast/logging/logging_defines.h"
@@ -29,6 +31,13 @@ CastSessionDelegate::~CastSessionDelegate() {
DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
}
+void CastSessionDelegate::SetSocketFactory(
+ scoped_ptr<CastSession::SocketFactory> socket_factory,
+ const net::IPEndPoint& remote_address) {
+ socket_factory_ = socket_factory.Pass();
+ remote_address_ = remote_address;
+}
+
void CastSessionDelegate::StartAudio(const AudioSenderConfig& config) {
DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
@@ -51,6 +60,14 @@ void CastSessionDelegate::StartSending() {
if (cast_environment_)
return;
+ if (!socket_factory_) {
+ // TODO(hubbe): Post an error back to the user
+ return;
+ }
+
+ socket_ = socket_factory_->create();
+ socket_->SetDelegate(this);
+
audio_encode_thread_.Start();
video_encode_thread_.Start();
@@ -67,15 +84,66 @@ void CastSessionDelegate::StartSending() {
NULL,
media::cast::GetDefaultCastLoggingConfig());
- // TODO(hclam): A couple things need to be done here:
- // 1. Connect media::cast::PacketSender to net::Socket interface.
- // 2. Implement VideoEncoderController to configure hardware encoder.
+ // TODO(hclam): Implement VideoEncoderController to configure hardware
+ // encoder.
cast_sender_.reset(CastSender::CreateCastSender(
cast_environment_,
audio_config_,
video_config_,
NULL,
- NULL));
+ this));
+}
+
+ // media::cast::PacketSender Implementation
+bool CastSessionDelegate::SendPacket(
+ const media::cast::Packet& packet) {
+ // TODO(hubbe): Make sure audio and video packets gets the right DSCP.
+ socket_->SendWithDscp(
+ remote_address_,
+ *reinterpret_cast<const std::vector<char> *>(&packet),
+ net::DSCP_AF41);
+ return true;
+}
+
+bool CastSessionDelegate::SendPackets(
+ const media::cast::PacketList& packets) {
+ // TODO(hubbe): Add ability to send multiple packets in one IPC message.
+ for (size_t i = 0; i < packets.size(); i++) {
+ SendPacket(packets[i]);
+ }
+ return true;
+}
+
+// content::P2PSocketClient::Delegate Implementation
+void CastSessionDelegate::OnOpen(
+ const net::IPEndPoint& address) {
+ // Called once Init completes. Ignored.
+}
+
+void CastSessionDelegate::OnIncomingTcpConnection(
+ const net::IPEndPoint& address,
+ content::P2PSocketClient* client) {
+ // We don't support server sockets.
Sergey Ulanov 2013/12/07 01:15:29 Do you ever use TCP sockets for cast? If not, then
hubbe 2013/12/10 18:25:57 Done.
+ NOTREACHED();
+}
+
+void CastSessionDelegate::OnSendComplete() {
+ // Ignored for now.
+}
+
+void CastSessionDelegate::OnError() {
+ // TODO(hubbe): Report this back to the user.
+}
+
+void CastSessionDelegate::OnDataReceived(const net::IPEndPoint& address,
+ const std::vector<char>& data) {
+ uint8 *packet_copy = new uint8[data.size()];
+ memcpy(packet_copy, &data[0], data.size());
+ cast_sender_->packet_receiver()->ReceivedPacket(
+ packet_copy,
+ data.size(),
+ base::Bind(&media::cast::PacketReceiver::DeletePacket,
+ packet_copy));
}
void CastSessionDelegate::MaybeStartSending() {

Powered by Google App Engine
This is Rietveld 408576698