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

Side by Side Diff: chrome/renderer/extensions/cast_streaming_native_handler.cc

Issue 391263002: Cast: cast.streaming API to support null audio (or video) track (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | 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/extensions/cast_streaming_native_handler.h" 5 #include "chrome/renderer/extensions/cast_streaming_native_handler.h"
6 6
7 #include <functional> 7 #include <functional>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 20 matching lines...) Expand all
31 31
32 namespace extensions { 32 namespace extensions {
33 33
34 namespace { 34 namespace {
35 const char kRtpStreamNotFound[] = "The RTP stream cannot be found"; 35 const char kRtpStreamNotFound[] = "The RTP stream cannot be found";
36 const char kUdpTransportNotFound[] = "The UDP transport cannot be found"; 36 const char kUdpTransportNotFound[] = "The UDP transport cannot be found";
37 const char kInvalidDestination[] = "Invalid destination"; 37 const char kInvalidDestination[] = "Invalid destination";
38 const char kInvalidRtpParams[] = "Invalid value for RTP params"; 38 const char kInvalidRtpParams[] = "Invalid value for RTP params";
39 const char kInvalidAesKey[] = "Invalid value for AES key"; 39 const char kInvalidAesKey[] = "Invalid value for AES key";
40 const char kInvalidAesIvMask[] = "Invalid value for AES IV mask"; 40 const char kInvalidAesIvMask[] = "Invalid value for AES IV mask";
41 const char kInvalidStreamArgs[] = "Invalid stream arguments";
41 const char kUnableToConvertArgs[] = "Unable to convert arguments"; 42 const char kUnableToConvertArgs[] = "Unable to convert arguments";
42 const char kUnableToConvertParams[] = "Unable to convert params"; 43 const char kUnableToConvertParams[] = "Unable to convert params";
44 const int kInvalidId = 0;
43 45
44 // These helper methods are used to convert between Extension API 46 // These helper methods are used to convert between Extension API
45 // types and Cast types. 47 // types and Cast types.
46 void ToCastCodecSpecificParams(const CodecSpecificParams& ext_params, 48 void ToCastCodecSpecificParams(const CodecSpecificParams& ext_params,
47 CastCodecSpecificParams* cast_params) { 49 CastCodecSpecificParams* cast_params) {
48 cast_params->key = ext_params.key; 50 cast_params->key = ext_params.key;
49 cast_params->value = ext_params.value; 51 cast_params->value = ext_params.value;
50 } 52 }
51 53
52 void FromCastCodecSpecificParams(const CastCodecSpecificParams& cast_params, 54 void FromCastCodecSpecificParams(const CastCodecSpecificParams& cast_params,
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 base::Bind(&CastStreamingNativeHandler::GetStats, 191 base::Bind(&CastStreamingNativeHandler::GetStats,
190 base::Unretained(this))); 192 base::Unretained(this)));
191 } 193 }
192 194
193 CastStreamingNativeHandler::~CastStreamingNativeHandler() { 195 CastStreamingNativeHandler::~CastStreamingNativeHandler() {
194 } 196 }
195 197
196 void CastStreamingNativeHandler::CreateCastSession( 198 void CastStreamingNativeHandler::CreateCastSession(
197 const v8::FunctionCallbackInfo<v8::Value>& args) { 199 const v8::FunctionCallbackInfo<v8::Value>& args) {
198 CHECK_EQ(3, args.Length()); 200 CHECK_EQ(3, args.Length());
199 CHECK(args[0]->IsObject());
200 CHECK(args[1]->IsObject());
201 CHECK(args[2]->IsFunction()); 201 CHECK(args[2]->IsFunction());
202 202
203 blink::WebDOMMediaStreamTrack track1 = 203 if (args[0]->IsNull() && args[1]->IsNull()) {
204 blink::WebDOMMediaStreamTrack::fromV8Value(args[0]); 204 v8::Isolate* isolate = context()->v8_context()->GetIsolate();
205 if (track1.isNull()) 205 isolate->ThrowException(v8::Exception::Error(
206 v8::String::NewFromUtf8(isolate, kInvalidStreamArgs)));
206 return; 207 return;
207 blink::WebDOMMediaStreamTrack track2 = 208 }
208 blink::WebDOMMediaStreamTrack::fromV8Value(args[1]);
209 if (track2.isNull())
210 return;
211 209
212 scoped_refptr<CastSession> session(new CastSession()); 210 scoped_refptr<CastSession> session(new CastSession());
213 scoped_ptr<CastRtpStream> stream1( 211 scoped_ptr<CastRtpStream> stream1, stream2;
214 new CastRtpStream(track1.component(), session)); 212 if (!args[0]->IsNull()) {
215 scoped_ptr<CastRtpStream> stream2( 213 CHECK(args[0]->IsObject());
216 new CastRtpStream(track2.component(), session)); 214 blink::WebDOMMediaStreamTrack track =
215 blink::WebDOMMediaStreamTrack::fromV8Value(args[0]);
216 stream1.reset(new CastRtpStream(track.component(), session));
217 }
218 if (!args[1]->IsNull()) {
219 CHECK(args[1]->IsObject());
220 blink::WebDOMMediaStreamTrack track =
221 blink::WebDOMMediaStreamTrack::fromV8Value(args[1]);
222 stream2.reset(new CastRtpStream(track.component(), session));
223 }
217 scoped_ptr<CastUdpTransport> udp_transport( 224 scoped_ptr<CastUdpTransport> udp_transport(
218 new CastUdpTransport(session)); 225 new CastUdpTransport(session));
219 226
220 // TODO(imcheng): Use a weak reference to ensure we don't call into an 227 // TODO(imcheng): Use a weak reference to ensure we don't call into an
221 // invalid context when the callback is invoked. 228 // invalid context when the callback is invoked.
222 create_callback_.reset(args[2].As<v8::Function>()); 229 create_callback_.reset(args[2].As<v8::Function>());
223 230
224 base::MessageLoop::current()->PostTask( 231 base::MessageLoop::current()->PostTask(
225 FROM_HERE, 232 FROM_HERE,
226 base::Bind( 233 base::Bind(
227 &CastStreamingNativeHandler::CallCreateCallback, 234 &CastStreamingNativeHandler::CallCreateCallback,
228 weak_factory_.GetWeakPtr(), 235 weak_factory_.GetWeakPtr(),
229 base::Passed(&stream1), 236 base::Passed(&stream1),
230 base::Passed(&stream2), 237 base::Passed(&stream2),
231 base::Passed(&udp_transport))); 238 base::Passed(&udp_transport)));
232 } 239 }
233 240
234 void CastStreamingNativeHandler::CallCreateCallback( 241 void CastStreamingNativeHandler::CallCreateCallback(
235 scoped_ptr<CastRtpStream> stream1, 242 scoped_ptr<CastRtpStream> stream1,
236 scoped_ptr<CastRtpStream> stream2, 243 scoped_ptr<CastRtpStream> stream2,
237 scoped_ptr<CastUdpTransport> udp_transport) { 244 scoped_ptr<CastUdpTransport> udp_transport) {
238 v8::Isolate* isolate = context()->isolate(); 245 v8::Isolate* isolate = context()->isolate();
239 v8::HandleScope handle_scope(isolate); 246 v8::HandleScope handle_scope(isolate);
240 v8::Context::Scope context_scope(context()->v8_context()); 247 v8::Context::Scope context_scope(context()->v8_context());
241 248
242 const int stream1_id = last_transport_id_++; 249 int stream1_id = kInvalidId;
243 rtp_stream_map_[stream1_id] = 250 int stream2_id = kInvalidId;
244 linked_ptr<CastRtpStream>(stream1.release()); 251
245 const int stream2_id = last_transport_id_++; 252 if (stream1) {
246 rtp_stream_map_[stream2_id] = 253 stream1_id = last_transport_id_++;
247 linked_ptr<CastRtpStream>(stream2.release()); 254 rtp_stream_map_[stream1_id] =
255 linked_ptr<CastRtpStream>(stream1.release());
256 }
257 if (stream2) {
258 stream2_id = last_transport_id_++;
259 rtp_stream_map_[stream2_id] =
260 linked_ptr<CastRtpStream>(stream2.release());
261 }
248 const int udp_id = last_transport_id_++; 262 const int udp_id = last_transport_id_++;
249 udp_transport_map_[udp_id] = 263 udp_transport_map_[udp_id] =
250 linked_ptr<CastUdpTransport>(udp_transport.release()); 264 linked_ptr<CastUdpTransport>(udp_transport.release());
251 265
252 v8::Handle<v8::Value> callback_args[3]; 266 v8::Handle<v8::Value> callback_args[3];
253 callback_args[0] = v8::Integer::New(isolate, stream1_id); 267 callback_args[0] = v8::Null(isolate);
254 callback_args[1] = v8::Integer::New(isolate, stream2_id); 268 callback_args[1] = v8::Null(isolate);
269 if (stream1_id != kInvalidId)
270 callback_args[0] = v8::Integer::New(isolate, stream1_id);
not at google - send to devlin 2014/07/15 23:32:18 can you put this up where it's guarded by the if (
Alpha Left Google 2014/07/15 23:48:42 Done.
271 if (stream2_id != kInvalidId)
272 callback_args[1] = v8::Integer::New(isolate, stream2_id);
255 callback_args[2] = v8::Integer::New(isolate, udp_id); 273 callback_args[2] = v8::Integer::New(isolate, udp_id);
256 context()->CallFunction(create_callback_.NewHandle(isolate), 274 context()->CallFunction(create_callback_.NewHandle(isolate),
257 3, callback_args); 275 3, callback_args);
258 create_callback_.reset(); 276 create_callback_.reset();
259 } 277 }
260 278
261 void CastStreamingNativeHandler::CallStartCallback(int stream_id) { 279 void CastStreamingNativeHandler::CallStartCallback(int stream_id) {
262 v8::Isolate* isolate = context()->isolate(); 280 v8::Isolate* isolate = context()->isolate();
263 v8::HandleScope handle_scope(isolate); 281 v8::HandleScope handle_scope(isolate);
264 v8::Context::Scope context_scope(context()->v8_context()); 282 v8::Context::Scope context_scope(context()->v8_context());
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 548
531 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 549 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
532 v8::Handle<v8::Value> callback_args[1]; 550 v8::Handle<v8::Value> callback_args[1];
533 callback_args[0] = converter->ToV8Value(stats.get(), context()->v8_context()); 551 callback_args[0] = converter->ToV8Value(stats.get(), context()->v8_context());
534 context()->CallFunction(it->second->NewHandle(isolate), 1, callback_args); 552 context()->CallFunction(it->second->NewHandle(isolate), 1, callback_args);
535 get_stats_callbacks_.erase(it); 553 get_stats_callbacks_.erase(it);
536 } 554 }
537 555
538 CastRtpStream* CastStreamingNativeHandler::GetRtpStreamOrThrow( 556 CastRtpStream* CastStreamingNativeHandler::GetRtpStreamOrThrow(
539 int transport_id) const { 557 int transport_id) const {
558 v8::Isolate* isolate = context()->v8_context()->GetIsolate();
not at google - send to devlin 2014/07/15 23:32:18 this change doesn't seem necessary
Alpha Left Google 2014/07/15 23:48:42 Done.
540 RtpStreamMap::const_iterator iter = rtp_stream_map_.find( 559 RtpStreamMap::const_iterator iter = rtp_stream_map_.find(
541 transport_id); 560 transport_id);
542 if (iter != rtp_stream_map_.end()) 561 if (iter != rtp_stream_map_.end())
543 return iter->second.get(); 562 return iter->second.get();
544 v8::Isolate* isolate = context()->v8_context()->GetIsolate();
545 isolate->ThrowException(v8::Exception::RangeError(v8::String::NewFromUtf8( 563 isolate->ThrowException(v8::Exception::RangeError(v8::String::NewFromUtf8(
546 isolate, kRtpStreamNotFound))); 564 isolate, kRtpStreamNotFound)));
547 return NULL; 565 return NULL;
548 } 566 }
549 567
550 CastUdpTransport* CastStreamingNativeHandler::GetUdpTransportOrThrow( 568 CastUdpTransport* CastStreamingNativeHandler::GetUdpTransportOrThrow(
551 int transport_id) const { 569 int transport_id) const {
552 UdpTransportMap::const_iterator iter = udp_transport_map_.find( 570 UdpTransportMap::const_iterator iter = udp_transport_map_.find(
553 transport_id); 571 transport_id);
554 if (iter != udp_transport_map_.end()) 572 if (iter != udp_transport_map_.end())
555 return iter->second.get(); 573 return iter->second.get();
556 v8::Isolate* isolate = context()->v8_context()->GetIsolate(); 574 v8::Isolate* isolate = context()->v8_context()->GetIsolate();
557 isolate->ThrowException(v8::Exception::RangeError( 575 isolate->ThrowException(v8::Exception::RangeError(
558 v8::String::NewFromUtf8(isolate, kUdpTransportNotFound))); 576 v8::String::NewFromUtf8(isolate, kUdpTransportNotFound)));
559 return NULL; 577 return NULL;
560 } 578 }
561 579
562 } // namespace extensions 580 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698