Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1312)

Side by Side Diff: chrome/renderer/media/cast_session_delegate.cc

Issue 555563003: Cast: Flow hw encoder initialization error to extensions API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed comments and missing patch" Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 11 matching lines...) Expand all
22 #include "media/cast/net/cast_transport_sender.h" 22 #include "media/cast/net/cast_transport_sender.h"
23 23
24 using media::cast::AudioSenderConfig; 24 using media::cast::AudioSenderConfig;
25 using media::cast::CastEnvironment; 25 using media::cast::CastEnvironment;
26 using media::cast::CastSender; 26 using media::cast::CastSender;
27 using media::cast::VideoSenderConfig; 27 using media::cast::VideoSenderConfig;
28 28
29 static base::LazyInstance<CastThreads> g_cast_threads = 29 static base::LazyInstance<CastThreads> g_cast_threads =
30 LAZY_INSTANCE_INITIALIZER; 30 LAZY_INSTANCE_INITIALIZER;
31 31
32 namespace {
33
34 std::string CastErrorToString(media::cast::CastInitializationStatus status) {
35 switch (status) {
36 case media::cast::STATUS_INVALID_CAST_ENVIRONMENT:
37 return "Invalid cast environment.";
38 case media::cast::STATUS_INVALID_CRYPTO_CONFIGURATION:
39 return "Invalid encryption keys.";
40 case media::cast::STATUS_UNSUPPORTED_AUDIO_CODEC:
41 return "Audio codec not supported.";
42 case media::cast::STATUS_UNSUPPORTED_VIDEO_CODEC:
43 return "Video codec not supported.";
44 case media::cast::STATUS_INVALID_AUDIO_CONFIGURATION:
45 return "Invalid audio configuration.";
46 case media::cast::STATUS_INVALID_VIDEO_CONFIGURATION:
47 return "Invalid video configuration.";
48 case media::cast::STATUS_HW_VIDEO_ENCODER_NOT_SUPPORTED:
49 return "Hardware video encoder not supported.";
50 default:
hubbe 2014/09/09 00:25:45 Remove the default so that we get a compile error
Alpha Left Google 2014/09/09 00:37:11 Done.
51 NOTREACHED() << "Not an error.";
52 return "";
53 }
54 }
55
56 } // namespace
57
32 CastSessionDelegate::CastSessionDelegate() 58 CastSessionDelegate::CastSessionDelegate()
33 : io_message_loop_proxy_( 59 : io_message_loop_proxy_(
34 content::RenderThread::Get()->GetIOMessageLoopProxy()), 60 content::RenderThread::Get()->GetIOMessageLoopProxy()),
35 weak_factory_(this) { 61 weak_factory_(this) {
36 DCHECK(io_message_loop_proxy_.get()); 62 DCHECK(io_message_loop_proxy_.get());
37 } 63 }
38 64
39 CastSessionDelegate::~CastSessionDelegate() { 65 CastSessionDelegate::~CastSessionDelegate() {
40 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 66 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
41 } 67 }
42 68
43 void CastSessionDelegate::StartAudio( 69 void CastSessionDelegate::StartAudio(
44 const AudioSenderConfig& config, 70 const AudioSenderConfig& config,
45 const AudioFrameInputAvailableCallback& callback, 71 const AudioFrameInputAvailableCallback& callback,
46 const ErrorCallback& error_callback) { 72 const ErrorCallback& error_callback) {
47 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 73 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
48 74
49 if (!cast_transport_ || !cast_sender_) { 75 if (!cast_transport_ || !cast_sender_) {
50 error_callback.Run("Destination not set."); 76 error_callback.Run("Destination not set.");
51 return; 77 return;
52 } 78 }
53 79
54 audio_frame_input_available_callback_ = callback; 80 audio_frame_input_available_callback_ = callback;
55 cast_sender_->InitializeAudio( 81 cast_sender_->InitializeAudio(
56 config, 82 config,
57 base::Bind(&CastSessionDelegate::InitializationResultCB, 83 base::Bind(&CastSessionDelegate::InitializationResultCB,
58 weak_factory_.GetWeakPtr())); 84 weak_factory_.GetWeakPtr(), error_callback));
59 } 85 }
60 86
61 void CastSessionDelegate::StartVideo( 87 void CastSessionDelegate::StartVideo(
62 const VideoSenderConfig& config, 88 const VideoSenderConfig& config,
63 const VideoFrameInputAvailableCallback& callback, 89 const VideoFrameInputAvailableCallback& callback,
64 const ErrorCallback& error_callback, 90 const ErrorCallback& error_callback,
65 const media::cast::CreateVideoEncodeAcceleratorCallback& create_vea_cb, 91 const media::cast::CreateVideoEncodeAcceleratorCallback& create_vea_cb,
66 const media::cast::CreateVideoEncodeMemoryCallback& 92 const media::cast::CreateVideoEncodeMemoryCallback&
67 create_video_encode_mem_cb) { 93 create_video_encode_mem_cb) {
68 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 94 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
69 95
70 if (!cast_transport_ || !cast_sender_) { 96 if (!cast_transport_ || !cast_sender_) {
71 error_callback.Run("Destination not set."); 97 error_callback.Run("Destination not set.");
72 return; 98 return;
73 } 99 }
74 100
75 video_frame_input_available_callback_ = callback; 101 video_frame_input_available_callback_ = callback;
76 102
77 cast_sender_->InitializeVideo( 103 cast_sender_->InitializeVideo(
78 config, 104 config,
79 base::Bind(&CastSessionDelegate::InitializationResultCB, 105 base::Bind(&CastSessionDelegate::InitializationResultCB,
80 weak_factory_.GetWeakPtr()), 106 weak_factory_.GetWeakPtr(), error_callback),
81 create_vea_cb, 107 create_vea_cb,
82 create_video_encode_mem_cb); 108 create_video_encode_mem_cb);
83 } 109 }
84 110
85 void CastSessionDelegate::StartUDP(const net::IPEndPoint& remote_endpoint) { 111 void CastSessionDelegate::StartUDP(const net::IPEndPoint& remote_endpoint) {
86 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 112 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
87 113
88 // CastSender uses the renderer's IO thread as the main thread. This reduces 114 // CastSender uses the renderer's IO thread as the main thread. This reduces
89 // thread hopping for incoming video frames and outgoing network packets. 115 // thread hopping for incoming video frames and outgoing network packets.
90 cast_environment_ = new CastEnvironment( 116 cast_environment_ = new CastEnvironment(
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 callback.Run(stats.Pass()); 222 callback.Run(stats.Pass());
197 } 223 }
198 224
199 void CastSessionDelegate::StatusNotificationCB( 225 void CastSessionDelegate::StatusNotificationCB(
200 media::cast::CastTransportStatus unused_status) { 226 media::cast::CastTransportStatus unused_status) {
201 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 227 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
202 // TODO(hubbe): Call javascript UDPTransport error function. 228 // TODO(hubbe): Call javascript UDPTransport error function.
203 } 229 }
204 230
205 void CastSessionDelegate::InitializationResultCB( 231 void CastSessionDelegate::InitializationResultCB(
232 const ErrorCallback& error_callback,
206 media::cast::CastInitializationStatus result) const { 233 media::cast::CastInitializationStatus result) const {
207 DCHECK(cast_sender_); 234 DCHECK(cast_sender_);
208 235
209 // TODO(pwestin): handle the error codes.
210 if (result == media::cast::STATUS_AUDIO_INITIALIZED) { 236 if (result == media::cast::STATUS_AUDIO_INITIALIZED) {
hubbe 2014/09/09 00:25:45 might be better to just inline CastErrorToString h
Alpha Left Google 2014/09/09 00:37:11 Done.
211 audio_frame_input_available_callback_.Run( 237 audio_frame_input_available_callback_.Run(
212 cast_sender_->audio_frame_input()); 238 cast_sender_->audio_frame_input());
213 } else if (result == media::cast::STATUS_VIDEO_INITIALIZED) { 239 } else if (result == media::cast::STATUS_VIDEO_INITIALIZED) {
214 video_frame_input_available_callback_.Run( 240 video_frame_input_available_callback_.Run(
215 cast_sender_->video_frame_input()); 241 cast_sender_->video_frame_input());
242 } else if (result > media::cast::STATUS_VIDEO_INITIALIZED) {
243 error_callback.Run(CastErrorToString(result));
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698