| 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_impl.h" | 5 #include "media/cast/sender/video_encoder_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.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 "media/base/video_frame.h" | 12 #include "media/base/video_frame.h" |
| 13 #include "media/cast/cast_defines.h" | 13 #include "media/cast/cast_defines.h" |
| 14 #include "media/cast/video_sender/codecs/vp8/vp8_encoder.h" | 14 #include "media/cast/sender/fake_software_video_encoder.h" |
| 15 #include "media/cast/video_sender/fake_software_video_encoder.h" | 15 #include "media/cast/sender/vp8_encoder.h" |
| 16 | 16 |
| 17 namespace media { | 17 namespace media { |
| 18 namespace cast { | 18 namespace cast { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 typedef base::Callback<void(Vp8Encoder*)> PassEncoderCallback; | 22 typedef base::Callback<void(Vp8Encoder*)> PassEncoderCallback; |
| 23 | 23 |
| 24 void InitializeEncoderOnEncoderThread( | 24 void InitializeEncoderOnEncoderThread( |
| 25 const scoped_refptr<CastEnvironment>& environment, | 25 const scoped_refptr<CastEnvironment>& environment, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 36 const VideoEncoderImpl::CodecDynamicConfig& dynamic_config, | 36 const VideoEncoderImpl::CodecDynamicConfig& dynamic_config, |
| 37 const VideoEncoderImpl::FrameEncodedCallback& frame_encoded_callback) { | 37 const VideoEncoderImpl::FrameEncodedCallback& frame_encoded_callback) { |
| 38 DCHECK(environment->CurrentlyOn(CastEnvironment::VIDEO)); | 38 DCHECK(environment->CurrentlyOn(CastEnvironment::VIDEO)); |
| 39 if (dynamic_config.key_frame_requested) { | 39 if (dynamic_config.key_frame_requested) { |
| 40 encoder->GenerateKeyFrame(); | 40 encoder->GenerateKeyFrame(); |
| 41 } | 41 } |
| 42 encoder->LatestFrameIdToReference( | 42 encoder->LatestFrameIdToReference( |
| 43 dynamic_config.latest_frame_id_to_reference); | 43 dynamic_config.latest_frame_id_to_reference); |
| 44 encoder->UpdateRates(dynamic_config.bit_rate); | 44 encoder->UpdateRates(dynamic_config.bit_rate); |
| 45 | 45 |
| 46 scoped_ptr<transport::EncodedFrame> encoded_frame( | 46 scoped_ptr<EncodedFrame> encoded_frame( |
| 47 new transport::EncodedFrame()); | 47 new EncodedFrame()); |
| 48 if (!encoder->Encode(video_frame, encoded_frame.get())) { | 48 if (!encoder->Encode(video_frame, encoded_frame.get())) { |
| 49 VLOG(1) << "Encoding failed"; | 49 VLOG(1) << "Encoding failed"; |
| 50 return; | 50 return; |
| 51 } | 51 } |
| 52 if (encoded_frame->data.empty()) { | 52 if (encoded_frame->data.empty()) { |
| 53 VLOG(1) << "Encoding resulted in an empty frame"; | 53 VLOG(1) << "Encoding resulted in an empty frame"; |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 encoded_frame->rtp_timestamp = transport::GetVideoRtpTimestamp(capture_time); | 56 encoded_frame->rtp_timestamp = GetVideoRtpTimestamp(capture_time); |
| 57 encoded_frame->reference_time = capture_time; | 57 encoded_frame->reference_time = capture_time; |
| 58 | 58 |
| 59 environment->PostTask( | 59 environment->PostTask( |
| 60 CastEnvironment::MAIN, | 60 CastEnvironment::MAIN, |
| 61 FROM_HERE, | 61 FROM_HERE, |
| 62 base::Bind( | 62 base::Bind( |
| 63 frame_encoded_callback, base::Passed(&encoded_frame))); | 63 frame_encoded_callback, base::Passed(&encoded_frame))); |
| 64 } | 64 } |
| 65 } // namespace | 65 } // namespace |
| 66 | 66 |
| 67 VideoEncoderImpl::VideoEncoderImpl( | 67 VideoEncoderImpl::VideoEncoderImpl( |
| 68 scoped_refptr<CastEnvironment> cast_environment, | 68 scoped_refptr<CastEnvironment> cast_environment, |
| 69 const VideoSenderConfig& video_config, | 69 const VideoSenderConfig& video_config, |
| 70 int max_unacked_frames) | 70 int max_unacked_frames) |
| 71 : cast_environment_(cast_environment) { | 71 : cast_environment_(cast_environment) { |
| 72 if (video_config.codec == transport::CODEC_VIDEO_VP8) { | 72 if (video_config.codec == CODEC_VIDEO_VP8) { |
| 73 encoder_.reset(new Vp8Encoder(video_config, max_unacked_frames)); | 73 encoder_.reset(new Vp8Encoder(video_config, max_unacked_frames)); |
| 74 cast_environment_->PostTask(CastEnvironment::VIDEO, | 74 cast_environment_->PostTask(CastEnvironment::VIDEO, |
| 75 FROM_HERE, | 75 FROM_HERE, |
| 76 base::Bind(&InitializeEncoderOnEncoderThread, | 76 base::Bind(&InitializeEncoderOnEncoderThread, |
| 77 cast_environment, | 77 cast_environment, |
| 78 encoder_.get())); | 78 encoder_.get())); |
| 79 #ifndef OFFICIAL_BUILD | 79 #ifndef OFFICIAL_BUILD |
| 80 } else if (video_config.codec == transport::CODEC_VIDEO_FAKE) { | 80 } else if (video_config.codec == CODEC_VIDEO_FAKE) { |
| 81 encoder_.reset(new FakeSoftwareVideoEncoder(video_config)); | 81 encoder_.reset(new FakeSoftwareVideoEncoder(video_config)); |
| 82 #endif | 82 #endif |
| 83 } else { | 83 } else { |
| 84 DCHECK(false) << "Invalid config"; // Codec not supported. | 84 DCHECK(false) << "Invalid config"; // Codec not supported. |
| 85 } | 85 } |
| 86 | 86 |
| 87 dynamic_config_.key_frame_requested = false; | 87 dynamic_config_.key_frame_requested = false; |
| 88 dynamic_config_.latest_frame_id_to_reference = kStartFrameId; | 88 dynamic_config_.latest_frame_id_to_reference = kStartFrameId; |
| 89 dynamic_config_.bit_rate = video_config.start_bitrate; | 89 dynamic_config_.bit_rate = video_config.start_bitrate; |
| 90 } | 90 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 dynamic_config_.key_frame_requested = true; | 129 dynamic_config_.key_frame_requested = true; |
| 130 } | 130 } |
| 131 | 131 |
| 132 // Inform the encoder to only reference frames older or equal to frame_id; | 132 // Inform the encoder to only reference frames older or equal to frame_id; |
| 133 void VideoEncoderImpl::LatestFrameIdToReference(uint32 frame_id) { | 133 void VideoEncoderImpl::LatestFrameIdToReference(uint32 frame_id) { |
| 134 dynamic_config_.latest_frame_id_to_reference = frame_id; | 134 dynamic_config_.latest_frame_id_to_reference = frame_id; |
| 135 } | 135 } |
| 136 | 136 |
| 137 } // namespace cast | 137 } // namespace cast |
| 138 } // namespace media | 138 } // namespace media |
| OLD | NEW |