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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 void UseOutputBitstreamBufferId(int32 bitstream_buffer_id); | 69 void UseOutputBitstreamBufferId(int32 bitstream_buffer_id); |
70 | 70 |
71 // Request encoding parameter change for the underlying encoder. | 71 // Request encoding parameter change for the underlying encoder. |
72 void RequestEncodingParametersChange(uint32 bitrate, uint32 framerate); | 72 void RequestEncodingParametersChange(uint32 bitrate, uint32 framerate); |
73 | 73 |
74 // Destroy this Impl's encoder. The destructor is not explicitly called, as | 74 // Destroy this Impl's encoder. The destructor is not explicitly called, as |
75 // Impl is a base::RefCountedThreadSafe. | 75 // Impl is a base::RefCountedThreadSafe. |
76 void Destroy(); | 76 void Destroy(); |
77 | 77 |
78 // media::VideoEncodeAccelerator::Client implementation. | 78 // media::VideoEncodeAccelerator::Client implementation. |
79 virtual void NotifyInitializeDone() OVERRIDE; | |
80 virtual void RequireBitstreamBuffers(unsigned int input_count, | 79 virtual void RequireBitstreamBuffers(unsigned int input_count, |
81 const gfx::Size& input_coded_size, | 80 const gfx::Size& input_coded_size, |
82 size_t output_buffer_size) OVERRIDE; | 81 size_t output_buffer_size) OVERRIDE; |
83 virtual void BitstreamBufferReady(int32 bitstream_buffer_id, | 82 virtual void BitstreamBufferReady(int32 bitstream_buffer_id, |
84 size_t payload_size, | 83 size_t payload_size, |
85 bool key_frame) OVERRIDE; | 84 bool key_frame) OVERRIDE; |
86 virtual void NotifyError(media::VideoEncodeAccelerator::Error error) OVERRIDE; | 85 virtual void NotifyError(media::VideoEncodeAccelerator::Error error) OVERRIDE; |
87 | 86 |
88 private: | 87 private: |
89 friend class base::RefCountedThreadSafe<Impl>; | 88 friend class base::RefCountedThreadSafe<Impl>; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 NOTIFY_ERROR(media::VideoEncodeAccelerator::kInvalidArgumentError); | 190 NOTIFY_ERROR(media::VideoEncodeAccelerator::kInvalidArgumentError); |
192 return; | 191 return; |
193 } | 192 } |
194 | 193 |
195 video_encoder_ = gpu_factories_->CreateVideoEncodeAccelerator().Pass(); | 194 video_encoder_ = gpu_factories_->CreateVideoEncodeAccelerator().Pass(); |
196 if (!video_encoder_) { | 195 if (!video_encoder_) { |
197 NOTIFY_ERROR(media::VideoEncodeAccelerator::kPlatformFailureError); | 196 NOTIFY_ERROR(media::VideoEncodeAccelerator::kPlatformFailureError); |
198 return; | 197 return; |
199 } | 198 } |
200 input_visible_size_ = input_visible_size; | 199 input_visible_size_ = input_visible_size; |
201 video_encoder_->Initialize(media::VideoFrame::I420, | 200 if (!video_encoder_->Initialize(media::VideoFrame::I420, |
202 input_visible_size_, | 201 input_visible_size_, |
203 profile, | 202 profile, |
204 bitrate * 1000, | 203 bitrate * 1000, |
205 this); | 204 this)) { |
| 205 NOTIFY_ERROR(media::VideoEncodeAccelerator::kInvalidArgumentError); |
| 206 return; |
| 207 } |
206 } | 208 } |
207 | 209 |
208 void RTCVideoEncoder::Impl::Enqueue(const webrtc::I420VideoFrame* input_frame, | 210 void RTCVideoEncoder::Impl::Enqueue(const webrtc::I420VideoFrame* input_frame, |
209 bool force_keyframe, | 211 bool force_keyframe, |
210 base::WaitableEvent* async_waiter, | 212 base::WaitableEvent* async_waiter, |
211 int32_t* async_retval) { | 213 int32_t* async_retval) { |
212 DVLOG(3) << "Impl::Enqueue()"; | 214 DVLOG(3) << "Impl::Enqueue()"; |
213 DCHECK(thread_checker_.CalledOnValidThread()); | 215 DCHECK(thread_checker_.CalledOnValidThread()); |
214 DCHECK(!input_next_frame_); | 216 DCHECK(!input_next_frame_); |
215 | 217 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 video_encoder_->RequestEncodingParametersChange(bitrate * 1000, framerate); | 276 video_encoder_->RequestEncodingParametersChange(bitrate * 1000, framerate); |
275 } | 277 } |
276 | 278 |
277 void RTCVideoEncoder::Impl::Destroy() { | 279 void RTCVideoEncoder::Impl::Destroy() { |
278 DVLOG(3) << "Impl::Destroy()"; | 280 DVLOG(3) << "Impl::Destroy()"; |
279 DCHECK(thread_checker_.CalledOnValidThread()); | 281 DCHECK(thread_checker_.CalledOnValidThread()); |
280 if (video_encoder_) | 282 if (video_encoder_) |
281 video_encoder_.release()->Destroy(); | 283 video_encoder_.release()->Destroy(); |
282 } | 284 } |
283 | 285 |
284 void RTCVideoEncoder::Impl::NotifyInitializeDone() { | |
285 DVLOG(3) << "Impl::NotifyInitializeDone()"; | |
286 DCHECK(thread_checker_.CalledOnValidThread()); | |
287 } | |
288 | |
289 void RTCVideoEncoder::Impl::RequireBitstreamBuffers( | 286 void RTCVideoEncoder::Impl::RequireBitstreamBuffers( |
290 unsigned int input_count, | 287 unsigned int input_count, |
291 const gfx::Size& input_coded_size, | 288 const gfx::Size& input_coded_size, |
292 size_t output_buffer_size) { | 289 size_t output_buffer_size) { |
293 DVLOG(3) << "Impl::RequireBitstreamBuffers(): input_count=" << input_count | 290 DVLOG(3) << "Impl::RequireBitstreamBuffers(): input_count=" << input_count |
294 << ", input_coded_size=" << input_coded_size.ToString() | 291 << ", input_coded_size=" << input_coded_size.ToString() |
295 << ", output_buffer_size=" << output_buffer_size; | 292 << ", output_buffer_size=" << output_buffer_size; |
296 DCHECK(thread_checker_.CalledOnValidThread()); | 293 DCHECK(thread_checker_.CalledOnValidThread()); |
297 | 294 |
298 if (!video_encoder_) | 295 if (!video_encoder_) |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", | 700 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", |
704 init_retval == WEBRTC_VIDEO_CODEC_OK); | 701 init_retval == WEBRTC_VIDEO_CODEC_OK); |
705 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { | 702 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { |
706 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", | 703 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", |
707 video_codec_profile_, | 704 video_codec_profile_, |
708 media::VIDEO_CODEC_PROFILE_MAX + 1); | 705 media::VIDEO_CODEC_PROFILE_MAX + 1); |
709 } | 706 } |
710 } | 707 } |
711 | 708 |
712 } // namespace content | 709 } // namespace content |
OLD | NEW |