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

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: comments 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";
43 44
44 // These helper methods are used to convert between Extension API 45 // These helper methods are used to convert between Extension API
45 // types and Cast types. 46 // types and Cast types.
46 void ToCastCodecSpecificParams(const CodecSpecificParams& ext_params, 47 void ToCastCodecSpecificParams(const CodecSpecificParams& ext_params,
47 CastCodecSpecificParams* cast_params) { 48 CastCodecSpecificParams* cast_params) {
48 cast_params->key = ext_params.key; 49 cast_params->key = ext_params.key;
49 cast_params->value = ext_params.value; 50 cast_params->value = ext_params.value;
50 } 51 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 base::Bind(&CastStreamingNativeHandler::GetStats, 190 base::Bind(&CastStreamingNativeHandler::GetStats,
190 base::Unretained(this))); 191 base::Unretained(this)));
191 } 192 }
192 193
193 CastStreamingNativeHandler::~CastStreamingNativeHandler() { 194 CastStreamingNativeHandler::~CastStreamingNativeHandler() {
194 } 195 }
195 196
196 void CastStreamingNativeHandler::CreateCastSession( 197 void CastStreamingNativeHandler::CreateCastSession(
197 const v8::FunctionCallbackInfo<v8::Value>& args) { 198 const v8::FunctionCallbackInfo<v8::Value>& args) {
198 CHECK_EQ(3, args.Length()); 199 CHECK_EQ(3, args.Length());
199 CHECK(args[0]->IsObject());
200 CHECK(args[1]->IsObject());
201 CHECK(args[2]->IsFunction()); 200 CHECK(args[2]->IsFunction());
202 201
203 blink::WebDOMMediaStreamTrack track1 = 202 if (args[0]->IsNull() && args[1]->IsNull()) {
not at google - send to devlin 2014/07/15 23:55:42 undefined is an acceptable value for optional argu
Alpha Left Google 2014/07/16 21:47:46 Checked for IsUndefined() now.
204 blink::WebDOMMediaStreamTrack::fromV8Value(args[0]); 203 v8::Isolate* isolate = context()->v8_context()->GetIsolate();
205 if (track1.isNull()) 204 isolate->ThrowException(v8::Exception::Error(
205 v8::String::NewFromUtf8(isolate, kInvalidStreamArgs)));
206 return; 206 return;
207 blink::WebDOMMediaStreamTrack track2 = 207 }
208 blink::WebDOMMediaStreamTrack::fromV8Value(args[1]);
209 if (track2.isNull())
210 return;
211 208
212 scoped_refptr<CastSession> session(new CastSession()); 209 scoped_refptr<CastSession> session(new CastSession());
213 scoped_ptr<CastRtpStream> stream1( 210 scoped_ptr<CastRtpStream> stream1, stream2;
214 new CastRtpStream(track1.component(), session)); 211 if (!args[0]->IsNull()) {
215 scoped_ptr<CastRtpStream> stream2( 212 CHECK(args[0]->IsObject());
216 new CastRtpStream(track2.component(), session)); 213 blink::WebDOMMediaStreamTrack track =
214 blink::WebDOMMediaStreamTrack::fromV8Value(args[0]);
215 stream1.reset(new CastRtpStream(track.component(), session));
216 }
217 if (!args[1]->IsNull()) {
218 CHECK(args[1]->IsObject());
219 blink::WebDOMMediaStreamTrack track =
220 blink::WebDOMMediaStreamTrack::fromV8Value(args[1]);
221 stream2.reset(new CastRtpStream(track.component(), session));
222 }
217 scoped_ptr<CastUdpTransport> udp_transport( 223 scoped_ptr<CastUdpTransport> udp_transport(
218 new CastUdpTransport(session)); 224 new CastUdpTransport(session));
219 225
220 // TODO(imcheng): Use a weak reference to ensure we don't call into an 226 // TODO(imcheng): Use a weak reference to ensure we don't call into an
221 // invalid context when the callback is invoked. 227 // invalid context when the callback is invoked.
222 create_callback_.reset(args[2].As<v8::Function>()); 228 create_callback_.reset(args[2].As<v8::Function>());
223 229
224 base::MessageLoop::current()->PostTask( 230 base::MessageLoop::current()->PostTask(
225 FROM_HERE, 231 FROM_HERE,
226 base::Bind( 232 base::Bind(
227 &CastStreamingNativeHandler::CallCreateCallback, 233 &CastStreamingNativeHandler::CallCreateCallback,
228 weak_factory_.GetWeakPtr(), 234 weak_factory_.GetWeakPtr(),
229 base::Passed(&stream1), 235 base::Passed(&stream1),
230 base::Passed(&stream2), 236 base::Passed(&stream2),
231 base::Passed(&udp_transport))); 237 base::Passed(&udp_transport)));
232 } 238 }
233 239
234 void CastStreamingNativeHandler::CallCreateCallback( 240 void CastStreamingNativeHandler::CallCreateCallback(
235 scoped_ptr<CastRtpStream> stream1, 241 scoped_ptr<CastRtpStream> stream1,
236 scoped_ptr<CastRtpStream> stream2, 242 scoped_ptr<CastRtpStream> stream2,
237 scoped_ptr<CastUdpTransport> udp_transport) { 243 scoped_ptr<CastUdpTransport> udp_transport) {
238 v8::Isolate* isolate = context()->isolate(); 244 v8::Isolate* isolate = context()->isolate();
239 v8::HandleScope handle_scope(isolate); 245 v8::HandleScope handle_scope(isolate);
240 v8::Context::Scope context_scope(context()->v8_context()); 246 v8::Context::Scope context_scope(context()->v8_context());
241 247
242 const int stream1_id = last_transport_id_++; 248 v8::Handle<v8::Value> callback_args[3];
243 rtp_stream_map_[stream1_id] = 249 callback_args[0] = v8::Null(isolate);
244 linked_ptr<CastRtpStream>(stream1.release()); 250 callback_args[1] = v8::Null(isolate);
245 const int stream2_id = last_transport_id_++; 251
246 rtp_stream_map_[stream2_id] = 252 if (stream1) {
247 linked_ptr<CastRtpStream>(stream2.release()); 253 const int stream1_id = last_transport_id_++;
254 callback_args[0] = v8::Integer::New(isolate, stream1_id);
255 rtp_stream_map_[stream1_id] =
256 linked_ptr<CastRtpStream>(stream1.release());
257 }
258 if (stream2) {
259 const int stream2_id = last_transport_id_++;
260 callback_args[1] = v8::Integer::New(isolate, stream2_id);
261 rtp_stream_map_[stream2_id] =
262 linked_ptr<CastRtpStream>(stream2.release());
263 }
248 const int udp_id = last_transport_id_++; 264 const int udp_id = last_transport_id_++;
249 udp_transport_map_[udp_id] = 265 udp_transport_map_[udp_id] =
250 linked_ptr<CastUdpTransport>(udp_transport.release()); 266 linked_ptr<CastUdpTransport>(udp_transport.release());
251
252 v8::Handle<v8::Value> callback_args[3];
253 callback_args[0] = v8::Integer::New(isolate, stream1_id);
254 callback_args[1] = v8::Integer::New(isolate, stream2_id);
255 callback_args[2] = v8::Integer::New(isolate, udp_id); 267 callback_args[2] = v8::Integer::New(isolate, udp_id);
256 context()->CallFunction(create_callback_.NewHandle(isolate), 268 context()->CallFunction(create_callback_.NewHandle(isolate),
257 3, callback_args); 269 3, callback_args);
258 create_callback_.reset(); 270 create_callback_.reset();
259 } 271 }
260 272
261 void CastStreamingNativeHandler::CallStartCallback(int stream_id) { 273 void CastStreamingNativeHandler::CallStartCallback(int stream_id) {
262 v8::Isolate* isolate = context()->isolate(); 274 v8::Isolate* isolate = context()->isolate();
263 v8::HandleScope handle_scope(isolate); 275 v8::HandleScope handle_scope(isolate);
264 v8::Context::Scope context_scope(context()->v8_context()); 276 v8::Context::Scope context_scope(context()->v8_context());
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 transport_id); 565 transport_id);
554 if (iter != udp_transport_map_.end()) 566 if (iter != udp_transport_map_.end())
555 return iter->second.get(); 567 return iter->second.get();
556 v8::Isolate* isolate = context()->v8_context()->GetIsolate(); 568 v8::Isolate* isolate = context()->v8_context()->GetIsolate();
557 isolate->ThrowException(v8::Exception::RangeError( 569 isolate->ThrowException(v8::Exception::RangeError(
558 v8::String::NewFromUtf8(isolate, kUdpTransportNotFound))); 570 v8::String::NewFromUtf8(isolate, kUdpTransportNotFound)));
559 return NULL; 571 return NULL;
560 } 572 }
561 573
562 } // namespace extensions 574 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698