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 <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 } // namespace transport | 35 } // namespace transport |
36 } // namespace cast | 36 } // namespace cast |
37 } // namespace media | 37 } // namespace media |
38 | 38 |
39 // This class hosts CastSender and connects it to audio/video frame input | 39 // This class hosts CastSender and connects it to audio/video frame input |
40 // and network socket. | 40 // and network socket. |
41 // This class is created on the render thread and destroyed on the IO | 41 // This class is created on the render thread and destroyed on the IO |
42 // thread. All methods are accessible only on the IO thread. | 42 // thread. All methods are accessible only on the IO thread. |
43 class CastSessionDelegate { | 43 class CastSessionDelegate { |
44 public: | 44 public: |
45 typedef base::Callback<void(const scoped_refptr<media::cast::FrameInput>&)> | 45 typedef base::Callback<void(const scoped_refptr< |
46 FrameInputAvailableCallback; | 46 media::cast::AudioFrameInput>&)> AudioFrameInputAvailableCallback; |
| 47 typedef base::Callback<void(const scoped_refptr< |
| 48 media::cast::VideoFrameInput>&)> VideoFrameInputAvailableCallback; |
47 typedef base::Callback<void(scoped_ptr<std::string>)> EventLogsCallback; | 49 typedef base::Callback<void(scoped_ptr<std::string>)> EventLogsCallback; |
48 | 50 |
49 CastSessionDelegate(); | 51 CastSessionDelegate(); |
50 virtual ~CastSessionDelegate(); | 52 virtual ~CastSessionDelegate(); |
51 | 53 |
| 54 // This will start the session by configuring and creating the Cast transport |
| 55 // and the Cast sender. |
| 56 // Must be called before initialization of audio or video. |
| 57 void StartUDP(const net::IPEndPoint& local_endpoint, |
| 58 const net::IPEndPoint& remote_endpoint); |
| 59 |
52 // After calling StartAudio() or StartVideo() encoding of that media will | 60 // After calling StartAudio() or StartVideo() encoding of that media will |
53 // begin as soon as data is delivered to its sink, if the second method is | 61 // begin as soon as data is delivered to its sink, if the second method is |
54 // called the first media will be restarted. It is strongly recommended not to | 62 // called the first media will be restarted. It is strongly recommended not to |
55 // deliver any data between calling the two methods. | 63 // deliver any data between calling the two methods. |
56 // It's OK to call only one of the two methods. | 64 // It's OK to call only one of the two methods. |
| 65 // StartUDP must be called before these methods. |
57 void StartAudio(const media::cast::AudioSenderConfig& config, | 66 void StartAudio(const media::cast::AudioSenderConfig& config, |
58 const FrameInputAvailableCallback& callback); | 67 const AudioFrameInputAvailableCallback& callback); |
59 void StartVideo(const media::cast::VideoSenderConfig& config, | 68 void StartVideo(const media::cast::VideoSenderConfig& config, |
60 const FrameInputAvailableCallback& callback); | 69 const VideoFrameInputAvailableCallback& callback); |
61 void StartUDP(const net::IPEndPoint& local_endpoint, | |
62 const net::IPEndPoint& remote_endpoint); | |
63 | 70 |
64 void ToggleLogging(bool is_audio, bool enable); | 71 void ToggleLogging(bool is_audio, bool enable); |
65 void GetEventLogsAndReset(bool is_audio, const EventLogsCallback& callback); | 72 void GetEventLogsAndReset(bool is_audio, const EventLogsCallback& callback); |
66 | 73 |
67 protected: | 74 protected: |
68 // Callback with the result of the initialization. | 75 // Callback with the result of the initialization. |
69 // If this callback is called with STATUS_INITIALIZED it will report back | 76 // If this callback is called with STATUS_INITIALIZED it will report back |
70 // to the sinks that it's ready to accept incoming audio / video frames. | 77 // to the sinks that it's ready to accept incoming audio / video frames. |
71 void InitializationResult(media::cast::CastInitializationStatus result) const; | 78 void InitializationResult(media::cast::CastInitializationStatus result) const; |
72 | 79 |
73 private: | 80 private: |
74 // Start encoding threads and initialize the CastEnvironment. | |
75 void Initialize(); | |
76 | |
77 // Configure CastSender. It is ready to accept audio / video frames after | |
78 // receiving a successful call to InitializationResult. | |
79 void StartSendingInternal(); | |
80 | |
81 void StatusNotificationCB( | 81 void StatusNotificationCB( |
82 media::cast::transport::CastTransportStatus status); | 82 media::cast::transport::CastTransportStatus status); |
83 | 83 |
84 base::ThreadChecker thread_checker_; | 84 base::ThreadChecker thread_checker_; |
85 scoped_refptr<media::cast::CastEnvironment> cast_environment_; | 85 scoped_refptr<media::cast::CastEnvironment> cast_environment_; |
86 scoped_ptr<media::cast::CastSender> cast_sender_; | 86 scoped_ptr<media::cast::CastSender> cast_sender_; |
87 scoped_ptr<media::cast::transport::CastTransportSender> cast_transport_; | 87 scoped_ptr<media::cast::transport::CastTransportSender> cast_transport_; |
88 | 88 |
89 // Configuration for audio and video. | 89 AudioFrameInputAvailableCallback audio_frame_input_available_callback_; |
90 scoped_ptr<media::cast::AudioSenderConfig> audio_config_; | 90 VideoFrameInputAvailableCallback video_frame_input_available_callback_; |
91 scoped_ptr<media::cast::VideoSenderConfig> video_config_; | |
92 | |
93 FrameInputAvailableCallback audio_frame_input_available_callback_; | |
94 FrameInputAvailableCallback video_frame_input_available_callback_; | |
95 | |
96 net::IPEndPoint local_endpoint_; | |
97 net::IPEndPoint remote_endpoint_; | |
98 bool transport_configured_; | |
99 | 91 |
100 scoped_ptr<media::cast::EncodingEventSubscriber> audio_event_subscriber_; | 92 scoped_ptr<media::cast::EncodingEventSubscriber> audio_event_subscriber_; |
101 scoped_ptr<media::cast::EncodingEventSubscriber> video_event_subscriber_; | 93 scoped_ptr<media::cast::EncodingEventSubscriber> video_event_subscriber_; |
102 | 94 |
103 // Proxy to the IO message loop. | 95 // Proxy to the IO message loop. |
104 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 96 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
105 base::WeakPtrFactory<CastSessionDelegate> weak_factory_; | 97 base::WeakPtrFactory<CastSessionDelegate> weak_factory_; |
106 | 98 |
107 DISALLOW_COPY_AND_ASSIGN(CastSessionDelegate); | 99 DISALLOW_COPY_AND_ASSIGN(CastSessionDelegate); |
108 }; | 100 }; |
109 | 101 |
110 #endif // CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_ | 102 #endif // CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_ |
OLD | NEW |