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 #include "chrome/renderer/media/cast_session_delegate.h" | 5 #include "chrome/renderer/media/cast_session_delegate.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "chrome/common/chrome_version_info.h" | 10 #include "chrome/common/chrome_version_info.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 if (!cast_transport_ || !cast_sender_) { | 49 if (!cast_transport_ || !cast_sender_) { |
50 error_callback.Run("Destination not set."); | 50 error_callback.Run("Destination not set."); |
51 return; | 51 return; |
52 } | 52 } |
53 | 53 |
54 audio_frame_input_available_callback_ = callback; | 54 audio_frame_input_available_callback_ = callback; |
55 cast_sender_->InitializeAudio( | 55 cast_sender_->InitializeAudio( |
56 config, | 56 config, |
57 base::Bind(&CastSessionDelegate::InitializationResultCB, | 57 base::Bind(&CastSessionDelegate::InitializationResultCB, |
58 weak_factory_.GetWeakPtr())); | 58 weak_factory_.GetWeakPtr(), error_callback)); |
59 } | 59 } |
60 | 60 |
61 void CastSessionDelegate::StartVideo( | 61 void CastSessionDelegate::StartVideo( |
62 const VideoSenderConfig& config, | 62 const VideoSenderConfig& config, |
63 const VideoFrameInputAvailableCallback& callback, | 63 const VideoFrameInputAvailableCallback& callback, |
64 const ErrorCallback& error_callback, | 64 const ErrorCallback& error_callback, |
65 const media::cast::CreateVideoEncodeAcceleratorCallback& create_vea_cb, | 65 const media::cast::CreateVideoEncodeAcceleratorCallback& create_vea_cb, |
66 const media::cast::CreateVideoEncodeMemoryCallback& | 66 const media::cast::CreateVideoEncodeMemoryCallback& |
67 create_video_encode_mem_cb) { | 67 create_video_encode_mem_cb) { |
68 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 68 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
69 | 69 |
70 if (!cast_transport_ || !cast_sender_) { | 70 if (!cast_transport_ || !cast_sender_) { |
71 error_callback.Run("Destination not set."); | 71 error_callback.Run("Destination not set."); |
72 return; | 72 return; |
73 } | 73 } |
74 | 74 |
75 video_frame_input_available_callback_ = callback; | 75 video_frame_input_available_callback_ = callback; |
76 | 76 |
77 cast_sender_->InitializeVideo( | 77 cast_sender_->InitializeVideo( |
78 config, | 78 config, |
79 base::Bind(&CastSessionDelegate::InitializationResultCB, | 79 base::Bind(&CastSessionDelegate::InitializationResultCB, |
80 weak_factory_.GetWeakPtr()), | 80 weak_factory_.GetWeakPtr(), error_callback), |
81 create_vea_cb, | 81 create_vea_cb, |
82 create_video_encode_mem_cb); | 82 create_video_encode_mem_cb); |
83 } | 83 } |
84 | 84 |
85 void CastSessionDelegate::StartUDP(const net::IPEndPoint& remote_endpoint) { | 85 void CastSessionDelegate::StartUDP(const net::IPEndPoint& remote_endpoint) { |
86 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 86 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
87 | 87 |
88 // CastSender uses the renderer's IO thread as the main thread. This reduces | 88 // CastSender uses the renderer's IO thread as the main thread. This reduces |
89 // thread hopping for incoming video frames and outgoing network packets. | 89 // thread hopping for incoming video frames and outgoing network packets. |
90 cast_environment_ = new CastEnvironment( | 90 cast_environment_ = new CastEnvironment( |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 callback.Run(stats.Pass()); | 196 callback.Run(stats.Pass()); |
197 } | 197 } |
198 | 198 |
199 void CastSessionDelegate::StatusNotificationCB( | 199 void CastSessionDelegate::StatusNotificationCB( |
200 media::cast::CastTransportStatus unused_status) { | 200 media::cast::CastTransportStatus unused_status) { |
201 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 201 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
202 // TODO(hubbe): Call javascript UDPTransport error function. | 202 // TODO(hubbe): Call javascript UDPTransport error function. |
203 } | 203 } |
204 | 204 |
205 void CastSessionDelegate::InitializationResultCB( | 205 void CastSessionDelegate::InitializationResultCB( |
| 206 const ErrorCallback& error_callback, |
206 media::cast::CastInitializationStatus result) const { | 207 media::cast::CastInitializationStatus result) const { |
207 DCHECK(cast_sender_); | 208 DCHECK(cast_sender_); |
208 | 209 |
209 // TODO(pwestin): handle the error codes. | 210 switch (result) { |
210 if (result == media::cast::STATUS_AUDIO_INITIALIZED) { | 211 case media::cast::STATUS_AUDIO_INITIALIZED: |
211 audio_frame_input_available_callback_.Run( | 212 audio_frame_input_available_callback_.Run( |
212 cast_sender_->audio_frame_input()); | 213 cast_sender_->audio_frame_input()); |
213 } else if (result == media::cast::STATUS_VIDEO_INITIALIZED) { | 214 break; |
214 video_frame_input_available_callback_.Run( | 215 case media::cast::STATUS_VIDEO_INITIALIZED: |
215 cast_sender_->video_frame_input()); | 216 video_frame_input_available_callback_.Run( |
| 217 cast_sender_->video_frame_input()); |
| 218 break; |
| 219 case media::cast::STATUS_INVALID_CAST_ENVIRONMENT: |
| 220 error_callback.Run("Invalid cast environment."); |
| 221 break; |
| 222 case media::cast::STATUS_INVALID_CRYPTO_CONFIGURATION: |
| 223 error_callback.Run("Invalid encryption keys."); |
| 224 break; |
| 225 case media::cast::STATUS_UNSUPPORTED_AUDIO_CODEC: |
| 226 error_callback.Run("Audio codec not supported."); |
| 227 break; |
| 228 case media::cast::STATUS_UNSUPPORTED_VIDEO_CODEC: |
| 229 error_callback.Run("Video codec not supported."); |
| 230 break; |
| 231 case media::cast::STATUS_INVALID_AUDIO_CONFIGURATION: |
| 232 error_callback.Run("Invalid audio configuration."); |
| 233 break; |
| 234 case media::cast::STATUS_INVALID_VIDEO_CONFIGURATION: |
| 235 error_callback.Run("Invalid video configuration."); |
| 236 break; |
| 237 case media::cast::STATUS_HW_VIDEO_ENCODER_NOT_SUPPORTED: |
| 238 error_callback.Run("Hardware video encoder not supported."); |
| 239 break; |
| 240 case media::cast::STATUS_AUDIO_UNINITIALIZED: |
| 241 case media::cast::STATUS_VIDEO_UNINITIALIZED: |
| 242 NOTREACHED() << "Not an error."; |
| 243 break; |
216 } | 244 } |
217 } | 245 } |
218 | 246 |
219 void CastSessionDelegate::LogRawEvents( | 247 void CastSessionDelegate::LogRawEvents( |
220 const std::vector<media::cast::PacketEvent>& packet_events, | 248 const std::vector<media::cast::PacketEvent>& packet_events, |
221 const std::vector<media::cast::FrameEvent>& frame_events) { | 249 const std::vector<media::cast::FrameEvent>& frame_events) { |
222 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 250 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
223 | 251 |
224 for (std::vector<media::cast::PacketEvent>::const_iterator it = | 252 for (std::vector<media::cast::PacketEvent>::const_iterator it = |
225 packet_events.begin(); | 253 packet_events.begin(); |
(...skipping 23 matching lines...) Expand all Loading... |
249 } else { | 277 } else { |
250 cast_environment_->Logging()->InsertFrameEvent( | 278 cast_environment_->Logging()->InsertFrameEvent( |
251 it->timestamp, | 279 it->timestamp, |
252 it->type, | 280 it->type, |
253 it->media_type, | 281 it->media_type, |
254 it->rtp_timestamp, | 282 it->rtp_timestamp, |
255 it->frame_id); | 283 it->frame_id); |
256 } | 284 } |
257 } | 285 } |
258 } | 286 } |
OLD | NEW |