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

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: merge 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 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_environment.h" 11 #include "media/cast/cast_environment.h"
11 #include "media/cast/cast_sender.h" 12 #include "media/cast/cast_sender.h"
12 #include "media/cast/logging/logging_defines.h" 13 #include "media/cast/logging/logging_defines.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 audio_configured_(false), 23 audio_configured_(false),
23 video_configured_(false), 24 video_configured_(false),
24 io_message_loop_proxy_( 25 io_message_loop_proxy_(
25 content::RenderThread::Get()->GetIOMessageLoopProxy()) { 26 content::RenderThread::Get()->GetIOMessageLoopProxy()) {
26 } 27 }
27 28
28 CastSessionDelegate::~CastSessionDelegate() { 29 CastSessionDelegate::~CastSessionDelegate() {
29 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 30 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
30 } 31 }
31 32
33 void CastSessionDelegate::SetSocketFactory(
34 scoped_ptr<CastSession::SocketFactory> socket_factory,
35 const net::IPEndPoint& remote_address) {
36 socket_factory_ = socket_factory.Pass();
37 remote_address_ = remote_address;
38 }
39
32 void CastSessionDelegate::StartAudio(const AudioSenderConfig& config) { 40 void CastSessionDelegate::StartAudio(const AudioSenderConfig& config) {
33 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 41 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
34 42
35 audio_configured_ = true; 43 audio_configured_ = true;
36 audio_config_ = config; 44 audio_config_ = config;
37 MaybeStartSending(); 45 MaybeStartSending();
38 } 46 }
39 47
40 void CastSessionDelegate::StartVideo(const VideoSenderConfig& config) { 48 void CastSessionDelegate::StartVideo(const VideoSenderConfig& config) {
41 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 49 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
42 50
43 video_configured_ = true; 51 video_configured_ = true;
44 video_config_ = config; 52 video_config_ = config;
45 MaybeStartSending(); 53 MaybeStartSending();
46 } 54 }
47 55
48 void CastSessionDelegate::StartSending() { 56 void CastSessionDelegate::StartSending() {
49 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 57 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
50 58
51 if (cast_environment_) 59 if (cast_environment_)
52 return; 60 return;
53 61
62 if (!socket_factory_) {
63 // TODO(hubbe): Post an error back to the user
64 return;
65 }
66
67 socket_ = socket_factory_->create();
68 socket_->SetDelegate(this);
69
54 audio_encode_thread_.Start(); 70 audio_encode_thread_.Start();
55 video_encode_thread_.Start(); 71 video_encode_thread_.Start();
56 72
57 // CastSender uses the renderer's IO thread as the main thread. This reduces 73 // CastSender uses the renderer's IO thread as the main thread. This reduces
58 // thread hopping for incoming video frames and outgoing network packets. 74 // thread hopping for incoming video frames and outgoing network packets.
59 // There's no need to decode so no thread assigned for decoding. 75 // There's no need to decode so no thread assigned for decoding.
60 // Get default logging: All disabled. 76 // Get default logging: All disabled.
61 cast_environment_ = new CastEnvironment( 77 cast_environment_ = new CastEnvironment(
62 &clock_, 78 &clock_,
63 base::MessageLoopProxy::current(), 79 base::MessageLoopProxy::current(),
64 audio_encode_thread_.message_loop_proxy(), 80 audio_encode_thread_.message_loop_proxy(),
65 NULL, 81 NULL,
66 video_encode_thread_.message_loop_proxy(), 82 video_encode_thread_.message_loop_proxy(),
67 NULL, 83 NULL,
68 media::cast::GetDefaultCastLoggingConfig()); 84 media::cast::GetDefaultCastLoggingConfig());
69 85
70 // TODO(hclam): A couple things need to be done here: 86 // TODO(hclam): A couple things need to be done here:
71 // 1. Connect media::cast::PacketSender to net::Socket interface. 87 // 1. Connect media::cast::PacketSender to net::Socket interface.
72 // 2. Implement VideoEncoderController to configure hardware encoder. 88 // 2. Implement VideoEncoderController to configure hardware encoder.
73 cast_sender_.reset(CastSender::CreateCastSender( 89 cast_sender_.reset(CastSender::CreateCastSender(
74 cast_environment_, 90 cast_environment_,
75 audio_config_, 91 audio_config_,
76 video_config_, 92 video_config_,
77 NULL, 93 NULL,
78 NULL)); 94 this));
95 }
96
97 // media::cast::PacketSender Implementation
98 bool CastSessionDelegate::SendPacket(
99 const media::cast::Packet& packet) {
100 // TODO(hubbe): Make sure audio and video packets gets the right DSCP.
101 socket_->SendWithDscp(
102 remote_address_,
103 *reinterpret_cast<const std::vector<char> *>(&packet),
104 net::DSCP_AF41);
105 return true;
106 }
107
108 bool CastSessionDelegate::SendPackets(
109 const media::cast::PacketList& packets) {
110 // TODO(hubbe): Add ability to send multiple packets in one IPC message.
111 for (size_t i = 0; i < packets.size(); i++) {
112 SendPacket(packets[i]);
113 }
114 return true;
115 }
116
117 // content::P2PSocketClient::Delegate Implementation
118 void CastSessionDelegate::OnOpen(
119 const net::IPEndPoint& address) {
120 // Called once Init completes. Ignored.
121 }
122
123 void CastSessionDelegate::OnIncomingTcpConnection(
124 const net::IPEndPoint& address,
125 content::P2PSocketClient* client) {
126 // We don't support server sockets.
127 NOTREACHED();
128 }
129
130 void CastSessionDelegate::OnSendComplete() {
131 // Ignored for now.
132 }
133
134 void CastSessionDelegate::OnError() {
135 // TODO(hubbe): Report this back to the user.
136 }
137
138 void CastSessionDelegate::OnDataReceived(const net::IPEndPoint& address,
139 const std::vector<char>& data) {
140 uint8 *packet_copy = new uint8[data.size()];
141 memcpy(packet_copy, &data[0], data.size());
142 cast_sender_->packet_receiver()->ReceivedPacket(
143 packet_copy,
144 data.size(),
145 base::Bind(&media::cast::PacketReceiver::DeletePacket,
146 packet_copy));
79 } 147 }
80 148
81 void CastSessionDelegate::MaybeStartSending() { 149 void CastSessionDelegate::MaybeStartSending() {
82 if (!audio_configured_ || !video_configured_) 150 if (!audio_configured_ || !video_configured_)
83 return; 151 return;
84 StartSending(); 152 StartSending();
85 } 153 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698