| 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 #ifndef CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_ |
| 6 #define CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "extensions/renderer/object_backed_native_handler.h" | 12 #include "extensions/renderer/object_backed_native_handler.h" |
| 13 #include "extensions/renderer/scoped_persistent.h" | 13 #include "extensions/renderer/scoped_persistent.h" |
| 14 #include "v8/include/v8.h" | 14 #include "v8/include/v8.h" |
| 15 | 15 |
| 16 class CastRtpStream; | 16 class CastRtpStream; |
| 17 class CastUdpTransport; | 17 class CastUdpTransport; |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 class BinaryValue; | 20 class BinaryValue; |
| 21 class DictionaryValue; | 21 class DictionaryValue; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace blink { |
| 25 class WebMediaStream; |
| 26 } |
| 27 |
| 28 namespace net { |
| 29 class IPEndPoint; |
| 30 } |
| 31 |
| 32 namespace media { |
| 33 class AudioCapturerSource; |
| 34 class AudioParameters; |
| 35 class VideoCapturerSource; |
| 36 namespace cast { |
| 37 struct FrameReceiverConfig; |
| 38 } |
| 39 } |
| 40 |
| 24 namespace extensions { | 41 namespace extensions { |
| 25 | 42 |
| 26 // Native code that handle chrome.webrtc custom bindings. | 43 // Native code that handle chrome.webrtc custom bindings. |
| 27 class CastStreamingNativeHandler : public ObjectBackedNativeHandler { | 44 class CastStreamingNativeHandler : public ObjectBackedNativeHandler { |
| 28 public: | 45 public: |
| 29 explicit CastStreamingNativeHandler(ScriptContext* context); | 46 explicit CastStreamingNativeHandler(ScriptContext* context); |
| 30 ~CastStreamingNativeHandler() override; | 47 ~CastStreamingNativeHandler() override; |
| 31 | 48 |
| 32 private: | 49 private: |
| 33 void CreateCastSession( | 50 void CreateCastSession( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 45 const v8::FunctionCallbackInfo<v8::Value>& args); | 62 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 46 | 63 |
| 47 void DestroyCastUdpTransport( | 64 void DestroyCastUdpTransport( |
| 48 const v8::FunctionCallbackInfo<v8::Value>& args); | 65 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 49 void SetDestinationCastUdpTransport( | 66 void SetDestinationCastUdpTransport( |
| 50 const v8::FunctionCallbackInfo<v8::Value>& args); | 67 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 51 void SetOptionsCastUdpTransport( | 68 void SetOptionsCastUdpTransport( |
| 52 const v8::FunctionCallbackInfo<v8::Value>& args); | 69 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 53 void StopCastUdpTransport( | 70 void StopCastUdpTransport( |
| 54 const v8::FunctionCallbackInfo<v8::Value>& args); | 71 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 72 void StartCastRtpReceiver( |
| 73 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 55 | 74 |
| 56 void ToggleLogging(const v8::FunctionCallbackInfo<v8::Value>& args); | 75 void ToggleLogging(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 57 void GetRawEvents(const v8::FunctionCallbackInfo<v8::Value>& args); | 76 void GetRawEvents(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 58 void GetStats(const v8::FunctionCallbackInfo<v8::Value>& args); | 77 void GetStats(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 59 | 78 |
| 60 // Helper method to call the v8 callback function after a session is | 79 // Helper method to call the v8 callback function after a session is |
| 61 // created. | 80 // created. |
| 62 void CallCreateCallback(scoped_ptr<CastRtpStream> stream1, | 81 void CallCreateCallback(scoped_ptr<CastRtpStream> stream1, |
| 63 scoped_ptr<CastRtpStream> stream2, | 82 scoped_ptr<CastRtpStream> stream2, |
| 64 scoped_ptr<CastUdpTransport> udp_transport); | 83 scoped_ptr<CastUdpTransport> udp_transport); |
| 65 | 84 |
| 66 void CallStartCallback(int stream_id); | 85 void CallStartCallback(int stream_id); |
| 67 void CallStopCallback(int stream_id); | 86 void CallStopCallback(int stream_id); |
| 68 void CallErrorCallback(int stream_id, const std::string& message); | 87 void CallErrorCallback(int stream_id, const std::string& message); |
| 69 | 88 |
| 89 void AddTracksToMediaStream( |
| 90 const std::string& url, |
| 91 const media::AudioParameters& params, |
| 92 scoped_refptr<media::AudioCapturerSource> audio, |
| 93 scoped_ptr<media::VideoCapturerSource> video); |
| 94 void CallReceiverErrorCallback( |
| 95 v8::CopyablePersistentTraits<v8::Function>::CopyablePersistent function, |
| 96 const std::string& error_message); |
| 97 |
| 70 void CallGetRawEventsCallback(int transport_id, | 98 void CallGetRawEventsCallback(int transport_id, |
| 71 scoped_ptr<base::BinaryValue> raw_events); | 99 scoped_ptr<base::BinaryValue> raw_events); |
| 72 void CallGetStatsCallback(int transport_id, | 100 void CallGetStatsCallback(int transport_id, |
| 73 scoped_ptr<base::DictionaryValue> stats); | 101 scoped_ptr<base::DictionaryValue> stats); |
| 74 | 102 |
| 75 // Gets the RTP stream or UDP transport indexed by an ID. | 103 // Gets the RTP stream or UDP transport indexed by an ID. |
| 76 // If not found, returns NULL and throws a V8 exception. | 104 // If not found, returns NULL and throws a V8 exception. |
| 77 CastRtpStream* GetRtpStreamOrThrow(int stream_id) const; | 105 CastRtpStream* GetRtpStreamOrThrow(int stream_id) const; |
| 78 CastUdpTransport* GetUdpTransportOrThrow(int transport_id) const; | 106 CastUdpTransport* GetUdpTransportOrThrow(int transport_id) const; |
| 79 | 107 |
| 108 bool FrameReceiverConfigFromArg( |
| 109 v8::Isolate* isolate, |
| 110 const v8::Handle<v8::Value>& arg, |
| 111 media::cast::FrameReceiverConfig* config); |
| 112 |
| 113 bool IPEndPointFromArg(v8::Isolate* isolate, |
| 114 const v8::Handle<v8::Value>& arg, |
| 115 bool empty_ok, |
| 116 net::IPEndPoint* ip_endpoint); |
| 117 |
| 80 int last_transport_id_; | 118 int last_transport_id_; |
| 81 | 119 |
| 82 typedef std::map<int, linked_ptr<CastRtpStream> > RtpStreamMap; | 120 typedef std::map<int, linked_ptr<CastRtpStream> > RtpStreamMap; |
| 83 RtpStreamMap rtp_stream_map_; | 121 RtpStreamMap rtp_stream_map_; |
| 84 | 122 |
| 85 typedef std::map<int, linked_ptr<CastUdpTransport> > UdpTransportMap; | 123 typedef std::map<int, linked_ptr<CastUdpTransport> > UdpTransportMap; |
| 86 UdpTransportMap udp_transport_map_; | 124 UdpTransportMap udp_transport_map_; |
| 87 | 125 |
| 88 extensions::ScopedPersistent<v8::Function> create_callback_; | 126 extensions::ScopedPersistent<v8::Function> create_callback_; |
| 89 | 127 |
| 90 typedef std::map<int, | 128 typedef std::map<int, |
| 91 linked_ptr<extensions::ScopedPersistent<v8::Function> > > | 129 linked_ptr<extensions::ScopedPersistent<v8::Function> > > |
| 92 RtpStreamCallbackMap; | 130 RtpStreamCallbackMap; |
| 93 RtpStreamCallbackMap get_raw_events_callbacks_; | 131 RtpStreamCallbackMap get_raw_events_callbacks_; |
| 94 RtpStreamCallbackMap get_stats_callbacks_; | 132 RtpStreamCallbackMap get_stats_callbacks_; |
| 95 | 133 |
| 96 base::WeakPtrFactory<CastStreamingNativeHandler> weak_factory_; | 134 base::WeakPtrFactory<CastStreamingNativeHandler> weak_factory_; |
| 97 | 135 |
| 98 DISALLOW_COPY_AND_ASSIGN(CastStreamingNativeHandler); | 136 DISALLOW_COPY_AND_ASSIGN(CastStreamingNativeHandler); |
| 99 }; | 137 }; |
| 100 | 138 |
| 101 } // namespace extensions | 139 } // namespace extensions |
| 102 | 140 |
| 103 #endif // CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_ | 141 #endif // CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_ |
| OLD | NEW |