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 8f0fc07b8e374f28e81da598a21a015bbaaffe02..9c824613ab2d365556860315bb7d82a5b189a363 100644 |
--- a/chrome/renderer/media/cast_session_delegate.cc |
+++ b/chrome/renderer/media/cast_session_delegate.cc |
@@ -6,6 +6,7 @@ |
#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" |
@@ -27,12 +28,27 @@ CastSessionDelegate::~CastSessionDelegate() { |
DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
} |
+void CastSessionDelegate::SetSocketFactory( |
+ CastSession::SocketFactory* socket_factory, |
+ const net::IPEndPoint& remote_address) { |
+ socket_factory_.reset(socket_factory); |
+ remote_address_ = remote_address; |
+} |
+ |
void CastSessionDelegate::PrepareForSending() { |
DCHECK(base::MessageLoopProxy::current() == io_message_loop_proxy_); |
if (cast_environment_) |
return; |
+ if (!socket_factory_) { |
Alpha Left Google
2013/11/09 00:30:18
I'd just do a DCHECK. We should never be here with
hubbe
2013/11/26 20:24:29
Isn't this function triggered by some javascript?
|
+ // TODO(hubbe): Post an error back to the user |
+ return; |
+ } |
+ |
+ socket_ = socket_factory_->create(); |
+ socket_->set_delegate(this); |
+ |
audio_encode_thread_.Start(); |
video_encode_thread_.Start(); |
@@ -49,12 +65,62 @@ void CastSessionDelegate::PrepareForSending() { |
// TODO(hclam): A couple things need to be done here: |
// 1. Pass audio and video configuration to CastSender. |
- // 2. Connect media::cast::PacketSender to net::Socket interface. |
- // 3. Implement VideoEncoderController to configure hardware encoder. |
+ // 2. Implement VideoEncoderController to configure hardware encoder. |
cast_sender_.reset(CastSender::CreateCastSender( |
cast_environment_, |
AudioSenderConfig(), |
VideoSenderConfig(), |
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. |
+ NOTREACHED(); |
+} |
+ |
+void CastSessionDelegate::OnSendComplete() { |
+ // Ignored |
Alpha Left Google
2013/11/09 00:30:18
nit: Period at the end of sentence.
hubbe
2013/11/26 20:24:29
Done.
|
+} |
+ |
+void CastSessionDelegate::OnError() { |
+ // TODO(hubbe): Report this back to the user |
Alpha Left Google
2013/11/09 00:30:18
nit: Period at the end of sentence.
hubbe
2013/11/26 20:24:29
Done.
|
+} |
+ |
+void CastSessionDelegate::OnDataReceived(const net::IPEndPoint& address, |
Alpha Left Google
2013/11/09 00:30:18
Should we verify the packet is coming from the rig
hubbe
2013/11/26 20:24:29
Good question.
Will each connection have its own s
|
+ const std::vector<char>& data) { |
+ uint8 *packet_copy = new uint8[data.size()]; |
Alpha Left Google
2013/11/09 00:30:18
Use scoped_ptr<uint8[]>.
hubbe
2013/11/26 20:24:29
see below
|
+ memcpy(packet_copy, &data[0], data.size()); |
+ cast_sender_->packet_receiver()->ReceivedPacket( |
+ packet_copy, data.size(), |
+ base::Bind(&media::cast::PacketReceiver::DeletePacket, |
+ packet_copy)); |
Alpha Left Google
2013/11/09 00:30:18
You can do a base::Passed(packet_copy) if packet_c
hubbe
2013/11/26 20:24:29
I'm not sure it's going to be that easy.
I also us
|
} |