| 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 if (!(video_decoder_->DecodeVideoFrame(encoded_frame.get(), render_time, |
| 184 scoped_ptr<I420VideoFrame> video_frame(new I420VideoFrame()); | 184 frame_decoded_callback))) { |
| 185 | |
| 186 bool success = video_decoder_->DecodeVideoFrame(encoded_frame.get(), | |
| 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. | 185 // This will happen if we decide to decode but not show a frame. |
| 197 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, | 186 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, |
| 198 base::Bind(&VideoReceiver::GetRawVideoFrame, | 187 base::Bind(&VideoReceiver::GetRawVideoFrame, |
| 199 weak_factory_.GetWeakPtr(), frame_decoded_callback)); | 188 weak_factory_.GetWeakPtr(), frame_decoded_callback)); |
| 200 } | 189 } |
| 201 } | 190 } |
| 202 | 191 |
| 203 // Called from the main cast thread. | 192 // Called from the main cast thread. |
| 204 void VideoReceiver::GetEncodedVideoFrame( | 193 void VideoReceiver::GetEncodedVideoFrame( |
| 205 const VideoFrameEncodedCallback& callback) { | 194 const VideoFrameEncodedCallback& callback) { |
| 206 scoped_ptr<EncodedVideoFrame> encoded_frame(new EncodedVideoFrame()); | 195 scoped_ptr<EncodedVideoFrame> encoded_frame(new EncodedVideoFrame()); |
| 207 uint32 rtp_timestamp = 0; | 196 uint32 rtp_timestamp = 0; |
| 208 bool next_frame = false; | 197 bool next_frame = false; |
| 209 | 198 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 weak_factory_.GetWeakPtr()), time_to_next); | 408 weak_factory_.GetWeakPtr()), time_to_next); |
| 420 } | 409 } |
| 421 | 410 |
| 422 void VideoReceiver::SendNextRtcpReport() { | 411 void VideoReceiver::SendNextRtcpReport() { |
| 423 rtcp_->SendRtcpReport(incoming_ssrc_); | 412 rtcp_->SendRtcpReport(incoming_ssrc_); |
| 424 ScheduleNextRtcpReport(); | 413 ScheduleNextRtcpReport(); |
| 425 } | 414 } |
| 426 | 415 |
| 427 } // namespace cast | 416 } // namespace cast |
| 428 } // namespace media | 417 } // namespace media |
| OLD | NEW |