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 // Callback called after a cast receiver has been started. Adds the | |
90 // output audio/video streams to the MediaStream specified by |url|. | |
91 void AddTracksToMediaStream( | |
92 const std::string& url, | |
93 const media::AudioParameters& params, | |
94 scoped_refptr<media::AudioCapturerSource> audio, | |
95 scoped_ptr<media::VideoCapturerSource> video); | |
96 | |
97 // |function| is a javascript function that will take |error_message| as | |
98 // an argument. Called when something goes wrong in a cast receiver. | |
99 void CallReceiverErrorCallback( | |
100 v8::CopyablePersistentTraits<v8::Function>::CopyablePersistent function, | |
101 const std::string& error_message); | |
102 | |
70 void CallGetRawEventsCallback(int transport_id, | 103 void CallGetRawEventsCallback(int transport_id, |
71 scoped_ptr<base::BinaryValue> raw_events); | 104 scoped_ptr<base::BinaryValue> raw_events); |
72 void CallGetStatsCallback(int transport_id, | 105 void CallGetStatsCallback(int transport_id, |
73 scoped_ptr<base::DictionaryValue> stats); | 106 scoped_ptr<base::DictionaryValue> stats); |
74 | 107 |
75 // Gets the RTP stream or UDP transport indexed by an ID. | 108 // Gets the RTP stream or UDP transport indexed by an ID. |
76 // If not found, returns NULL and throws a V8 exception. | 109 // If not found, returns NULL and throws a V8 exception. |
77 CastRtpStream* GetRtpStreamOrThrow(int stream_id) const; | 110 CastRtpStream* GetRtpStreamOrThrow(int stream_id) const; |
78 CastUdpTransport* GetUdpTransportOrThrow(int transport_id) const; | 111 CastUdpTransport* GetUdpTransportOrThrow(int transport_id) const; |
79 | 112 |
113 // Fills out a media::cast::FrameReceiverConfig from the v8 | |
114 // equivialent. (cast.streaming.receiverSession.RrtpReciverParams) | |
Yoyo Zhou
2015/03/04 23:31:33
check the spelling of this function
| |
115 // Returns true if everything was ok, raises a v8 exception and | |
116 // returns false if anything went wrong. | |
117 bool FrameReceiverConfigFromArg( | |
118 v8::Isolate* isolate, | |
119 const v8::Handle<v8::Value>& arg, | |
120 media::cast::FrameReceiverConfig* config); | |
121 | |
122 bool IPEndPointFromArg(v8::Isolate* isolate, | |
123 const v8::Handle<v8::Value>& arg, | |
124 net::IPEndPoint* ip_endpoint); | |
125 | |
80 int last_transport_id_; | 126 int last_transport_id_; |
81 | 127 |
82 typedef std::map<int, linked_ptr<CastRtpStream> > RtpStreamMap; | 128 typedef std::map<int, linked_ptr<CastRtpStream> > RtpStreamMap; |
83 RtpStreamMap rtp_stream_map_; | 129 RtpStreamMap rtp_stream_map_; |
84 | 130 |
85 typedef std::map<int, linked_ptr<CastUdpTransport> > UdpTransportMap; | 131 typedef std::map<int, linked_ptr<CastUdpTransport> > UdpTransportMap; |
86 UdpTransportMap udp_transport_map_; | 132 UdpTransportMap udp_transport_map_; |
87 | 133 |
88 extensions::ScopedPersistent<v8::Function> create_callback_; | 134 extensions::ScopedPersistent<v8::Function> create_callback_; |
89 | 135 |
90 typedef std::map<int, | 136 typedef std::map<int, |
91 linked_ptr<extensions::ScopedPersistent<v8::Function> > > | 137 linked_ptr<extensions::ScopedPersistent<v8::Function> > > |
92 RtpStreamCallbackMap; | 138 RtpStreamCallbackMap; |
93 RtpStreamCallbackMap get_raw_events_callbacks_; | 139 RtpStreamCallbackMap get_raw_events_callbacks_; |
94 RtpStreamCallbackMap get_stats_callbacks_; | 140 RtpStreamCallbackMap get_stats_callbacks_; |
95 | 141 |
96 base::WeakPtrFactory<CastStreamingNativeHandler> weak_factory_; | 142 base::WeakPtrFactory<CastStreamingNativeHandler> weak_factory_; |
97 | 143 |
98 DISALLOW_COPY_AND_ASSIGN(CastStreamingNativeHandler); | 144 DISALLOW_COPY_AND_ASSIGN(CastStreamingNativeHandler); |
99 }; | 145 }; |
100 | 146 |
101 } // namespace extensions | 147 } // namespace extensions |
102 | 148 |
103 #endif // CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_ | 149 #endif // CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_ |
OLD | NEW |