| 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/video_sender/video_encoder.h" | 5 #include "media/cast/video_sender/video_encoder.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 } | 22 } |
| 23 | 23 |
| 24 VideoEncoderImpl::VideoEncoderImpl( | 24 VideoEncoderImpl::VideoEncoderImpl( |
| 25 scoped_refptr<CastEnvironment> cast_environment, | 25 scoped_refptr<CastEnvironment> cast_environment, |
| 26 const VideoSenderConfig& video_config, | 26 const VideoSenderConfig& video_config, |
| 27 uint8 max_unacked_frames) | 27 uint8 max_unacked_frames) |
| 28 : video_config_(video_config), | 28 : video_config_(video_config), |
| 29 cast_environment_(cast_environment), | 29 cast_environment_(cast_environment), |
| 30 skip_next_frame_(false), | 30 skip_next_frame_(false), |
| 31 skip_count_(0) { | 31 skip_count_(0) { |
| 32 if (video_config.codec == transport::kVp8) { | 32 if (video_config.codec == kVp8) { |
| 33 vp8_encoder_.reset(new Vp8Encoder(video_config, max_unacked_frames)); | 33 vp8_encoder_.reset(new Vp8Encoder(video_config, max_unacked_frames)); |
| 34 } else { | 34 } else { |
| 35 DCHECK(false) << "Invalid config"; // Codec not supported. | 35 DCHECK(false) << "Invalid config"; // Codec not supported. |
| 36 } | 36 } |
| 37 | 37 |
| 38 dynamic_config_.key_frame_requested = false; | 38 dynamic_config_.key_frame_requested = false; |
| 39 dynamic_config_.latest_frame_id_to_reference = kStartFrameId; | 39 dynamic_config_.latest_frame_id_to_reference = kStartFrameId; |
| 40 dynamic_config_.bit_rate = video_config.start_bitrate; | 40 dynamic_config_.bit_rate = video_config.start_bitrate; |
| 41 } | 41 } |
| 42 | 42 |
| 43 VideoEncoderImpl::~VideoEncoderImpl() {} | 43 VideoEncoderImpl::~VideoEncoderImpl() {} |
| 44 | 44 |
| 45 bool VideoEncoderImpl::EncodeVideoFrame( | 45 bool VideoEncoderImpl::EncodeVideoFrame( |
| 46 const scoped_refptr<media::VideoFrame>& video_frame, | 46 const scoped_refptr<media::VideoFrame>& video_frame, |
| 47 const base::TimeTicks& capture_time, | 47 const base::TimeTicks& capture_time, |
| 48 const FrameEncodedCallback& frame_encoded_callback) { | 48 const FrameEncodedCallback& frame_encoded_callback) { |
| 49 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 49 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 50 if (video_config_.codec != transport::kVp8) return false; | 50 if (video_config_.codec != kVp8) return false; |
| 51 | 51 |
| 52 if (skip_next_frame_) { | 52 if (skip_next_frame_) { |
| 53 ++skip_count_; | 53 ++skip_count_; |
| 54 skip_next_frame_ = false; | 54 skip_next_frame_ = false; |
| 55 VLOG(1) << "Skip encoding frame"; | 55 VLOG(1) << "Skip encoding frame"; |
| 56 return false; | 56 return false; |
| 57 } | 57 } |
| 58 | 58 |
| 59 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 59 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
| 60 cast_environment_->Logging()->InsertFrameEvent(now, kVideoFrameSentToEncoder, | 60 cast_environment_->Logging()->InsertFrameEvent(now, kVideoFrameSentToEncoder, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 74 const CodecDynamicConfig& dynamic_config, | 74 const CodecDynamicConfig& dynamic_config, |
| 75 const FrameEncodedCallback& frame_encoded_callback) { | 75 const FrameEncodedCallback& frame_encoded_callback) { |
| 76 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::VIDEO_ENCODER)); | 76 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::VIDEO_ENCODER)); |
| 77 if (dynamic_config.key_frame_requested) { | 77 if (dynamic_config.key_frame_requested) { |
| 78 vp8_encoder_->GenerateKeyFrame(); | 78 vp8_encoder_->GenerateKeyFrame(); |
| 79 } | 79 } |
| 80 vp8_encoder_->LatestFrameIdToReference( | 80 vp8_encoder_->LatestFrameIdToReference( |
| 81 dynamic_config.latest_frame_id_to_reference); | 81 dynamic_config.latest_frame_id_to_reference); |
| 82 vp8_encoder_->UpdateRates(dynamic_config.bit_rate); | 82 vp8_encoder_->UpdateRates(dynamic_config.bit_rate); |
| 83 | 83 |
| 84 scoped_ptr<transport::EncodedVideoFrame> encoded_frame( | 84 scoped_ptr<EncodedVideoFrame> encoded_frame(new EncodedVideoFrame()); |
| 85 new transport::EncodedVideoFrame()); | |
| 86 bool retval = vp8_encoder_->Encode(video_frame, encoded_frame.get()); | 85 bool retval = vp8_encoder_->Encode(video_frame, encoded_frame.get()); |
| 87 | 86 |
| 88 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 87 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
| 89 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, | 88 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, |
| 90 base::Bind(LogFrameEncodedEvent, now, cast_environment_, capture_time)); | 89 base::Bind(LogFrameEncodedEvent, now, cast_environment_, capture_time)); |
| 91 | 90 |
| 92 if (!retval) { | 91 if (!retval) { |
| 93 VLOG(1) << "Encoding failed"; | 92 VLOG(1) << "Encoding failed"; |
| 94 return; | 93 return; |
| 95 } | 94 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 121 void VideoEncoderImpl::LatestFrameIdToReference(uint32 frame_id) { | 120 void VideoEncoderImpl::LatestFrameIdToReference(uint32 frame_id) { |
| 122 dynamic_config_.latest_frame_id_to_reference = frame_id; | 121 dynamic_config_.latest_frame_id_to_reference = frame_id; |
| 123 } | 122 } |
| 124 | 123 |
| 125 int VideoEncoderImpl::NumberOfSkippedFrames() const { | 124 int VideoEncoderImpl::NumberOfSkippedFrames() const { |
| 126 return skip_count_; | 125 return skip_count_; |
| 127 } | 126 } |
| 128 | 127 |
| 129 } // namespace cast | 128 } // namespace cast |
| 130 } // namespace media | 129 } // namespace media |
| OLD | NEW |