| 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_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/sender/fake_software_video_encoder.h" | 14 #include "media/cast/sender/fake_software_video_encoder.h" |
| 15 #if !defined(MEDIA_DISABLE_LIBVPX) | |
| 16 #include "media/cast/sender/vp8_encoder.h" | 15 #include "media/cast/sender/vp8_encoder.h" |
| 17 #endif // !defined(MEDIA_DISABLE_LIBVPX) | |
| 18 | 16 |
| 19 namespace media { | 17 namespace media { |
| 20 namespace cast { | 18 namespace cast { |
| 21 | 19 |
| 22 namespace { | 20 namespace { |
| 23 | 21 |
| 24 #if !defined(MEDIA_DISABLE_LIBVPX) | |
| 25 typedef base::Callback<void(Vp8Encoder*)> PassEncoderCallback; | 22 typedef base::Callback<void(Vp8Encoder*)> PassEncoderCallback; |
| 26 | 23 |
| 27 void InitializeEncoderOnEncoderThread( | 24 void InitializeEncoderOnEncoderThread( |
| 28 const scoped_refptr<CastEnvironment>& environment, | 25 const scoped_refptr<CastEnvironment>& environment, |
| 29 SoftwareVideoEncoder* encoder) { | 26 SoftwareVideoEncoder* encoder) { |
| 30 DCHECK(environment->CurrentlyOn(CastEnvironment::VIDEO)); | 27 DCHECK(environment->CurrentlyOn(CastEnvironment::VIDEO)); |
| 31 encoder->Initialize(); | 28 encoder->Initialize(); |
| 32 } | 29 } |
| 33 #endif // !defined(MEDIA_DISABLE_LIBVPX) | |
| 34 | 30 |
| 35 void EncodeVideoFrameOnEncoderThread( | 31 void EncodeVideoFrameOnEncoderThread( |
| 36 scoped_refptr<CastEnvironment> environment, | 32 scoped_refptr<CastEnvironment> environment, |
| 37 SoftwareVideoEncoder* encoder, | 33 SoftwareVideoEncoder* encoder, |
| 38 const scoped_refptr<media::VideoFrame>& video_frame, | 34 const scoped_refptr<media::VideoFrame>& video_frame, |
| 39 const base::TimeTicks& capture_time, | 35 const base::TimeTicks& capture_time, |
| 40 const VideoEncoderImpl::CodecDynamicConfig& dynamic_config, | 36 const VideoEncoderImpl::CodecDynamicConfig& dynamic_config, |
| 41 const VideoEncoderImpl::FrameEncodedCallback& frame_encoded_callback) { | 37 const VideoEncoderImpl::FrameEncodedCallback& frame_encoded_callback) { |
| 42 DCHECK(environment->CurrentlyOn(CastEnvironment::VIDEO)); | 38 DCHECK(environment->CurrentlyOn(CastEnvironment::VIDEO)); |
| 43 if (dynamic_config.key_frame_requested) { | 39 if (dynamic_config.key_frame_requested) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 67 frame_encoded_callback, base::Passed(&encoded_frame))); | 63 frame_encoded_callback, base::Passed(&encoded_frame))); |
| 68 } | 64 } |
| 69 } // namespace | 65 } // namespace |
| 70 | 66 |
| 71 VideoEncoderImpl::VideoEncoderImpl( | 67 VideoEncoderImpl::VideoEncoderImpl( |
| 72 scoped_refptr<CastEnvironment> cast_environment, | 68 scoped_refptr<CastEnvironment> cast_environment, |
| 73 const VideoSenderConfig& video_config, | 69 const VideoSenderConfig& video_config, |
| 74 int max_unacked_frames) | 70 int max_unacked_frames) |
| 75 : cast_environment_(cast_environment) { | 71 : cast_environment_(cast_environment) { |
| 76 if (video_config.codec == CODEC_VIDEO_VP8) { | 72 if (video_config.codec == CODEC_VIDEO_VP8) { |
| 77 #if !defined(MEDIA_DISABLE_LIBVPX) | |
| 78 encoder_.reset(new Vp8Encoder(video_config, max_unacked_frames)); | 73 encoder_.reset(new Vp8Encoder(video_config, max_unacked_frames)); |
| 79 cast_environment_->PostTask(CastEnvironment::VIDEO, | 74 cast_environment_->PostTask(CastEnvironment::VIDEO, |
| 80 FROM_HERE, | 75 FROM_HERE, |
| 81 base::Bind(&InitializeEncoderOnEncoderThread, | 76 base::Bind(&InitializeEncoderOnEncoderThread, |
| 82 cast_environment, | 77 cast_environment, |
| 83 encoder_.get())); | 78 encoder_.get())); |
| 84 #endif // !defined(MEDIA_DISABLE_LIBVPX) | |
| 85 #ifndef OFFICIAL_BUILD | 79 #ifndef OFFICIAL_BUILD |
| 86 } else if (video_config.codec == CODEC_VIDEO_FAKE) { | 80 } else if (video_config.codec == CODEC_VIDEO_FAKE) { |
| 87 encoder_.reset(new FakeSoftwareVideoEncoder(video_config)); | 81 encoder_.reset(new FakeSoftwareVideoEncoder(video_config)); |
| 88 #endif | 82 #endif |
| 89 } else { | 83 } else { |
| 90 DCHECK(false) << "Invalid config"; // Codec not supported. | 84 DCHECK(false) << "Invalid config"; // Codec not supported. |
| 91 } | 85 } |
| 92 | 86 |
| 93 dynamic_config_.key_frame_requested = false; | 87 dynamic_config_.key_frame_requested = false; |
| 94 dynamic_config_.latest_frame_id_to_reference = kStartFrameId; | 88 dynamic_config_.latest_frame_id_to_reference = kStartFrameId; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 dynamic_config_.key_frame_requested = true; | 129 dynamic_config_.key_frame_requested = true; |
| 136 } | 130 } |
| 137 | 131 |
| 138 // 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; |
| 139 void VideoEncoderImpl::LatestFrameIdToReference(uint32 frame_id) { | 133 void VideoEncoderImpl::LatestFrameIdToReference(uint32 frame_id) { |
| 140 dynamic_config_.latest_frame_id_to_reference = frame_id; | 134 dynamic_config_.latest_frame_id_to_reference = frame_id; |
| 141 } | 135 } |
| 142 | 136 |
| 143 } // namespace cast | 137 } // namespace cast |
| 144 } // namespace media | 138 } // namespace media |
| OLD | NEW |