Index: media/cast/video_sender/codecs/vp8/vp8_encoder.cc |
diff --git a/media/cast/video_sender/codecs/vp8/vp8_encoder.cc b/media/cast/video_sender/codecs/vp8/vp8_encoder.cc |
index 595a0cab1f955234c8c3194abf7b7eb7f388a685..c977dd2b3724eddcd47807006d689a33fb34662a 100644 |
--- a/media/cast/video_sender/codecs/vp8/vp8_encoder.cc |
+++ b/media/cast/video_sender/codecs/vp8/vp8_encoder.cc |
@@ -28,13 +28,6 @@ Vp8Encoder::Vp8Encoder(const VideoSenderConfig& video_config, |
max_number_of_repeated_buffers_in_a_row_( |
(max_unacked_frames > kNumberOfVp8VideoBuffers) ? |
((max_unacked_frames - 1) / kNumberOfVp8VideoBuffers) : 0), |
- config_(new vpx_codec_enc_cfg_t()), |
- encoder_(new vpx_codec_ctx_t()), |
- // Creating a wrapper to the image - setting image data to NULL. Actual |
- // pointer will be set during encode. Setting align to 1, as it is |
- // meaningless (actual memory is not allocated). |
- raw_image_(vpx_img_wrap(NULL, IMG_FMT_I420, video_config.width, |
- video_config.height, 1, NULL)), |
key_frame_requested_(true), |
timestamp_(0), |
last_encoded_frame_id_(kStartFrameId), |
@@ -55,11 +48,7 @@ Vp8Encoder::Vp8Encoder(const VideoSenderConfig& video_config, |
cast_config_.max_number_of_video_buffers_used == |
kNumberOfVp8VideoBuffers) << "Invalid argument"; |
- for (int i = 0; i < kNumberOfVp8VideoBuffers; ++i) { |
- acked_frame_buffers_[i] = true; |
- used_buffers_frame_id_[i] = kStartFrameId; |
- } |
- InitEncode(video_config.number_of_cores); |
+ thread_checker_.DetachFromThread(); |
} |
Vp8Encoder::~Vp8Encoder() { |
@@ -67,7 +56,26 @@ Vp8Encoder::~Vp8Encoder() { |
vpx_img_free(raw_image_); |
} |
+void Vp8Encoder::Initialize() { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ config_.reset(new vpx_codec_enc_cfg_t()); |
+ encoder_.reset(new vpx_codec_ctx_t()); |
+ |
+ // Creating a wrapper to the image - setting image data to NULL. Actual |
+ // pointer will be set during encode. Setting align to 1, as it is |
+ // meaningless (actual memory is not allocated). |
+ raw_image_ = vpx_img_wrap(NULL, IMG_FMT_I420, cast_config_.width, |
+ cast_config_.height, 1, NULL); |
+ |
+ for (int i = 0; i < kNumberOfVp8VideoBuffers; ++i) { |
+ acked_frame_buffers_[i] = true; |
+ used_buffers_frame_id_[i] = kStartFrameId; |
+ } |
+ InitEncode(cast_config_.number_of_cores); |
+} |
+ |
void Vp8Encoder::InitEncode(int number_of_cores) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
// Populate encoder configuration with default values. |
if (vpx_codec_enc_config_default(vpx_codec_vp8_cx(), config_.get(), 0)) { |
DCHECK(false) << "Invalid return value"; |
@@ -129,6 +137,7 @@ void Vp8Encoder::InitEncode(int number_of_cores) { |
bool Vp8Encoder::Encode(const scoped_refptr<media::VideoFrame>& video_frame, |
transport::EncodedVideoFrame* encoded_image) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
// Image in vpx_image_t format. |
// Input image is const. VP8's raw image is not defined as const. |
raw_image_->planes[PLANE_Y] = |
@@ -334,6 +343,7 @@ void Vp8Encoder::GetCodecUpdateFlags(Vp8Buffers buffer_to_update, |
} |
void Vp8Encoder::UpdateRates(uint32 new_bitrate) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
uint32 new_bitrate_kbit = new_bitrate / 1000; |
if (config_->rc_target_bitrate == new_bitrate_kbit) return; |
@@ -346,6 +356,7 @@ void Vp8Encoder::UpdateRates(uint32 new_bitrate) { |
} |
void Vp8Encoder::LatestFrameIdToReference(uint32 frame_id) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
if (!use_multiple_video_buffers_) return; |
VLOG(1) << "VP8 ok to reference frame:" << static_cast<int>(frame_id); |
@@ -357,6 +368,7 @@ void Vp8Encoder::LatestFrameIdToReference(uint32 frame_id) { |
} |
void Vp8Encoder::GenerateKeyFrame() { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
key_frame_requested_ = true; |
} |