• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_
6 #define CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_
7 
8 #include <map>
9 
10 #include "base/memory/linked_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/renderer/extensions/object_backed_native_handler.h"
13 #include "chrome/renderer/extensions/scoped_persistent.h"
14 #include "v8/include/v8.h"
15 
16 class CastRtpStream;
17 class CastUdpTransport;
18 
19 namespace extensions {
20 
21 class ChromeV8Context;
22 
23 // Native code that handle chrome.webrtc custom bindings.
24 class CastStreamingNativeHandler : public ObjectBackedNativeHandler {
25  public:
26   explicit CastStreamingNativeHandler(ChromeV8Context* context);
27   virtual ~CastStreamingNativeHandler();
28 
29  private:
30   void CreateCastSession(
31       const v8::FunctionCallbackInfo<v8::Value>& args);
32 
33   void DestroyCastRtpStream(
34       const v8::FunctionCallbackInfo<v8::Value>& args);
35   void CreateParamsCastRtpStream(
36       const v8::FunctionCallbackInfo<v8::Value>& args);
37   void GetCapsCastRtpStream(
38       const v8::FunctionCallbackInfo<v8::Value>& args);
39   void StartCastRtpStream(
40       const v8::FunctionCallbackInfo<v8::Value>& args);
41   void StopCastRtpStream(
42       const v8::FunctionCallbackInfo<v8::Value>& args);
43 
44   void DestroyCastUdpTransport(
45       const v8::FunctionCallbackInfo<v8::Value>& args);
46   void StartCastUdpTransport(
47       const v8::FunctionCallbackInfo<v8::Value>& args);
48   void StopCastUdpTransport(
49       const v8::FunctionCallbackInfo<v8::Value>& args);
50 
51   // Helper method to call the v8 callback function after a session is
52   // created.
53   void CallCreateCallback(scoped_ptr<CastRtpStream> stream1,
54                           scoped_ptr<CastRtpStream> stream2,
55                           scoped_ptr<CastUdpTransport> udp_transport);
56 
57   // Gets the RTP stream or UDP transport indexed by an ID.
58   // If not found, returns NULL and throws a V8 exception.
59   CastRtpStream* GetRtpStreamOrThrow(int stream_id) const;
60   CastUdpTransport* GetUdpTransportOrThrow(int transport_id) const;
61 
62   int last_transport_id_;
63 
64   typedef std::map<int, linked_ptr<CastRtpStream> > RtpStreamMap;
65   RtpStreamMap rtp_stream_map_;
66 
67   typedef std::map<int, linked_ptr<CastUdpTransport> > UdpTransportMap;
68   UdpTransportMap udp_transport_map_;
69 
70   base::WeakPtrFactory<CastStreamingNativeHandler> weak_factory_;
71 
72   extensions::ScopedPersistent<v8::Function> create_callback_;
73 
74   DISALLOW_COPY_AND_ASSIGN(CastStreamingNativeHandler);
75 };
76 
77 }  // namespace extensions
78 
79 #endif  // CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_
80