Chromium Code Reviews| 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 "content/renderer/media/rtc_video_encoder.h" | 5 #include "content/renderer/media/rtc_video_encoder.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 | 157 |
| 158 enum { | 158 enum { |
| 159 kInputBufferExtraCount = 1, // The number of input buffers allocated, more | 159 kInputBufferExtraCount = 1, // The number of input buffers allocated, more |
| 160 // than what is requested by | 160 // than what is requested by |
| 161 // VEA::RequireBitstreamBuffers(). | 161 // VEA::RequireBitstreamBuffers(). |
| 162 kOutputBufferCount = 3, | 162 kOutputBufferCount = 3, |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 ~Impl() override; | 165 ~Impl() override; |
| 166 | 166 |
| 167 // Resets the class members. | |
| 168 void Reset(); | |
| 169 | |
| 167 // Logs the |error| and |str| sent from |location| and NotifyError()s forward. | 170 // Logs the |error| and |str| sent from |location| and NotifyError()s forward. |
| 168 void LogAndNotifyError(const tracked_objects::Location& location, | 171 void LogAndNotifyError(const tracked_objects::Location& location, |
| 169 const std::string& str, | 172 const std::string& str, |
| 170 media::VideoEncodeAccelerator::Error error); | 173 media::VideoEncodeAccelerator::Error error); |
| 171 | 174 |
| 172 // Perform encoding on an input frame from the input queue. | 175 // Perform encoding on an input frame from the input queue. |
| 173 void EncodeOneFrame(); | 176 void EncodeOneFrame(); |
| 174 | 177 |
| 175 // Notify that an input frame is finished for encoding. |index| is the index | 178 // Notify that an input frame is finished for encoding. |index| is the index |
| 176 // of the completed frame in |input_buffers_|. | 179 // of the completed frame in |input_buffers_|. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 | 258 |
| 256 DISALLOW_COPY_AND_ASSIGN(Impl); | 259 DISALLOW_COPY_AND_ASSIGN(Impl); |
| 257 }; | 260 }; |
| 258 | 261 |
| 259 RTCVideoEncoder::Impl::Impl(media::GpuVideoAcceleratorFactories* gpu_factories, | 262 RTCVideoEncoder::Impl::Impl(media::GpuVideoAcceleratorFactories* gpu_factories, |
| 260 webrtc::VideoCodecType video_codec_type) | 263 webrtc::VideoCodecType video_codec_type) |
| 261 : gpu_factories_(gpu_factories), | 264 : gpu_factories_(gpu_factories), |
| 262 async_waiter_(NULL), | 265 async_waiter_(NULL), |
| 263 async_retval_(NULL), | 266 async_retval_(NULL), |
| 264 input_next_frame_(NULL), | 267 input_next_frame_(NULL), |
| 265 input_next_frame_keyframe_(false), | |
| 266 output_buffers_free_count_(0), | |
| 267 encoded_image_callback_(nullptr), | 268 encoded_image_callback_(nullptr), |
| 268 video_codec_type_(video_codec_type), | 269 video_codec_type_(video_codec_type), |
| 269 status_(WEBRTC_VIDEO_CODEC_UNINITIALIZED) { | 270 status_(WEBRTC_VIDEO_CODEC_UNINITIALIZED) { |
| 270 thread_checker_.DetachFromThread(); | 271 thread_checker_.DetachFromThread(); |
| 271 // Picture ID should start on a random number. | 272 Reset(); |
|
wuchengli
2016/04/29 13:58:24
This means RTCVideoEncoder is reused after RTCVide
emircan
2016/04/29 19:37:27
Sure, reverting to earlier sounds better as the de
| |
| 272 picture_id_ = static_cast<uint16_t>(base::RandInt(0, 0x7FFF)); | |
| 273 } | 273 } |
| 274 | 274 |
| 275 void RTCVideoEncoder::Impl::CreateAndInitializeVEA( | 275 void RTCVideoEncoder::Impl::CreateAndInitializeVEA( |
| 276 const gfx::Size& input_visible_size, | 276 const gfx::Size& input_visible_size, |
| 277 uint32_t bitrate, | 277 uint32_t bitrate, |
| 278 media::VideoCodecProfile profile, | 278 media::VideoCodecProfile profile, |
| 279 base::WaitableEvent* async_waiter, | 279 base::WaitableEvent* async_waiter, |
| 280 int32_t* async_retval) { | 280 int32_t* async_retval) { |
| 281 DVLOG(3) << "Impl::CreateAndInitializeVEA()"; | 281 DVLOG(3) << "Impl::CreateAndInitializeVEA()"; |
| 282 DCHECK(thread_checker_.CalledOnValidThread()); | 282 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 video_encoder_->RequestEncodingParametersChange(bitrate * 1000, framerate); | 379 video_encoder_->RequestEncodingParametersChange(bitrate * 1000, framerate); |
| 380 } | 380 } |
| 381 | 381 |
| 382 void RTCVideoEncoder::Impl::Destroy(base::WaitableEvent* async_waiter) { | 382 void RTCVideoEncoder::Impl::Destroy(base::WaitableEvent* async_waiter) { |
| 383 DVLOG(3) << "Impl::Destroy()"; | 383 DVLOG(3) << "Impl::Destroy()"; |
| 384 DCHECK(thread_checker_.CalledOnValidThread()); | 384 DCHECK(thread_checker_.CalledOnValidThread()); |
| 385 if (video_encoder_) { | 385 if (video_encoder_) { |
| 386 video_encoder_.reset(); | 386 video_encoder_.reset(); |
| 387 SetStatus(WEBRTC_VIDEO_CODEC_UNINITIALIZED); | 387 SetStatus(WEBRTC_VIDEO_CODEC_UNINITIALIZED); |
| 388 } | 388 } |
| 389 Reset(); | |
| 389 async_waiter->Signal(); | 390 async_waiter->Signal(); |
| 390 } | 391 } |
| 391 | 392 |
| 392 int32_t RTCVideoEncoder::Impl::GetStatus() const { | 393 int32_t RTCVideoEncoder::Impl::GetStatus() const { |
| 393 base::AutoLock lock(status_lock_); | 394 base::AutoLock lock(status_lock_); |
| 394 return status_; | 395 return status_; |
| 395 } | 396 } |
| 396 | 397 |
| 397 void RTCVideoEncoder::Impl::SetStatus(int32_t status) { | 398 void RTCVideoEncoder::Impl::SetStatus(int32_t status) { |
| 398 base::AutoLock lock(status_lock_); | 399 base::AutoLock lock(status_lock_); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 | 511 |
| 511 video_encoder_.reset(); | 512 video_encoder_.reset(); |
| 512 | 513 |
| 513 SetStatus(retval); | 514 SetStatus(retval); |
| 514 if (async_waiter_) | 515 if (async_waiter_) |
| 515 SignalAsyncWaiter(retval); | 516 SignalAsyncWaiter(retval); |
| 516 } | 517 } |
| 517 | 518 |
| 518 RTCVideoEncoder::Impl::~Impl() { DCHECK(!video_encoder_); } | 519 RTCVideoEncoder::Impl::~Impl() { DCHECK(!video_encoder_); } |
| 519 | 520 |
| 521 void RTCVideoEncoder::Impl::Reset() { | |
| 522 input_next_frame_keyframe_ = false; | |
| 523 input_buffers_.clear(); | |
| 524 output_buffers_.clear(); | |
| 525 input_buffers_free_.clear(); | |
| 526 output_buffers_free_count_ = 0; | |
| 527 // Picture ID should start on a random number. | |
| 528 picture_id_ = static_cast<uint16_t>(base::RandInt(0, 0x7FFF)); | |
| 529 } | |
| 530 | |
| 520 void RTCVideoEncoder::Impl::LogAndNotifyError( | 531 void RTCVideoEncoder::Impl::LogAndNotifyError( |
| 521 const tracked_objects::Location& location, | 532 const tracked_objects::Location& location, |
| 522 const std::string& str, | 533 const std::string& str, |
| 523 media::VideoEncodeAccelerator::Error error) { | 534 media::VideoEncodeAccelerator::Error error) { |
| 524 static const char* const kErrorNames[] = { | 535 static const char* const kErrorNames[] = { |
| 525 "kIllegalStateError", "kInvalidArgumentError", "kPlatformFailureError"}; | 536 "kIllegalStateError", "kInvalidArgumentError", "kPlatformFailureError"}; |
| 526 static_assert( | 537 static_assert( |
| 527 arraysize(kErrorNames) == media::VideoEncodeAccelerator::kErrorMax + 1, | 538 arraysize(kErrorNames) == media::VideoEncodeAccelerator::kErrorMax + 1, |
| 528 "Different number of errors and textual descriptions"); | 539 "Different number of errors and textual descriptions"); |
| 529 DLOG(ERROR) << location.ToString() << kErrorNames[error] << " - " << str; | 540 DLOG(ERROR) << location.ToString() << kErrorNames[error] << " - " << str; |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", | 846 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", |
| 836 init_retval == WEBRTC_VIDEO_CODEC_OK); | 847 init_retval == WEBRTC_VIDEO_CODEC_OK); |
| 837 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { | 848 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { |
| 838 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", | 849 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", |
| 839 profile, | 850 profile, |
| 840 media::VIDEO_CODEC_PROFILE_MAX + 1); | 851 media::VIDEO_CODEC_PROFILE_MAX + 1); |
| 841 } | 852 } |
| 842 } | 853 } |
| 843 | 854 |
| 844 } // namespace content | 855 } // namespace content |
| OLD | NEW |