| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 rtp_stream_map_[stream1_id] = std::move(stream1); | 433 rtp_stream_map_[stream1_id] = std::move(stream1); |
| 434 } | 434 } |
| 435 if (stream2) { | 435 if (stream2) { |
| 436 const int stream2_id = last_transport_id_++; | 436 const int stream2_id = last_transport_id_++; |
| 437 callback_args[1] = v8::Integer::New(isolate, stream2_id); | 437 callback_args[1] = v8::Integer::New(isolate, stream2_id); |
| 438 rtp_stream_map_[stream2_id] = std::move(stream2); | 438 rtp_stream_map_[stream2_id] = std::move(stream2); |
| 439 } | 439 } |
| 440 const int udp_id = last_transport_id_++; | 440 const int udp_id = last_transport_id_++; |
| 441 udp_transport_map_[udp_id] = std::move(udp_transport); | 441 udp_transport_map_[udp_id] = std::move(udp_transport); |
| 442 callback_args[2] = v8::Integer::New(isolate, udp_id); | 442 callback_args[2] = v8::Integer::New(isolate, udp_id); |
| 443 context()->CallFunction( | 443 context()->SafeCallFunction( |
| 444 v8::Local<v8::Function>::New(isolate, create_callback_), 3, | 444 v8::Local<v8::Function>::New(isolate, create_callback_), 3, |
| 445 callback_args); | 445 callback_args); |
| 446 create_callback_.Reset(); | 446 create_callback_.Reset(); |
| 447 } | 447 } |
| 448 | 448 |
| 449 void CastStreamingNativeHandler::CallStartCallback(int stream_id) const { | 449 void CastStreamingNativeHandler::CallStartCallback(int stream_id) const { |
| 450 v8::Isolate* isolate = context()->isolate(); | 450 v8::Isolate* isolate = context()->isolate(); |
| 451 v8::HandleScope handle_scope(isolate); | 451 v8::HandleScope handle_scope(isolate); |
| 452 v8::Context::Scope context_scope(context()->v8_context()); | 452 v8::Context::Scope context_scope(context()->v8_context()); |
| 453 v8::Local<v8::Array> event_args = v8::Array::New(isolate, 1); | 453 v8::Local<v8::Array> event_args = v8::Array::New(isolate, 1); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 v8::HandleScope handle_scope(isolate); | 705 v8::HandleScope handle_scope(isolate); |
| 706 v8::Context::Scope context_scope(context()->v8_context()); | 706 v8::Context::Scope context_scope(context()->v8_context()); |
| 707 | 707 |
| 708 RtpStreamCallbackMap::iterator it = | 708 RtpStreamCallbackMap::iterator it = |
| 709 get_raw_events_callbacks_.find(transport_id); | 709 get_raw_events_callbacks_.find(transport_id); |
| 710 if (it == get_raw_events_callbacks_.end()) | 710 if (it == get_raw_events_callbacks_.end()) |
| 711 return; | 711 return; |
| 712 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 712 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
| 713 v8::Local<v8::Value> callback_args[] = { | 713 v8::Local<v8::Value> callback_args[] = { |
| 714 converter->ToV8Value(raw_events.get(), context()->v8_context())}; | 714 converter->ToV8Value(raw_events.get(), context()->v8_context())}; |
| 715 context()->CallFunction(v8::Local<v8::Function>::New(isolate, it->second), | 715 context()->SafeCallFunction(v8::Local<v8::Function>::New(isolate, it->second), |
| 716 arraysize(callback_args), callback_args); | 716 arraysize(callback_args), callback_args); |
| 717 get_raw_events_callbacks_.erase(it); | 717 get_raw_events_callbacks_.erase(it); |
| 718 } | 718 } |
| 719 | 719 |
| 720 void CastStreamingNativeHandler::CallGetStatsCallback( | 720 void CastStreamingNativeHandler::CallGetStatsCallback( |
| 721 int transport_id, | 721 int transport_id, |
| 722 std::unique_ptr<base::DictionaryValue> stats) { | 722 std::unique_ptr<base::DictionaryValue> stats) { |
| 723 v8::Isolate* isolate = context()->isolate(); | 723 v8::Isolate* isolate = context()->isolate(); |
| 724 v8::HandleScope handle_scope(isolate); | 724 v8::HandleScope handle_scope(isolate); |
| 725 v8::Context::Scope context_scope(context()->v8_context()); | 725 v8::Context::Scope context_scope(context()->v8_context()); |
| 726 | 726 |
| 727 RtpStreamCallbackMap::iterator it = get_stats_callbacks_.find(transport_id); | 727 RtpStreamCallbackMap::iterator it = get_stats_callbacks_.find(transport_id); |
| 728 if (it == get_stats_callbacks_.end()) | 728 if (it == get_stats_callbacks_.end()) |
| 729 return; | 729 return; |
| 730 | 730 |
| 731 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 731 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
| 732 v8::Local<v8::Value> callback_args[] = { | 732 v8::Local<v8::Value> callback_args[] = { |
| 733 converter->ToV8Value(stats.get(), context()->v8_context())}; | 733 converter->ToV8Value(stats.get(), context()->v8_context())}; |
| 734 context()->CallFunction(v8::Local<v8::Function>::New(isolate, it->second), | 734 context()->SafeCallFunction(v8::Local<v8::Function>::New(isolate, it->second), |
| 735 arraysize(callback_args), callback_args); | 735 arraysize(callback_args), callback_args); |
| 736 get_stats_callbacks_.erase(it); | 736 get_stats_callbacks_.erase(it); |
| 737 } | 737 } |
| 738 | 738 |
| 739 CastRtpStream* CastStreamingNativeHandler::GetRtpStreamOrThrow( | 739 CastRtpStream* CastStreamingNativeHandler::GetRtpStreamOrThrow( |
| 740 int transport_id) const { | 740 int transport_id) const { |
| 741 RtpStreamMap::const_iterator iter = rtp_stream_map_.find( | 741 RtpStreamMap::const_iterator iter = rtp_stream_map_.find( |
| 742 transport_id); | 742 transport_id); |
| 743 if (iter != rtp_stream_map_.end()) | 743 if (iter != rtp_stream_map_.end()) |
| 744 return iter->second.get(); | 744 return iter->second.get(); |
| 745 v8::Isolate* isolate = context()->v8_context()->GetIsolate(); | 745 v8::Isolate* isolate = context()->v8_context()->GetIsolate(); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 } | 964 } |
| 965 | 965 |
| 966 void CastStreamingNativeHandler::CallReceiverErrorCallback( | 966 void CastStreamingNativeHandler::CallReceiverErrorCallback( |
| 967 v8::CopyablePersistentTraits<v8::Function>::CopyablePersistent function, | 967 v8::CopyablePersistentTraits<v8::Function>::CopyablePersistent function, |
| 968 const std::string& error_message) { | 968 const std::string& error_message) { |
| 969 v8::Isolate* isolate = context()->v8_context()->GetIsolate(); | 969 v8::Isolate* isolate = context()->v8_context()->GetIsolate(); |
| 970 v8::Local<v8::Value> arg = v8::String::NewFromUtf8(isolate, | 970 v8::Local<v8::Value> arg = v8::String::NewFromUtf8(isolate, |
| 971 error_message.data(), | 971 error_message.data(), |
| 972 v8::String::kNormalString, | 972 v8::String::kNormalString, |
| 973 error_message.size()); | 973 error_message.size()); |
| 974 context()->CallFunction( | 974 context()->SafeCallFunction(v8::Local<v8::Function>::New(isolate, function), |
| 975 v8::Local<v8::Function>::New(isolate, function), 1, &arg); | 975 1, &arg); |
| 976 } | 976 } |
| 977 | 977 |
| 978 void CastStreamingNativeHandler::AddTracksToMediaStream( | 978 void CastStreamingNativeHandler::AddTracksToMediaStream( |
| 979 const std::string& url, | 979 const std::string& url, |
| 980 const media::AudioParameters& params, | 980 const media::AudioParameters& params, |
| 981 scoped_refptr<media::AudioCapturerSource> audio, | 981 scoped_refptr<media::AudioCapturerSource> audio, |
| 982 std::unique_ptr<media::VideoCapturerSource> video) { | 982 std::unique_ptr<media::VideoCapturerSource> video) { |
| 983 blink::WebMediaStream web_stream = | 983 blink::WebMediaStream web_stream = |
| 984 blink::WebMediaStreamRegistry::lookupMediaStreamDescriptor(GURL(url)); | 984 blink::WebMediaStreamRegistry::lookupMediaStreamDescriptor(GURL(url)); |
| 985 if (web_stream.isNull()) { | 985 if (web_stream.isNull()) { |
| 986 LOG(DFATAL) << "Stream not found."; | 986 LOG(DFATAL) << "Stream not found."; |
| 987 return; | 987 return; |
| 988 } | 988 } |
| 989 if (!content::AddAudioTrackToMediaStream( | 989 if (!content::AddAudioTrackToMediaStream( |
| 990 audio, params.sample_rate(), params.channel_layout(), | 990 audio, params.sample_rate(), params.channel_layout(), |
| 991 params.frames_per_buffer(), true, // is_remote | 991 params.frames_per_buffer(), true, // is_remote |
| 992 true, // is_readonly | 992 true, // is_readonly |
| 993 &web_stream)) { | 993 &web_stream)) { |
| 994 LOG(ERROR) << "Failed to add Cast audio track to media stream."; | 994 LOG(ERROR) << "Failed to add Cast audio track to media stream."; |
| 995 } | 995 } |
| 996 if (!content::AddVideoTrackToMediaStream(std::move(video), true, // is_remote | 996 if (!content::AddVideoTrackToMediaStream(std::move(video), true, // is_remote |
| 997 true, // is_readonly | 997 true, // is_readonly |
| 998 &web_stream)) { | 998 &web_stream)) { |
| 999 LOG(ERROR) << "Failed to add Cast video track to media stream."; | 999 LOG(ERROR) << "Failed to add Cast video track to media stream."; |
| 1000 } | 1000 } |
| 1001 } | 1001 } |
| 1002 | 1002 |
| 1003 } // namespace extensions | 1003 } // namespace extensions |
| OLD | NEW |