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

Side by Side Diff: chrome/renderer/media/cast_session_delegate.cc

Issue 883293005: Cast: Basic cast_receiver API for chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merged Created 5 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 unified diff | Download patch
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/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
(...skipping 13 matching lines...) Expand all
24 #include "media/cast/net/cast_transport_sender.h" 24 #include "media/cast/net/cast_transport_sender.h"
25 25
26 using media::cast::AudioSenderConfig; 26 using media::cast::AudioSenderConfig;
27 using media::cast::CastEnvironment; 27 using media::cast::CastEnvironment;
28 using media::cast::CastSender; 28 using media::cast::CastSender;
29 using media::cast::VideoSenderConfig; 29 using media::cast::VideoSenderConfig;
30 30
31 static base::LazyInstance<CastThreads> g_cast_threads = 31 static base::LazyInstance<CastThreads> g_cast_threads =
32 LAZY_INSTANCE_INITIALIZER; 32 LAZY_INSTANCE_INITIALIZER;
33 33
34 CastSessionDelegate::CastSessionDelegate() 34 CastSessionDelegateBase::CastSessionDelegateBase()
35 : io_message_loop_proxy_( 35 : io_message_loop_proxy_(
36 content::RenderThread::Get()->GetIOMessageLoopProxy()), 36 content::RenderThread::Get()->GetIOMessageLoopProxy()),
37 weak_factory_(this) { 37 weak_factory_(this) {
38 DCHECK(io_message_loop_proxy_.get()); 38 DCHECK(io_message_loop_proxy_.get());
39 } 39 }
40 40
41 CastSessionDelegateBase::~CastSessionDelegateBase() {
42 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
43 }
44
45 void CastSessionDelegateBase::StartUDP(
46 const net::IPEndPoint& local_endpoint,
47 const net::IPEndPoint& remote_endpoint,
48 scoped_ptr<base::DictionaryValue> options) {
49 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
50
51 // CastSender uses the renderer's IO thread as the main thread. This reduces
52 // thread hopping for incoming video frames and outgoing network packets.
53 cast_environment_ = new CastEnvironment(
miu 2015/02/11 02:52:50 This is a little weird. I would expect the CastEn
hubbe 2015/02/11 22:38:17 This is simply replicating existing (but perhaps s
54 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(),
55 base::MessageLoopProxy::current(),
56 g_cast_threads.Get().GetAudioEncodeMessageLoopProxy(),
57 g_cast_threads.Get().GetVideoEncodeMessageLoopProxy());
58
59 // Rationale for using unretained: The callback cannot be called after the
60 // destruction of CastTransportSenderIPC, and they both share the same thread.
61 cast_transport_.reset(new CastTransportSenderIPC(
62 local_endpoint,
63 remote_endpoint,
64 options.Pass(),
65 media::cast::PacketReceiverCallback(),
66 base::Bind(&CastSessionDelegateBase::StatusNotificationCB,
67 base::Unretained(this)),
68 base::Bind(&CastSessionDelegateBase::LogRawEvents,
69 base::Unretained(this))));
70 }
71
72 void CastSessionDelegateBase::StatusNotificationCB(
73 media::cast::CastTransportStatus unused_status) {
74 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
75 // TODO(hubbe): Call javascript UDPTransport error function.
76 }
77
78 CastSessionDelegate::CastSessionDelegate()
79 : weak_factory_(this) {
80 DCHECK(io_message_loop_proxy_.get());
81 }
82
41 CastSessionDelegate::~CastSessionDelegate() { 83 CastSessionDelegate::~CastSessionDelegate() {
42 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 84 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
43 } 85 }
44 86
45 void CastSessionDelegate::StartAudio( 87 void CastSessionDelegate::StartAudio(
46 const AudioSenderConfig& config, 88 const AudioSenderConfig& config,
47 const AudioFrameInputAvailableCallback& callback, 89 const AudioFrameInputAvailableCallback& callback,
48 const ErrorCallback& error_callback) { 90 const ErrorCallback& error_callback) {
49 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 91 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
50 92
(...skipping 26 matching lines...) Expand all
77 video_frame_input_available_callback_ = callback; 119 video_frame_input_available_callback_ = callback;
78 120
79 cast_sender_->InitializeVideo( 121 cast_sender_->InitializeVideo(
80 config, 122 config,
81 base::Bind(&CastSessionDelegate::OnOperationalStatusChange, 123 base::Bind(&CastSessionDelegate::OnOperationalStatusChange,
82 weak_factory_.GetWeakPtr(), false, error_callback), 124 weak_factory_.GetWeakPtr(), false, error_callback),
83 create_vea_cb, 125 create_vea_cb,
84 create_video_encode_mem_cb); 126 create_video_encode_mem_cb);
85 } 127 }
86 128
87 void CastSessionDelegate::StartUDP(const net::IPEndPoint& remote_endpoint, 129
88 scoped_ptr<base::DictionaryValue> options) { 130 void CastSessionDelegate::StartUDP(
131 const net::IPEndPoint& local_endpoint,
132 const net::IPEndPoint& remote_endpoint,
133 scoped_ptr<base::DictionaryValue> options) {
89 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 134 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
90 135 CastSessionDelegateBase::StartUDP(local_endpoint,
91 // CastSender uses the renderer's IO thread as the main thread. This reduces 136 remote_endpoint,
92 // thread hopping for incoming video frames and outgoing network packets. 137 options.Pass());
93 cast_environment_ = new CastEnvironment(
94 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(),
95 base::MessageLoopProxy::current(),
96 g_cast_threads.Get().GetAudioEncodeMessageLoopProxy(),
97 g_cast_threads.Get().GetVideoEncodeMessageLoopProxy());
98
99 event_subscribers_.reset( 138 event_subscribers_.reset(
100 new media::cast::RawEventSubscriberBundle(cast_environment_)); 139 new media::cast::RawEventSubscriberBundle(cast_environment_));
101 140
102 // Rationale for using unretained: The callback cannot be called after the
103 // destruction of CastTransportSenderIPC, and they both share the same thread.
104 cast_transport_.reset(new CastTransportSenderIPC(
105 net::IPEndPoint(),
106 remote_endpoint,
107 options.Pass(),
108 media::cast::PacketReceiverCallback(),
109 base::Bind(&CastSessionDelegate::StatusNotificationCB,
110 base::Unretained(this)),
111 base::Bind(&CastSessionDelegate::LogRawEvents, base::Unretained(this))));
112
113 cast_sender_ = CastSender::Create(cast_environment_, cast_transport_.get()); 141 cast_sender_ = CastSender::Create(cast_environment_, cast_transport_.get());
114 } 142 }
115 143
116 void CastSessionDelegate::ToggleLogging(bool is_audio, bool enable) { 144 void CastSessionDelegate::ToggleLogging(bool is_audio, bool enable) {
117 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 145 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
118 if (!event_subscribers_.get()) 146 if (!event_subscribers_.get())
119 return; 147 return;
120 148
121 if (enable) 149 if (enable)
122 event_subscribers_->AddEventSubscribers(is_audio); 150 event_subscribers_->AddEventSubscribers(is_audio);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 callback.Run(make_scoped_ptr(new base::DictionaryValue).Pass()); 223 callback.Run(make_scoped_ptr(new base::DictionaryValue).Pass());
196 return; 224 return;
197 } 225 }
198 226
199 scoped_ptr<base::DictionaryValue> stats = subscriber->GetStats(); 227 scoped_ptr<base::DictionaryValue> stats = subscriber->GetStats();
200 subscriber->Reset(); 228 subscriber->Reset();
201 229
202 callback.Run(stats.Pass()); 230 callback.Run(stats.Pass());
203 } 231 }
204 232
205 void CastSessionDelegate::StatusNotificationCB(
206 media::cast::CastTransportStatus unused_status) {
207 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
208 // TODO(hubbe): Call javascript UDPTransport error function.
209 }
210
211 void CastSessionDelegate::OnOperationalStatusChange( 233 void CastSessionDelegate::OnOperationalStatusChange(
212 bool is_for_audio, 234 bool is_for_audio,
213 const ErrorCallback& error_callback, 235 const ErrorCallback& error_callback,
214 media::cast::OperationalStatus status) { 236 media::cast::OperationalStatus status) {
215 DCHECK(cast_sender_); 237 DCHECK(cast_sender_);
216 238
217 switch (status) { 239 switch (status) {
218 case media::cast::STATUS_UNINITIALIZED: 240 case media::cast::STATUS_UNINITIALIZED:
219 case media::cast::STATUS_CODEC_REINIT_PENDING: 241 case media::cast::STATUS_CODEC_REINIT_PENDING:
220 // Not an error. 242 // Not an error.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } else { 312 } else {
291 cast_environment_->Logging()->InsertFrameEvent( 313 cast_environment_->Logging()->InsertFrameEvent(
292 it->timestamp, 314 it->timestamp,
293 it->type, 315 it->type,
294 it->media_type, 316 it->media_type,
295 it->rtp_timestamp, 317 it->rtp_timestamp,
296 it->frame_id); 318 it->frame_id);
297 } 319 }
298 } 320 }
299 } 321 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698