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_MEDIA_CAST_SESSION_DELEGATE_H_ | 5 #ifndef CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_ |
6 #define CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_ | 6 #define CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
12 #include "base/time/default_tick_clock.h" | 12 #include "base/time/default_tick_clock.h" |
| 13 #include "chrome/renderer/media/cast_session.h" |
| 14 #include "content/public/renderer/p2p_socket_client.h" |
| 15 #include "content/public/renderer/p2p_socket_client_delegate.h" |
13 #include "media/cast/cast_config.h" | 16 #include "media/cast/cast_config.h" |
| 17 #include "media/cast/cast_sender.h" |
14 | 18 |
15 namespace base { | 19 namespace base { |
16 class MessageLoopProxy; | 20 class MessageLoopProxy; |
17 } // namespace base | 21 } // namespace base |
18 | 22 |
19 namespace media { | |
20 namespace cast { | |
21 class CastEnvironment; | |
22 class CastSender; | |
23 } // namespace cast | |
24 } // namespace media | |
25 | |
26 // This class hosts CastSender and connects it to audio/video frame input | 23 // This class hosts CastSender and connects it to audio/video frame input |
27 // and network socket. | 24 // and network socket. |
28 // This class is created on the render thread and destroyed on the IO | 25 // This class is created on the render thread and destroyed on the IO |
29 // thread. All methods are accessible only on the IO thread. | 26 // thread. All methods are accessible only on the IO thread. |
30 class CastSessionDelegate { | 27 class CastSessionDelegate |
| 28 : public media::cast::PacketSender, |
| 29 public content::P2PSocketClientDelegate { |
31 public: | 30 public: |
32 CastSessionDelegate(); | 31 CastSessionDelegate(); |
33 ~CastSessionDelegate(); | 32 virtual ~CastSessionDelegate(); |
| 33 |
| 34 void SetSocketFactory( |
| 35 scoped_ptr<CastSession::P2PSocketFactory> socket_factory, |
| 36 const net::IPEndPoint& remote_address); |
34 | 37 |
35 // After calling StartAudio() and StartVideo() with configuration encoding | 38 // After calling StartAudio() and StartVideo() with configuration encoding |
36 // will begin. | 39 // will begin. |
37 void StartAudio(const media::cast::AudioSenderConfig& config); | 40 void StartAudio(const media::cast::AudioSenderConfig& config); |
38 void StartVideo(const media::cast::VideoSenderConfig& config); | 41 void StartVideo(const media::cast::VideoSenderConfig& config); |
39 | 42 |
40 private: | 43 private: |
41 // Start encoding threads and configure CastSender. It is ready to accept | 44 // Start encoding threads and configure CastSender. It is ready to accept |
42 // audio/video frames after this call. | 45 // audio/video frames after this call. |
43 void StartSending(); | 46 void StartSending(); |
44 | 47 |
45 // If both audio and video are configured properly then start CastSender. | 48 // If both audio and video are configured properly then start CastSender. |
46 void MaybeStartSending(); | 49 void MaybeStartSending(); |
47 | 50 |
| 51 // media::cast::PacketSender Implementation |
| 52 virtual bool SendPacket(const media::cast::Packet& packet) OVERRIDE; |
| 53 virtual bool SendPackets(const media::cast::PacketList& packets) OVERRIDE; |
| 54 |
| 55 // content::P2PSocketClient::Delegate Implementation |
| 56 virtual void OnOpen(const net::IPEndPoint& address) OVERRIDE; |
| 57 virtual void OnIncomingTcpConnection( |
| 58 const net::IPEndPoint& address, |
| 59 content::P2PSocketClient* client) OVERRIDE; |
| 60 virtual void OnSendComplete() OVERRIDE; |
| 61 virtual void OnError() OVERRIDE; |
| 62 virtual void OnDataReceived(const net::IPEndPoint& address, |
| 63 const std::vector<char>& data) OVERRIDE; |
| 64 private: |
48 base::ThreadChecker thread_checker_; | 65 base::ThreadChecker thread_checker_; |
49 scoped_refptr<media::cast::CastEnvironment> cast_environment_; | 66 scoped_refptr<media::cast::CastEnvironment> cast_environment_; |
50 scoped_ptr<media::cast::CastSender> cast_sender_; | 67 scoped_ptr<media::cast::CastSender> cast_sender_; |
| 68 scoped_ptr<CastSession::P2PSocketFactory> socket_factory_; |
| 69 net::IPEndPoint remote_address_; |
| 70 scoped_refptr<content::P2PSocketClient> socket_; |
51 | 71 |
52 // Utilities threads owned by this class. They are used by CastSender for | 72 // Utilities threads owned by this class. They are used by CastSender for |
53 // encoding. | 73 // encoding. |
54 // TODO(hclam): See crbug.com/317006 for more details. | 74 // TODO(hclam): See crbug.com/317006 for more details. |
55 // This class shouldn't create and own threads. | 75 // This class shouldn't create and own threads. |
56 base::Thread audio_encode_thread_; | 76 base::Thread audio_encode_thread_; |
57 base::Thread video_encode_thread_; | 77 base::Thread video_encode_thread_; |
58 | 78 |
59 // Clock used by CastSender. | 79 // Clock used by CastSender. |
60 base::DefaultTickClock clock_; | 80 base::DefaultTickClock clock_; |
61 | 81 |
62 // Configuration for audio and video. | 82 // Configuration for audio and video. |
63 media::cast::AudioSenderConfig audio_config_; | 83 media::cast::AudioSenderConfig audio_config_; |
64 media::cast::VideoSenderConfig video_config_; | 84 media::cast::VideoSenderConfig video_config_; |
65 bool audio_configured_; | 85 bool audio_configured_; |
66 bool video_configured_; | 86 bool video_configured_; |
67 | 87 |
68 // Proxy to the IO message loop. | 88 // Proxy to the IO message loop. |
69 const scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 89 const scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
70 | 90 |
71 DISALLOW_COPY_AND_ASSIGN(CastSessionDelegate); | 91 DISALLOW_COPY_AND_ASSIGN(CastSessionDelegate); |
72 }; | 92 }; |
73 | 93 |
74 #endif // CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_ | 94 #endif // CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_ |
OLD | NEW |