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 "media/cast/video_sender/video_sender.h" | 5 #include "media/cast/video_sender/video_sender.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "crypto/encryptor.h" | 12 #include "crypto/encryptor.h" |
13 #include "crypto/symmetric_key.h" | 13 #include "crypto/symmetric_key.h" |
14 #include "media/cast/cast_defines.h" | 14 #include "media/cast/cast_defines.h" |
15 #include "media/cast/net/pacing/paced_sender.h" | 15 #include "media/cast/transport/pacing/paced_sender.h" |
16 #include "media/cast/video_sender/video_encoder.h" | 16 #include "media/cast/video_sender/video_encoder.h" |
17 | 17 |
18 namespace media { | 18 namespace media { |
19 namespace cast { | 19 namespace cast { |
20 | 20 |
21 const int64 kMinSchedulingDelayMs = 1; | 21 const int64 kMinSchedulingDelayMs = 1; |
22 | 22 |
23 class LocalRtcpVideoSenderFeedback : public RtcpSenderFeedback { | 23 class LocalRtcpVideoSenderFeedback : public RtcpSenderFeedback { |
24 public: | 24 public: |
25 explicit LocalRtcpVideoSenderFeedback(VideoSender* video_sender) | 25 explicit LocalRtcpVideoSenderFeedback(VideoSender* video_sender) |
26 : video_sender_(video_sender) { | 26 : video_sender_(video_sender) { |
27 } | 27 } |
28 | 28 |
29 virtual void OnReceivedCastFeedback( | 29 virtual void OnReceivedCastFeedback( |
30 const RtcpCastMessage& cast_feedback) OVERRIDE { | 30 const RtcpCastMessage& cast_feedback) OVERRIDE { |
31 video_sender_->OnReceivedCastFeedback(cast_feedback); | 31 video_sender_->OnReceivedCastFeedback(cast_feedback); |
32 } | 32 } |
33 | 33 |
34 private: | 34 private: |
35 VideoSender* video_sender_; | 35 VideoSender* video_sender_; |
36 }; | 36 }; |
37 | 37 |
38 class LocalRtpVideoSenderStatistics : public RtpSenderStatistics { | 38 class LocalRtpVideoSenderStatistics : public RtpSenderStatistics { |
39 public: | 39 public: |
40 explicit LocalRtpVideoSenderStatistics(RtpSender* rtp_sender) | 40 explicit LocalRtpVideoSenderStatistics(transport::RtpSender* rtp_sender) |
41 : rtp_sender_(rtp_sender) { | 41 : rtp_sender_(rtp_sender) { |
42 } | 42 } |
43 | 43 |
44 virtual void GetStatistics(const base::TimeTicks& now, | 44 virtual void GetStatistics(const base::TimeTicks& now, |
45 RtcpSenderInfo* sender_info) OVERRIDE { | 45 transport::RtcpSenderInfo* sender_info) OVERRIDE { |
46 rtp_sender_->RtpStatistics(now, sender_info); | 46 rtp_sender_->RtpStatistics(now, sender_info); |
47 } | 47 } |
48 | 48 |
49 private: | 49 private: |
50 RtpSender* rtp_sender_; | 50 transport::RtpSender* rtp_sender_; |
51 }; | 51 }; |
52 | 52 |
53 VideoSender::VideoSender( | 53 VideoSender::VideoSender( |
54 scoped_refptr<CastEnvironment> cast_environment, | 54 scoped_refptr<CastEnvironment> cast_environment, |
55 const VideoSenderConfig& video_config, | 55 const VideoSenderConfig& video_config, |
56 VideoEncoderController* const video_encoder_controller, | 56 VideoEncoderController* const video_encoder_controller, |
57 PacedPacketSender* const paced_packet_sender) | 57 transport::PacedPacketSender* const paced_packet_sender) |
58 : rtp_max_delay_( | 58 : rtp_max_delay_( |
59 base::TimeDelta::FromMilliseconds(video_config.rtp_max_delay_ms)), | 59 base::TimeDelta::FromMilliseconds(video_config.rtp_max_delay_ms)), |
60 max_frame_rate_(video_config.max_frame_rate), | 60 max_frame_rate_(video_config.max_frame_rate), |
61 cast_environment_(cast_environment), | 61 cast_environment_(cast_environment), |
62 rtcp_feedback_(new LocalRtcpVideoSenderFeedback(this)), | 62 rtcp_feedback_(new LocalRtcpVideoSenderFeedback(this)), |
63 rtp_sender_(new RtpSender(cast_environment, NULL, &video_config, | 63 rtp_sender_(new transport::RtpSender(cast_environment, |
64 paced_packet_sender)), | 64 NULL, |
| 65 &video_config, |
| 66 paced_packet_sender)), |
65 last_acked_frame_id_(-1), | 67 last_acked_frame_id_(-1), |
66 last_sent_frame_id_(-1), | 68 last_sent_frame_id_(-1), |
67 duplicate_ack_(0), | 69 duplicate_ack_(0), |
68 last_skip_count_(0), | 70 last_skip_count_(0), |
69 congestion_control_(cast_environment->Clock(), | 71 congestion_control_(cast_environment->Clock(), |
70 video_config.congestion_control_back_off, | 72 video_config.congestion_control_back_off, |
71 video_config.max_bitrate, | 73 video_config.max_bitrate, |
72 video_config.min_bitrate, | 74 video_config.min_bitrate, |
73 video_config.start_bitrate), | 75 video_config.start_bitrate), |
74 initialized_(false), | 76 initialized_(false), |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 base::TimeDelta::FromMilliseconds(kMinSchedulingDelayMs)); | 227 base::TimeDelta::FromMilliseconds(kMinSchedulingDelayMs)); |
226 | 228 |
227 cast_environment_->PostDelayedTask(CastEnvironment::MAIN, FROM_HERE, | 229 cast_environment_->PostDelayedTask(CastEnvironment::MAIN, FROM_HERE, |
228 base::Bind(&VideoSender::SendRtcpReport, weak_factory_.GetWeakPtr()), | 230 base::Bind(&VideoSender::SendRtcpReport, weak_factory_.GetWeakPtr()), |
229 time_to_next); | 231 time_to_next); |
230 } | 232 } |
231 | 233 |
232 void VideoSender::SendRtcpReport() { | 234 void VideoSender::SendRtcpReport() { |
233 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 235 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
234 | 236 |
235 RtcpSenderLogMessage sender_log_message; | 237 transport::RtcpSenderLogMessage sender_log_message; |
236 const FrameRawMap& frame_raw_map = | 238 const FrameRawMap& frame_raw_map = |
237 cast_environment_->Logging()->GetFrameRawData(); | 239 cast_environment_->Logging()->GetFrameRawData(); |
238 | 240 |
239 FrameRawMap::const_iterator it = frame_raw_map.begin(); | 241 FrameRawMap::const_iterator it = frame_raw_map.begin(); |
240 while (it != frame_raw_map.end()) { | 242 while (it != frame_raw_map.end()) { |
241 RtcpSenderFrameLogMessage frame_message; | 243 transport::RtcpSenderFrameLogMessage frame_message; |
242 frame_message.rtp_timestamp = it->first; | 244 frame_message.rtp_timestamp = it->first; |
243 frame_message.frame_status = kRtcpSenderFrameStatusUnknown; | 245 frame_message.frame_status = transport::kRtcpSenderFrameStatusUnknown; |
244 if (it->second.type.empty()) { | 246 if (it->second.type.empty()) { |
245 ++it; | 247 ++it; |
246 continue; | 248 continue; |
247 } | 249 } |
248 CastLoggingEvent last_event = it->second.type.back(); | 250 CastLoggingEvent last_event = it->second.type.back(); |
249 switch (last_event) { | 251 switch (last_event) { |
250 case kVideoFrameCaptured: | 252 case kVideoFrameCaptured: |
251 frame_message.frame_status = kRtcpSenderFrameStatusDroppedByFlowControl; | 253 frame_message.frame_status = |
| 254 transport::kRtcpSenderFrameStatusDroppedByFlowControl; |
252 break; | 255 break; |
253 case kVideoFrameSentToEncoder: | 256 case kVideoFrameSentToEncoder: |
254 frame_message.frame_status = kRtcpSenderFrameStatusDroppedByEncoder; | 257 frame_message.frame_status = |
| 258 transport::kRtcpSenderFrameStatusDroppedByEncoder; |
255 break; | 259 break; |
256 case kVideoFrameEncoded: | 260 case kVideoFrameEncoded: |
257 frame_message.frame_status = kRtcpSenderFrameStatusSentToNetwork; | 261 frame_message.frame_status = |
| 262 transport::kRtcpSenderFrameStatusSentToNetwork; |
258 break; | 263 break; |
259 default: | 264 default: |
260 ++it; | 265 ++it; |
261 continue; | 266 continue; |
262 } | 267 } |
263 ++it; | 268 ++it; |
264 if (it == frame_raw_map.end()) { | 269 if (it == frame_raw_map.end()) { |
265 // Last message on our map; only send if it is kVideoFrameEncoded. | 270 // Last message on our map; only send if it is kVideoFrameEncoded. |
266 if (last_event != kVideoFrameEncoded) { | 271 if (last_event != kVideoFrameEncoded) { |
267 // For other events we will wait for it to finish and report the result | 272 // For other events we will wait for it to finish and report the result |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 457 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
453 MissingFramesAndPacketsMap missing_frames_and_packets; | 458 MissingFramesAndPacketsMap missing_frames_and_packets; |
454 PacketIdSet missing; | 459 PacketIdSet missing; |
455 missing_frames_and_packets.insert(std::make_pair(resend_frame_id, missing)); | 460 missing_frames_and_packets.insert(std::make_pair(resend_frame_id, missing)); |
456 rtp_sender_->ResendPackets(missing_frames_and_packets); | 461 rtp_sender_->ResendPackets(missing_frames_and_packets); |
457 last_send_time_ = cast_environment_->Clock()->NowTicks(); | 462 last_send_time_ = cast_environment_->Clock()->NowTicks(); |
458 } | 463 } |
459 | 464 |
460 } // namespace cast | 465 } // namespace cast |
461 } // namespace media | 466 } // namespace media |
OLD | NEW |