| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 void UseOutputBitstreamBufferId(int32 bitstream_buffer_id); | 68 void UseOutputBitstreamBufferId(int32 bitstream_buffer_id); |
| 69 | 69 |
| 70 // Request encoding parameter change for the underlying encoder. | 70 // Request encoding parameter change for the underlying encoder. |
| 71 void RequestEncodingParametersChange(uint32 bitrate, uint32 framerate); | 71 void RequestEncodingParametersChange(uint32 bitrate, uint32 framerate); |
| 72 | 72 |
| 73 // Destroy this Impl's encoder. The destructor is not explicitly called, as | 73 // Destroy this Impl's encoder. The destructor is not explicitly called, as |
| 74 // Impl is a base::RefCountedThreadSafe. | 74 // Impl is a base::RefCountedThreadSafe. |
| 75 void Destroy(); | 75 void Destroy(); |
| 76 | 76 |
| 77 // media::VideoEncodeAccelerator::Client implementation. | 77 // media::VideoEncodeAccelerator::Client implementation. |
| 78 virtual void NotifyInitializeDone() OVERRIDE; | |
| 79 virtual void RequireBitstreamBuffers(unsigned int input_count, | 78 virtual void RequireBitstreamBuffers(unsigned int input_count, |
| 80 const gfx::Size& input_coded_size, | 79 const gfx::Size& input_coded_size, |
| 81 size_t output_buffer_size) OVERRIDE; | 80 size_t output_buffer_size) OVERRIDE; |
| 82 virtual void BitstreamBufferReady(int32 bitstream_buffer_id, | 81 virtual void BitstreamBufferReady(int32 bitstream_buffer_id, |
| 83 size_t payload_size, | 82 size_t payload_size, |
| 84 bool key_frame) OVERRIDE; | 83 bool key_frame) OVERRIDE; |
| 85 virtual void NotifyError(media::VideoEncodeAccelerator::Error error) OVERRIDE; | 84 virtual void NotifyError(media::VideoEncodeAccelerator::Error error) OVERRIDE; |
| 86 | 85 |
| 87 private: | 86 private: |
| 88 friend class base::RefCountedThreadSafe<Impl>; | 87 friend class base::RefCountedThreadSafe<Impl>; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 NOTIFY_ERROR(media::VideoEncodeAccelerator::kInvalidArgumentError); | 179 NOTIFY_ERROR(media::VideoEncodeAccelerator::kInvalidArgumentError); |
| 181 return; | 180 return; |
| 182 } | 181 } |
| 183 | 182 |
| 184 video_encoder_ = gpu_factories_->CreateVideoEncodeAccelerator().Pass(); | 183 video_encoder_ = gpu_factories_->CreateVideoEncodeAccelerator().Pass(); |
| 185 if (!video_encoder_) { | 184 if (!video_encoder_) { |
| 186 NOTIFY_ERROR(media::VideoEncodeAccelerator::kPlatformFailureError); | 185 NOTIFY_ERROR(media::VideoEncodeAccelerator::kPlatformFailureError); |
| 187 return; | 186 return; |
| 188 } | 187 } |
| 189 input_visible_size_ = input_visible_size; | 188 input_visible_size_ = input_visible_size; |
| 190 video_encoder_->Initialize(media::VideoFrame::I420, | 189 if (!video_encoder_->Initialize(media::VideoFrame::I420, |
| 191 input_visible_size_, | 190 input_visible_size_, |
| 192 profile, | 191 profile, |
| 193 bitrate * 1000, | 192 bitrate * 1000, |
| 194 this); | 193 this)) { |
| 194 NOTIFY_ERROR(media::VideoEncodeAccelerator::kInvalidArgumentError); |
| 195 return; |
| 196 } |
| 195 } | 197 } |
| 196 | 198 |
| 197 void RTCVideoEncoder::Impl::Enqueue(const webrtc::I420VideoFrame* input_frame, | 199 void RTCVideoEncoder::Impl::Enqueue(const webrtc::I420VideoFrame* input_frame, |
| 198 bool force_keyframe, | 200 bool force_keyframe, |
| 199 base::WaitableEvent* async_waiter, | 201 base::WaitableEvent* async_waiter, |
| 200 int32_t* async_retval) { | 202 int32_t* async_retval) { |
| 201 DVLOG(3) << "Impl::Enqueue()"; | 203 DVLOG(3) << "Impl::Enqueue()"; |
| 202 DCHECK(thread_checker_.CalledOnValidThread()); | 204 DCHECK(thread_checker_.CalledOnValidThread()); |
| 203 DCHECK(!input_next_frame_); | 205 DCHECK(!input_next_frame_); |
| 204 | 206 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 video_encoder_->RequestEncodingParametersChange(bitrate * 1000, framerate); | 241 video_encoder_->RequestEncodingParametersChange(bitrate * 1000, framerate); |
| 240 } | 242 } |
| 241 | 243 |
| 242 void RTCVideoEncoder::Impl::Destroy() { | 244 void RTCVideoEncoder::Impl::Destroy() { |
| 243 DVLOG(3) << "Impl::Destroy()"; | 245 DVLOG(3) << "Impl::Destroy()"; |
| 244 DCHECK(thread_checker_.CalledOnValidThread()); | 246 DCHECK(thread_checker_.CalledOnValidThread()); |
| 245 if (video_encoder_) | 247 if (video_encoder_) |
| 246 video_encoder_.release()->Destroy(); | 248 video_encoder_.release()->Destroy(); |
| 247 } | 249 } |
| 248 | 250 |
| 249 void RTCVideoEncoder::Impl::NotifyInitializeDone() { | |
| 250 DVLOG(3) << "Impl::NotifyInitializeDone()"; | |
| 251 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 252 } | |
| 253 | |
| 254 void RTCVideoEncoder::Impl::RequireBitstreamBuffers( | 251 void RTCVideoEncoder::Impl::RequireBitstreamBuffers( |
| 255 unsigned int input_count, | 252 unsigned int input_count, |
| 256 const gfx::Size& input_coded_size, | 253 const gfx::Size& input_coded_size, |
| 257 size_t output_buffer_size) { | 254 size_t output_buffer_size) { |
| 258 DVLOG(3) << "Impl::RequireBitstreamBuffers(): input_count=" << input_count | 255 DVLOG(3) << "Impl::RequireBitstreamBuffers(): input_count=" << input_count |
| 259 << ", input_coded_size=" << input_coded_size.ToString() | 256 << ", input_coded_size=" << input_coded_size.ToString() |
| 260 << ", output_buffer_size=" << output_buffer_size; | 257 << ", output_buffer_size=" << output_buffer_size; |
| 261 DCHECK(thread_checker_.CalledOnValidThread()); | 258 DCHECK(thread_checker_.CalledOnValidThread()); |
| 262 | 259 |
| 263 if (!video_encoder_) | 260 if (!video_encoder_) |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", | 656 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", |
| 660 init_retval == WEBRTC_VIDEO_CODEC_OK); | 657 init_retval == WEBRTC_VIDEO_CODEC_OK); |
| 661 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { | 658 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { |
| 662 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", | 659 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", |
| 663 video_codec_profile_, | 660 video_codec_profile_, |
| 664 media::VIDEO_CODEC_PROFILE_MAX + 1); | 661 media::VIDEO_CODEC_PROFILE_MAX + 1); |
| 665 } | 662 } |
| 666 } | 663 } |
| 667 | 664 |
| 668 } // namespace content | 665 } // namespace content |
| OLD | NEW |