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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "chrome/renderer/media/cast_transport_sender_ipc.h" | 9 #include "chrome/renderer/media/cast_transport_sender_ipc.h" |
10 #include "content/public/renderer/p2p_socket_client.h" | 10 #include "content/public/renderer/p2p_socket_client.h" |
11 #include "content/public/renderer/render_thread.h" | 11 #include "content/public/renderer/render_thread.h" |
12 #include "media/cast/cast_config.h" | 12 #include "media/cast/cast_config.h" |
13 #include "media/cast/cast_environment.h" | 13 #include "media/cast/cast_environment.h" |
14 #include "media/cast/cast_sender.h" | 14 #include "media/cast/cast_sender.h" |
| 15 #include "media/cast/logging/encoding_event_subscriber.h" |
15 #include "media/cast/logging/logging_defines.h" | 16 #include "media/cast/logging/logging_defines.h" |
16 #include "media/cast/transport/cast_transport_config.h" | 17 #include "media/cast/transport/cast_transport_config.h" |
17 #include "media/cast/transport/cast_transport_sender.h" | 18 #include "media/cast/transport/cast_transport_sender.h" |
18 | 19 |
19 using media::cast::AudioSenderConfig; | 20 using media::cast::AudioSenderConfig; |
20 using media::cast::CastEnvironment; | 21 using media::cast::CastEnvironment; |
21 using media::cast::CastSender; | 22 using media::cast::CastSender; |
22 using media::cast::VideoSenderConfig; | 23 using media::cast::VideoSenderConfig; |
23 | 24 |
| 25 namespace { |
| 26 |
| 27 // Allow about 9MB for video event logs. Assume serialized log data for |
| 28 // each frame will take up to 150 bytes. |
| 29 const int kMaxVideoEventEntries = 9000000 / 150; |
| 30 |
| 31 // Allow about 9MB for audio event logs. Assume serialized log data for |
| 32 // each frame will take up to 75 bytes. |
| 33 const int kMaxAudioEventEntries = 9000000 / 75; |
| 34 |
| 35 } // namespace |
| 36 |
24 CastSessionDelegate::CastSessionDelegate() | 37 CastSessionDelegate::CastSessionDelegate() |
25 : audio_encode_thread_("CastAudioEncodeThread"), | 38 : audio_encode_thread_("CastAudioEncodeThread"), |
26 video_encode_thread_("CastVideoEncodeThread"), | 39 video_encode_thread_("CastVideoEncodeThread"), |
27 transport_configured_(false), | 40 transport_configured_(false), |
28 io_message_loop_proxy_( | 41 io_message_loop_proxy_( |
29 content::RenderThread::Get()->GetIOMessageLoopProxy()) { | 42 content::RenderThread::Get()->GetIOMessageLoopProxy()) { |
30 DCHECK(io_message_loop_proxy_); | 43 DCHECK(io_message_loop_proxy_); |
31 } | 44 } |
32 | 45 |
33 CastSessionDelegate::~CastSessionDelegate() { | 46 CastSessionDelegate::~CastSessionDelegate() { |
34 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 47 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 48 |
| 49 if (audio_event_subscriber_.get()) { |
| 50 cast_environment_->Logging()->RemoveRawEventSubscriber( |
| 51 audio_event_subscriber_.get()); |
| 52 } |
| 53 if (video_event_subscriber_.get()) { |
| 54 cast_environment_->Logging()->RemoveRawEventSubscriber( |
| 55 video_event_subscriber_.get()); |
| 56 } |
35 } | 57 } |
36 | 58 |
37 void CastSessionDelegate::Initialize() { | 59 void CastSessionDelegate::Initialize() { |
38 if (cast_environment_) | 60 if (cast_environment_) |
39 return; // Already initialized. | 61 return; // Already initialized. |
40 | 62 |
41 audio_encode_thread_.Start(); | 63 audio_encode_thread_.Start(); |
42 video_encode_thread_.Start(); | 64 video_encode_thread_.Start(); |
43 | 65 |
44 // CastSender uses the renderer's IO thread as the main thread. This reduces | 66 // CastSender uses the renderer's IO thread as the main thread. This reduces |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 void CastSessionDelegate::StartUDP( | 101 void CastSessionDelegate::StartUDP( |
80 const net::IPEndPoint& local_endpoint, | 102 const net::IPEndPoint& local_endpoint, |
81 const net::IPEndPoint& remote_endpoint) { | 103 const net::IPEndPoint& remote_endpoint) { |
82 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 104 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
83 transport_configured_ = true; | 105 transport_configured_ = true; |
84 local_endpoint_ = local_endpoint; | 106 local_endpoint_ = local_endpoint; |
85 remote_endpoint_ = remote_endpoint; | 107 remote_endpoint_ = remote_endpoint; |
86 StartSendingInternal(); | 108 StartSendingInternal(); |
87 } | 109 } |
88 | 110 |
| 111 void CastSessionDelegate::GetEventLogsAndReset( |
| 112 const EventLogsCallback& callback) { |
| 113 if (!cast_sender_.get()) |
| 114 return; |
| 115 |
| 116 // TODO(imcheng): Get data from event subscribers. |
| 117 scoped_ptr<std::string> result(new std::string); |
| 118 callback.Run(result.Pass()); |
| 119 } |
| 120 |
89 void CastSessionDelegate::StatusNotificationCB( | 121 void CastSessionDelegate::StatusNotificationCB( |
90 media::cast::transport::CastTransportStatus unused_status) { | 122 media::cast::transport::CastTransportStatus unused_status) { |
91 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 123 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
92 // TODO(hubbe): Call javascript UDPTransport error function. | 124 // TODO(hubbe): Call javascript UDPTransport error function. |
93 } | 125 } |
94 | 126 |
95 void CastSessionDelegate::StartSendingInternal() { | 127 void CastSessionDelegate::StartSendingInternal() { |
96 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 128 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
97 | 129 |
98 // No transport, wait. | 130 // No transport, wait. |
(...skipping 10 matching lines...) Expand all Loading... |
109 | 141 |
110 // TODO(hubbe): set config.aes_key and config.aes_iv_mask. | 142 // TODO(hubbe): set config.aes_key and config.aes_iv_mask. |
111 config.local_endpoint = local_endpoint_; | 143 config.local_endpoint = local_endpoint_; |
112 config.receiver_endpoint = remote_endpoint_; | 144 config.receiver_endpoint = remote_endpoint_; |
113 if (audio_config_) { | 145 if (audio_config_) { |
114 config.audio_ssrc = audio_config_->sender_ssrc; | 146 config.audio_ssrc = audio_config_->sender_ssrc; |
115 config.audio_codec = audio_config_->codec; | 147 config.audio_codec = audio_config_->codec; |
116 config.audio_rtp_config = audio_config_->rtp_config; | 148 config.audio_rtp_config = audio_config_->rtp_config; |
117 config.audio_frequency = audio_config_->frequency; | 149 config.audio_frequency = audio_config_->frequency; |
118 config.audio_channels = audio_config_->channels; | 150 config.audio_channels = audio_config_->channels; |
| 151 |
| 152 if (!audio_event_subscriber_.get()) { |
| 153 audio_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( |
| 154 media::cast::AUDIO_EVENT, kMaxAudioEventEntries)); |
| 155 cast_environment_->Logging()->AddRawEventSubscriber( |
| 156 audio_event_subscriber_.get()); |
| 157 } |
119 } | 158 } |
120 if (video_config_) { | 159 if (video_config_) { |
121 config.video_ssrc = video_config_->sender_ssrc; | 160 config.video_ssrc = video_config_->sender_ssrc; |
122 config.video_codec = video_config_->codec; | 161 config.video_codec = video_config_->codec; |
123 config.video_rtp_config = video_config_->rtp_config; | 162 config.video_rtp_config = video_config_->rtp_config; |
| 163 |
| 164 if (!video_event_subscriber_.get()) { |
| 165 video_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( |
| 166 media::cast::VIDEO_EVENT, kMaxVideoEventEntries)); |
| 167 cast_environment_->Logging()->AddRawEventSubscriber( |
| 168 video_event_subscriber_.get()); |
| 169 } |
124 } | 170 } |
125 | 171 |
126 cast_transport_.reset(new CastTransportSenderIPC( | 172 cast_transport_.reset(new CastTransportSenderIPC( |
127 config, | 173 config, |
128 base::Bind(&CastSessionDelegate::StatusNotificationCB, | 174 base::Bind(&CastSessionDelegate::StatusNotificationCB, |
129 base::Unretained(this)))); | 175 base::Unretained(this)))); |
130 | 176 |
131 cast_sender_.reset(CastSender::CreateCastSender( | 177 cast_sender_.reset(CastSender::CreateCastSender( |
132 cast_environment_, | 178 cast_environment_, |
133 audio_config_.get(), | 179 audio_config_.get(), |
(...skipping 12 matching lines...) Expand all Loading... |
146 // TODO(pwestin): handle the error codes. | 192 // TODO(pwestin): handle the error codes. |
147 if (result == media::cast::STATUS_INITIALIZED) { | 193 if (result == media::cast::STATUS_INITIALIZED) { |
148 if (!audio_frame_input_available_callback_.is_null()) { | 194 if (!audio_frame_input_available_callback_.is_null()) { |
149 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); | 195 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); |
150 } | 196 } |
151 if (!video_frame_input_available_callback_.is_null()) { | 197 if (!video_frame_input_available_callback_.is_null()) { |
152 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); | 198 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); |
153 } | 199 } |
154 } | 200 } |
155 } | 201 } |
OLD | NEW |