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_receiver/video_receiver.h" | 5 #include "media/cast/video_receiver/video_receiver.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 int max_unacked_frames = video_config.rtp_max_delay_ms * | 124 int max_unacked_frames = video_config.rtp_max_delay_ms * |
125 video_config.max_frame_rate / 1000; | 125 video_config.max_frame_rate / 1000; |
126 DCHECK(max_unacked_frames) << "Invalid argument"; | 126 DCHECK(max_unacked_frames) << "Invalid argument"; |
127 | 127 |
128 framer_.reset(new Framer(cast_environment->Clock(), | 128 framer_.reset(new Framer(cast_environment->Clock(), |
129 incoming_payload_feedback_.get(), | 129 incoming_payload_feedback_.get(), |
130 video_config.incoming_ssrc, | 130 video_config.incoming_ssrc, |
131 video_config.decoder_faster_than_max_frame_rate, | 131 video_config.decoder_faster_than_max_frame_rate, |
132 max_unacked_frames)); | 132 max_unacked_frames)); |
133 if (!video_config.use_external_decoder) { | 133 if (!video_config.use_external_decoder) { |
134 video_decoder_.reset(new VideoDecoder(video_config)); | 134 video_decoder_.reset(new VideoDecoder(video_config, cast_environment)); |
135 } | 135 } |
136 | 136 |
137 rtcp_.reset( | 137 rtcp_.reset( |
138 new Rtcp(cast_environment_->Clock(), | 138 new Rtcp(cast_environment_->Clock(), |
139 NULL, | 139 NULL, |
140 packet_sender, | 140 packet_sender, |
141 NULL, | 141 NULL, |
142 rtp_video_receiver_statistics_.get(), | 142 rtp_video_receiver_statistics_.get(), |
143 video_config.rtcp_mode, | 143 video_config.rtcp_mode, |
144 base::TimeDelta::FromMilliseconds(video_config.rtcp_interval), | 144 base::TimeDelta::FromMilliseconds(video_config.rtcp_interval), |
(...skipping 28 matching lines...) Expand all Loading... | |
173 } | 173 } |
174 | 174 |
175 // Utility function to run the decoder on a designated decoding thread. | 175 // Utility function to run the decoder on a designated decoding thread. |
176 void VideoReceiver::DecodeVideoFrameThread( | 176 void VideoReceiver::DecodeVideoFrameThread( |
177 scoped_ptr<EncodedVideoFrame> encoded_frame, | 177 scoped_ptr<EncodedVideoFrame> encoded_frame, |
178 const base::TimeTicks render_time, | 178 const base::TimeTicks render_time, |
179 const VideoFrameDecodedCallback& frame_decoded_callback) { | 179 const VideoFrameDecodedCallback& frame_decoded_callback) { |
180 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::VIDEO_DECODER)); | 180 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::VIDEO_DECODER)); |
181 DCHECK(video_decoder_); | 181 DCHECK(video_decoder_); |
182 | 182 |
183 // TODO(mikhal): Allow the application to allocate this memory. | 183 bool success = video_decoder_->DecodeVideoFrame(encoded_frame.get(), |
Alpha Left Google
2013/11/06 02:22:06
nit: I'd drop this local variable. You can call th
mikhal
2013/11/06 18:29:16
Done.
| |
184 scoped_ptr<I420VideoFrame> video_frame(new I420VideoFrame()); | 184 render_time, frame_decoded_callback); |
185 | 185 |
186 bool success = video_decoder_->DecodeVideoFrame(encoded_frame.get(), | 186 if (!success) { |
187 render_time, video_frame.get()); | |
188 | |
189 if (success) { | |
190 VLOG(1) << "Decoded frame " << static_cast<int>(encoded_frame->frame_id); | |
191 // Frame decoded - return frame to the user via callback. | |
192 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, | |
193 base::Bind(frame_decoded_callback, | |
194 base::Passed(&video_frame), render_time)); | |
195 } else { | |
196 // This will happen if we decide to decode but not show a frame. | 187 // This will happen if we decide to decode but not show a frame. |
197 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, | 188 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, |
198 base::Bind(&VideoReceiver::GetRawVideoFrame, | 189 base::Bind(&VideoReceiver::GetRawVideoFrame, |
199 weak_factory_.GetWeakPtr(), frame_decoded_callback)); | 190 weak_factory_.GetWeakPtr(), frame_decoded_callback)); |
200 } | 191 } |
201 } | 192 } |
202 | 193 |
203 // Called from the main cast thread. | 194 // Called from the main cast thread. |
204 void VideoReceiver::GetEncodedVideoFrame( | 195 void VideoReceiver::GetEncodedVideoFrame( |
205 const VideoFrameEncodedCallback& callback) { | 196 const VideoFrameEncodedCallback& callback) { |
206 scoped_ptr<EncodedVideoFrame> encoded_frame(new EncodedVideoFrame()); | 197 scoped_ptr<EncodedVideoFrame> encoded_frame(new EncodedVideoFrame()); |
207 uint32 rtp_timestamp = 0; | 198 uint32 rtp_timestamp = 0; |
208 bool next_frame = false; | 199 bool next_frame = false; |
209 | 200 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 weak_factory_.GetWeakPtr()), time_to_next); | 410 weak_factory_.GetWeakPtr()), time_to_next); |
420 } | 411 } |
421 | 412 |
422 void VideoReceiver::SendNextRtcpReport() { | 413 void VideoReceiver::SendNextRtcpReport() { |
423 rtcp_->SendRtcpReport(incoming_ssrc_); | 414 rtcp_->SendRtcpReport(incoming_ssrc_); |
424 ScheduleNextRtcpReport(); | 415 ScheduleNextRtcpReport(); |
425 } | 416 } |
426 | 417 |
427 } // namespace cast | 418 } // namespace cast |
428 } // namespace media | 419 } // namespace media |
OLD | NEW |