OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sender/video_sender.h" | 5 #include "media/cast/sender/video_sender.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 cast_environment, | 33 cast_environment, |
34 false, | 34 false, |
35 transport_sender, | 35 transport_sender, |
36 base::TimeDelta::FromMilliseconds(video_config.rtcp_interval), | 36 base::TimeDelta::FromMilliseconds(video_config.rtcp_interval), |
37 kVideoFrequency, | 37 kVideoFrequency, |
38 video_config.ssrc, | 38 video_config.ssrc, |
39 video_config.max_frame_rate, | 39 video_config.max_frame_rate, |
40 video_config.target_playout_delay, | 40 video_config.target_playout_delay, |
41 NewFixedCongestionControl( | 41 NewFixedCongestionControl( |
42 (video_config.min_bitrate + video_config.max_bitrate) / 2)), | 42 (video_config.min_bitrate + video_config.max_bitrate) / 2)), |
| 43 frames_in_encoder_(0), |
43 last_bitrate_(0), | 44 last_bitrate_(0), |
44 weak_factory_(this) { | 45 weak_factory_(this) { |
45 cast_initialization_status_ = STATUS_VIDEO_UNINITIALIZED; | 46 cast_initialization_status_ = STATUS_VIDEO_UNINITIALIZED; |
46 VLOG(1) << "max_unacked_frames is " << max_unacked_frames_ | 47 VLOG(1) << "max_unacked_frames is " << max_unacked_frames_ |
47 << " for target_playout_delay=" | 48 << " for target_playout_delay=" |
48 << target_playout_delay_.InMilliseconds() << " ms" | 49 << target_playout_delay_.InMilliseconds() << " ms" |
49 << " and max_frame_rate=" << video_config.max_frame_rate; | 50 << " and max_frame_rate=" << video_config.max_frame_rate; |
50 DCHECK_GT(max_unacked_frames_, 0); | 51 DCHECK_GT(max_unacked_frames_, 0); |
51 | 52 |
52 if (video_config.use_external_encoder) { | 53 if (video_config.use_external_encoder) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 uint32 bitrate = congestion_control_->GetBitrate( | 120 uint32 bitrate = congestion_control_->GetBitrate( |
120 capture_time + target_playout_delay_, target_playout_delay_); | 121 capture_time + target_playout_delay_, target_playout_delay_); |
121 if (bitrate != last_bitrate_) { | 122 if (bitrate != last_bitrate_) { |
122 video_encoder_->SetBitRate(bitrate); | 123 video_encoder_->SetBitRate(bitrate); |
123 last_bitrate_ = bitrate; | 124 last_bitrate_ = bitrate; |
124 } | 125 } |
125 | 126 |
126 if (video_encoder_->EncodeVideoFrame( | 127 if (video_encoder_->EncodeVideoFrame( |
127 video_frame, | 128 video_frame, |
128 capture_time, | 129 capture_time, |
129 base::Bind(&FrameSender::SendEncodedFrame, | 130 base::Bind(&VideoSender::OnEncodedVideoFrame, |
130 weak_factory_.GetWeakPtr(), | 131 weak_factory_.GetWeakPtr(), |
131 bitrate))) { | 132 bitrate))) { |
132 frames_in_encoder_++; | 133 frames_in_encoder_++; |
133 } else { | 134 } else { |
134 VLOG(1) << "Encoder rejected a frame. Skipping..."; | 135 VLOG(1) << "Encoder rejected a frame. Skipping..."; |
135 } | 136 } |
136 } | 137 } |
137 | 138 |
| 139 int VideoSender::GetNumberOfFramesInEncoder() const { |
| 140 return frames_in_encoder_; |
| 141 } |
| 142 |
138 void VideoSender::OnAck(uint32 frame_id) { | 143 void VideoSender::OnAck(uint32 frame_id) { |
139 video_encoder_->LatestFrameIdToReference(frame_id); | 144 video_encoder_->LatestFrameIdToReference(frame_id); |
140 } | 145 } |
141 | 146 |
| 147 void VideoSender::OnEncodedVideoFrame( |
| 148 int encoder_bitrate, |
| 149 scoped_ptr<EncodedFrame> encoded_frame) { |
| 150 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 151 |
| 152 frames_in_encoder_--; |
| 153 DCHECK_GE(frames_in_encoder_, 0); |
| 154 |
| 155 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); |
| 156 } |
| 157 |
142 } // namespace cast | 158 } // namespace cast |
143 } // namespace media | 159 } // namespace media |
OLD | NEW |