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