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

Side by Side 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: Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/media/cast_session_delegate.h" 5 #include "chrome/renderer/media/cast_session_delegate.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "content/public/renderer/p2p_socket_client.h"
9 #include "content/public/renderer/render_thread.h" 10 #include "content/public/renderer/render_thread.h"
10 #include "media/cast/cast_config.h" 11 #include "media/cast/cast_config.h"
11 #include "media/cast/cast_environment.h" 12 #include "media/cast/cast_environment.h"
12 #include "media/cast/cast_sender.h" 13 #include "media/cast/cast_sender.h"
13 14
14 using media::cast::AudioSenderConfig; 15 using media::cast::AudioSenderConfig;
15 using media::cast::CastEnvironment; 16 using media::cast::CastEnvironment;
16 using media::cast::CastSender; 17 using media::cast::CastSender;
17 using media::cast::VideoSenderConfig; 18 using media::cast::VideoSenderConfig;
18 19
19 CastSessionDelegate::CastSessionDelegate() 20 CastSessionDelegate::CastSessionDelegate()
20 : audio_encode_thread_("CastAudioEncodeThread"), 21 : audio_encode_thread_("CastAudioEncodeThread"),
21 video_encode_thread_("CastVideoEncodeThread"), 22 video_encode_thread_("CastVideoEncodeThread"),
22 io_message_loop_proxy_( 23 io_message_loop_proxy_(
23 content::RenderThread::Get()->GetIOMessageLoopProxy()) { 24 content::RenderThread::Get()->GetIOMessageLoopProxy()) {
24 } 25 }
25 26
26 CastSessionDelegate::~CastSessionDelegate() { 27 CastSessionDelegate::~CastSessionDelegate() {
27 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 28 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
28 } 29 }
29 30
31 void CastSessionDelegate::SetSocketFactory(
32 CastSession::SocketFactory* socket_factory,
33 const net::IPEndPoint& remote_address) {
34 socket_factory_.reset(socket_factory);
35 remote_address_ = remote_address;
36 }
37
30 void CastSessionDelegate::PrepareForSending() { 38 void CastSessionDelegate::PrepareForSending() {
31 DCHECK(base::MessageLoopProxy::current() == io_message_loop_proxy_); 39 DCHECK(base::MessageLoopProxy::current() == io_message_loop_proxy_);
32 40
33 if (cast_environment_) 41 if (cast_environment_)
34 return; 42 return;
35 43
44 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?
45 // TODO(hubbe): Post an error back to the user
46 return;
47 }
48
49 socket_ = socket_factory_->create();
50 socket_->set_delegate(this);
51
36 audio_encode_thread_.Start(); 52 audio_encode_thread_.Start();
37 video_encode_thread_.Start(); 53 video_encode_thread_.Start();
38 54
39 // CastSender uses the renderer's IO thread as the main thread. This reduces 55 // CastSender uses the renderer's IO thread as the main thread. This reduces
40 // thread hopping for incoming video frames and outgoing network packets. 56 // thread hopping for incoming video frames and outgoing network packets.
41 // There's no need to decode so no thread assigned for decoding. 57 // There's no need to decode so no thread assigned for decoding.
42 cast_environment_ = new CastEnvironment( 58 cast_environment_ = new CastEnvironment(
43 &clock_, 59 &clock_,
44 base::MessageLoopProxy::current(), 60 base::MessageLoopProxy::current(),
45 audio_encode_thread_.message_loop_proxy(), 61 audio_encode_thread_.message_loop_proxy(),
46 NULL, 62 NULL,
47 video_encode_thread_.message_loop_proxy(), 63 video_encode_thread_.message_loop_proxy(),
48 NULL); 64 NULL);
49 65
50 // TODO(hclam): A couple things need to be done here: 66 // TODO(hclam): A couple things need to be done here:
51 // 1. Pass audio and video configuration to CastSender. 67 // 1. Pass audio and video configuration to CastSender.
52 // 2. Connect media::cast::PacketSender to net::Socket interface. 68 // 2. Implement VideoEncoderController to configure hardware encoder.
53 // 3. Implement VideoEncoderController to configure hardware encoder.
54 cast_sender_.reset(CastSender::CreateCastSender( 69 cast_sender_.reset(CastSender::CreateCastSender(
55 cast_environment_, 70 cast_environment_,
56 AudioSenderConfig(), 71 AudioSenderConfig(),
57 VideoSenderConfig(), 72 VideoSenderConfig(),
58 NULL, 73 NULL,
59 NULL)); 74 this));
60 } 75 }
76
77 // media::cast::PacketSender Implementation
78 bool CastSessionDelegate::SendPacket(
79 const media::cast::Packet& packet) {
80 // TODO(hubbe): Make sure audio and video packets gets the right DSCP.
81 socket_->SendWithDscp(
82 remote_address_,
83 *reinterpret_cast<const std::vector<char> *>(&packet),
84 net::DSCP_AF41);
85 return true;
86 }
87
88 bool CastSessionDelegate::SendPackets(
89 const media::cast::PacketList& packets) {
90 // TODO(hubbe): Add ability to send multiple packets in one IPC message.
91 for (size_t i = 0; i < packets.size(); i++) {
92 SendPacket(packets[i]);
93 }
94 return true;
95 }
96
97 // content::P2PSocketClient::Delegate Implementation
98 void CastSessionDelegate::OnOpen(
99 const net::IPEndPoint& address) {
100 // Called once Init completes. Ignored.
101 }
102
103 void CastSessionDelegate::OnIncomingTcpConnection(
104 const net::IPEndPoint& address,
105 content::P2PSocketClient* client) {
106 // We don't support server sockets.
107 NOTREACHED();
108 }
109
110 void CastSessionDelegate::OnSendComplete() {
111 // 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.
112 }
113
114 void CastSessionDelegate::OnError() {
115 // 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.
116 }
117
118 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
119 const std::vector<char>& data) {
120 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
121 memcpy(packet_copy, &data[0], data.size());
122 cast_sender_->packet_receiver()->ReceivedPacket(
123 packet_copy, data.size(),
124 base::Bind(&media::cast::PacketReceiver::DeletePacket,
125 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
126 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698