• 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_MEDIA_CAST_SESSION_H_
6 #define CHROME_RENDERER_MEDIA_CAST_SESSION_H_
7 
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "net/base/ip_endpoint.h"
13 
14 namespace base {
15 class MessageLoopProxy;
16 }  // namespace base
17 
18 namespace media {
19 class VideoFrame;
20 namespace cast {
21 class FrameInput;
22 struct AudioSenderConfig;
23 struct VideoSenderConfig;
24 }  // namespace cast
25 }  // namespace media
26 
27 namespace content{
28 class P2PSocketClient;
29 }  // namespace content
30 
31 class CastSessionDelegate;
32 
33 // This class represents a Cast session and allows the session to be
34 // configured on the main thread. Actual work is forwarded to
35 // CastSessionDelegate on the IO thread.
36 class CastSession : public base::RefCounted<CastSession> {
37  public:
38   typedef
39   base::Callback<void(const scoped_refptr<media::cast::FrameInput>&)>
40   FrameInputAvailableCallback;
41 
42   CastSession();
43 
44   // Start encoding of audio and video using the provided configuration.
45   //
46   // When Cast sender is started and ready to be used
47   // media::cast::FrameInput will be given through the callback. The
48   // callback will be made on the main thread.
49   void StartAudio(const media::cast::AudioSenderConfig& config,
50                   const FrameInputAvailableCallback& callback);
51   void StartVideo(const media::cast::VideoSenderConfig& config,
52                   const FrameInputAvailableCallback& callback);
53 
54   class P2PSocketFactory {
55    public:
56     virtual ~P2PSocketFactory();
57 
58     // Called on IO thread.
59     virtual scoped_refptr<content::P2PSocketClient> Create() = 0;
60   };
61 
62   // Send the socket factory to the delegate, where create will be
63   // called. The delegate will then delete the socket factory on the
64   // IO thread. We do it this way because the P2P socket needs to
65   // be created on the same thread that the callbacks will be called on.
66   // The |remote_endpoint| is the address will be used when calling
67   // SendWithDscp on the P2PSocketClient.
68   // Takes ownership of socket_factory.
69   void SetSocketFactory(scoped_ptr<P2PSocketFactory> socket_factory,
70                         const net::IPEndPoint& remote_address);
71 
72  private:
73   friend class base::RefCounted<CastSession>;
74   virtual ~CastSession();
75 
76   // This member should never be dereferenced on the main thread.
77   // CastSessionDelegate lives only on the IO thread. It is always
78   // safe to post task on the IO thread to access CastSessionDelegate
79   // because it is owned by this object.
80   scoped_ptr<CastSessionDelegate> delegate_;
81 
82   // Proxy to the IO message loop.
83   const scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
84 
85   DISALLOW_COPY_AND_ASSIGN(CastSession);
86 };
87 
88 #endif  // CHROME_RENDERER_MEDIA_CAST_SESSION_H_
89