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 21 matching lines...) Expand all Loading... |
32 class CastEnvironment; | 32 class CastEnvironment; |
33 class FrameInput; | 33 class FrameInput; |
34 class RawEventSubscriberBundle; | 34 class RawEventSubscriberBundle; |
35 | 35 |
36 namespace transport { | 36 namespace transport { |
37 class CastTransportSender; | 37 class CastTransportSender; |
38 } // namespace transport | 38 } // namespace transport |
39 } // namespace cast | 39 } // namespace cast |
40 } // namespace media | 40 } // namespace media |
41 | 41 |
| 42 // Breaks out functionality that is common between. |
| 43 class CastSessionDelegateBase { |
| 44 public: |
| 45 CastSessionDelegateBase(); |
| 46 virtual ~CastSessionDelegateBase(); |
| 47 |
| 48 // This will start the session by configuring and creating the Cast transport |
| 49 // and the Cast sender. |
| 50 // Must be called before initialization of audio or video. |
| 51 void StartUDP(const net::IPEndPoint& local_endpoint, |
| 52 const net::IPEndPoint& remote_endpoint, |
| 53 scoped_ptr<base::DictionaryValue> options); |
| 54 |
| 55 protected: |
| 56 void StatusNotificationCB( |
| 57 media::cast::CastTransportStatus status); |
| 58 virtual void LogRawEvents( |
| 59 const std::vector<media::cast::PacketEvent>& packet_events, |
| 60 const std::vector<media::cast::FrameEvent>& frame_events) = 0; |
| 61 |
| 62 base::ThreadChecker thread_checker_; |
| 63 scoped_refptr<media::cast::CastEnvironment> cast_environment_; |
| 64 scoped_ptr<media::cast::CastTransportSender> cast_transport_; |
| 65 |
| 66 // Proxy to the IO message loop. |
| 67 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
| 68 base::WeakPtrFactory<CastSessionDelegateBase> weak_factory_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(CastSessionDelegateBase); |
| 71 }; |
| 72 |
42 // This class hosts CastSender and connects it to audio/video frame input | 73 // This class hosts CastSender and connects it to audio/video frame input |
43 // and network socket. | 74 // and network socket. |
44 // This class is created on the render thread and destroyed on the IO | 75 // This class is created on the render thread and destroyed on the IO |
45 // thread. All methods are accessible only on the IO thread. | 76 // thread. All methods are accessible only on the IO thread. |
46 class CastSessionDelegate { | 77 class CastSessionDelegate : public CastSessionDelegateBase { |
47 public: | 78 public: |
48 typedef base::Callback<void(const scoped_refptr< | 79 typedef base::Callback<void(const scoped_refptr< |
49 media::cast::AudioFrameInput>&)> AudioFrameInputAvailableCallback; | 80 media::cast::AudioFrameInput>&)> AudioFrameInputAvailableCallback; |
50 typedef base::Callback<void(const scoped_refptr< | 81 typedef base::Callback<void(const scoped_refptr< |
51 media::cast::VideoFrameInput>&)> VideoFrameInputAvailableCallback; | 82 media::cast::VideoFrameInput>&)> VideoFrameInputAvailableCallback; |
52 typedef base::Callback<void(scoped_ptr<base::BinaryValue>)> EventLogsCallback; | 83 typedef base::Callback<void(scoped_ptr<base::BinaryValue>)> EventLogsCallback; |
53 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> StatsCallback; | 84 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> StatsCallback; |
54 typedef base::Callback<void(const std::string&)> ErrorCallback; | 85 typedef base::Callback<void(const std::string&)> ErrorCallback; |
55 | 86 |
56 CastSessionDelegate(); | 87 CastSessionDelegate(); |
57 virtual ~CastSessionDelegate(); | 88 ~CastSessionDelegate() override; |
58 | 89 |
59 // This will start the session by configuring and creating the Cast transport | 90 void StartUDP(const net::IPEndPoint& local_endpoint, |
60 // and the Cast sender. | 91 const net::IPEndPoint& remote_endpoint, |
61 // Must be called before initialization of audio or video. | |
62 void StartUDP(const net::IPEndPoint& remote_endpoint, | |
63 scoped_ptr<base::DictionaryValue> options); | 92 scoped_ptr<base::DictionaryValue> options); |
64 | 93 |
65 // After calling StartAudio() or StartVideo() encoding of that media will | 94 // After calling StartAudio() or StartVideo() encoding of that media will |
66 // begin as soon as data is delivered to its sink, if the second method is | 95 // begin as soon as data is delivered to its sink, if the second method is |
67 // called the first media will be restarted. It is strongly recommended not to | 96 // called the first media will be restarted. It is strongly recommended not to |
68 // deliver any data between calling the two methods. | 97 // deliver any data between calling the two methods. |
69 // It's OK to call only one of the two methods. | 98 // It's OK to call only one of the two methods. |
70 // StartUDP must be called before these methods. | 99 // StartUDP must be called before these methods. |
71 void StartAudio(const media::cast::AudioSenderConfig& config, | 100 void StartAudio(const media::cast::AudioSenderConfig& config, |
72 const AudioFrameInputAvailableCallback& callback, | 101 const AudioFrameInputAvailableCallback& callback, |
(...skipping 14 matching lines...) Expand all Loading... |
87 | 116 |
88 protected: | 117 protected: |
89 // Callback with the result of the initialization. | 118 // Callback with the result of the initialization. |
90 // If this callback is called with STATUS_INITIALIZED it will report back | 119 // If this callback is called with STATUS_INITIALIZED it will report back |
91 // to the sinks that it's ready to accept incoming audio / video frames. | 120 // to the sinks that it's ready to accept incoming audio / video frames. |
92 void InitializationResultCB( | 121 void InitializationResultCB( |
93 const ErrorCallback& error_callback, | 122 const ErrorCallback& error_callback, |
94 media::cast::CastInitializationStatus result) const; | 123 media::cast::CastInitializationStatus result) const; |
95 | 124 |
96 private: | 125 private: |
97 void StatusNotificationCB( | |
98 media::cast::CastTransportStatus status); | |
99 | |
100 // Adds logs collected from transport on browser side. | 126 // Adds logs collected from transport on browser side. |
101 void LogRawEvents(const std::vector<media::cast::PacketEvent>& packet_events, | 127 void LogRawEvents(const std::vector<media::cast::PacketEvent>& packet_events, |
102 const std::vector<media::cast::FrameEvent>& frame_events); | 128 const std::vector<media::cast::FrameEvent>& frame_events) |
| 129 override; |
103 | 130 |
104 base::ThreadChecker thread_checker_; | |
105 scoped_refptr<media::cast::CastEnvironment> cast_environment_; | |
106 scoped_ptr<media::cast::CastSender> cast_sender_; | 131 scoped_ptr<media::cast::CastSender> cast_sender_; |
107 scoped_ptr<media::cast::CastTransportSender> cast_transport_; | |
108 | 132 |
109 AudioFrameInputAvailableCallback audio_frame_input_available_callback_; | 133 AudioFrameInputAvailableCallback audio_frame_input_available_callback_; |
110 VideoFrameInputAvailableCallback video_frame_input_available_callback_; | 134 VideoFrameInputAvailableCallback video_frame_input_available_callback_; |
111 | 135 |
112 scoped_ptr<media::cast::RawEventSubscriberBundle> event_subscribers_; | 136 scoped_ptr<media::cast::RawEventSubscriberBundle> event_subscribers_; |
113 | 137 |
114 // Proxy to the IO message loop. | |
115 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | |
116 base::WeakPtrFactory<CastSessionDelegate> weak_factory_; | 138 base::WeakPtrFactory<CastSessionDelegate> weak_factory_; |
117 | 139 |
118 DISALLOW_COPY_AND_ASSIGN(CastSessionDelegate); | 140 DISALLOW_COPY_AND_ASSIGN(CastSessionDelegate); |
119 }; | 141 }; |
120 | 142 |
121 #endif // CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_ | 143 #endif // CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_ |
OLD | NEW |