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/common/gpu/media/android_video_encode_accelerator.h" | 5 #include "content/common/gpu/media/android_video_encode_accelerator.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 RETURN_ON_FAILURE(frame->row_bytes(VideoFrame::kYPlane) == | 246 RETURN_ON_FAILURE(frame->row_bytes(VideoFrame::kYPlane) == |
247 frame->stride(VideoFrame::kYPlane) && | 247 frame->stride(VideoFrame::kYPlane) && |
248 frame->row_bytes(VideoFrame::kUPlane) == | 248 frame->row_bytes(VideoFrame::kUPlane) == |
249 frame->stride(VideoFrame::kUPlane) && | 249 frame->stride(VideoFrame::kUPlane) && |
250 frame->row_bytes(VideoFrame::kVPlane) == | 250 frame->row_bytes(VideoFrame::kVPlane) == |
251 frame->stride(VideoFrame::kVPlane) && | 251 frame->stride(VideoFrame::kVPlane) && |
252 frame->coded_size() == frame->visible_rect().size(), | 252 frame->coded_size() == frame->visible_rect().size(), |
253 "Non-packed frame, or visible_rect != coded_size", | 253 "Non-packed frame, or visible_rect != coded_size", |
254 kInvalidArgumentError); | 254 kInvalidArgumentError); |
255 | 255 |
256 pending_frames_.push(MakeTuple(frame, force_keyframe, base::Time::Now())); | 256 pending_frames_.push( |
| 257 base::MakeTuple(frame, force_keyframe, base::Time::Now())); |
257 DoIOTask(); | 258 DoIOTask(); |
258 } | 259 } |
259 | 260 |
260 void AndroidVideoEncodeAccelerator::UseOutputBitstreamBuffer( | 261 void AndroidVideoEncodeAccelerator::UseOutputBitstreamBuffer( |
261 const media::BitstreamBuffer& buffer) { | 262 const media::BitstreamBuffer& buffer) { |
262 DVLOG(3) << __PRETTY_FUNCTION__ << ": bitstream_buffer_id=" << buffer.id(); | 263 DVLOG(3) << __PRETTY_FUNCTION__ << ": bitstream_buffer_id=" << buffer.id(); |
263 DCHECK(thread_checker_.CalledOnValidThread()); | 264 DCHECK(thread_checker_.CalledOnValidThread()); |
264 RETURN_ON_FAILURE(buffer.size() >= media_codec_->GetOutputBuffersCapacity(), | 265 RETURN_ON_FAILURE(buffer.size() >= media_codec_->GetOutputBuffersCapacity(), |
265 "Output buffers too small!", | 266 "Output buffers too small!", |
266 kInvalidArgumentError); | 267 kInvalidArgumentError); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 if (status != media::MEDIA_CODEC_OK) { | 314 if (status != media::MEDIA_CODEC_OK) { |
314 DCHECK(status == media::MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER || | 315 DCHECK(status == media::MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER || |
315 status == media::MEDIA_CODEC_ERROR); | 316 status == media::MEDIA_CODEC_ERROR); |
316 RETURN_ON_FAILURE(status != media::MEDIA_CODEC_ERROR, | 317 RETURN_ON_FAILURE(status != media::MEDIA_CODEC_ERROR, |
317 "MediaCodec error", | 318 "MediaCodec error", |
318 kPlatformFailureError); | 319 kPlatformFailureError); |
319 return; | 320 return; |
320 } | 321 } |
321 | 322 |
322 const PendingFrames::value_type& input = pending_frames_.front(); | 323 const PendingFrames::value_type& input = pending_frames_.front(); |
323 bool is_key_frame = get<1>(input); | 324 bool is_key_frame = base::get<1>(input); |
324 if (is_key_frame) { | 325 if (is_key_frame) { |
325 // Ideally MediaCodec would honor BUFFER_FLAG_SYNC_FRAME so we could | 326 // Ideally MediaCodec would honor BUFFER_FLAG_SYNC_FRAME so we could |
326 // indicate this in the QueueInputBuffer() call below and guarantee _this_ | 327 // indicate this in the QueueInputBuffer() call below and guarantee _this_ |
327 // frame be encoded as a key frame, but sadly that flag is ignored. | 328 // frame be encoded as a key frame, but sadly that flag is ignored. |
328 // Instead, we request a key frame "soon". | 329 // Instead, we request a key frame "soon". |
329 media_codec_->RequestKeyFrameSoon(); | 330 media_codec_->RequestKeyFrameSoon(); |
330 } | 331 } |
331 scoped_refptr<VideoFrame> frame = get<0>(input); | 332 scoped_refptr<VideoFrame> frame = base::get<0>(input); |
332 | 333 |
333 uint8* buffer = NULL; | 334 uint8* buffer = NULL; |
334 size_t capacity = 0; | 335 size_t capacity = 0; |
335 media_codec_->GetInputBuffer(input_buf_index, &buffer, &capacity); | 336 media_codec_->GetInputBuffer(input_buf_index, &buffer, &capacity); |
336 | 337 |
337 size_t queued_size = | 338 size_t queued_size = |
338 VideoFrame::AllocationSize(VideoFrame::I420, frame->coded_size()); | 339 VideoFrame::AllocationSize(VideoFrame::I420, frame->coded_size()); |
339 RETURN_ON_FAILURE(capacity >= queued_size, | 340 RETURN_ON_FAILURE(capacity >= queued_size, |
340 "Failed to get input buffer: " << input_buf_index, | 341 "Failed to get input buffer: " << input_buf_index, |
341 kPlatformFailureError); | 342 kPlatformFailureError); |
(...skipping 16 matching lines...) Expand all Loading... |
358 dst_uv, | 359 dst_uv, |
359 dst_stride_uv, | 360 dst_stride_uv, |
360 frame->coded_size().width(), | 361 frame->coded_size().width(), |
361 frame->coded_size().height()); | 362 frame->coded_size().height()); |
362 RETURN_ON_FAILURE(converted, "Failed to I420ToNV12!", kPlatformFailureError); | 363 RETURN_ON_FAILURE(converted, "Failed to I420ToNV12!", kPlatformFailureError); |
363 | 364 |
364 fake_input_timestamp_ += base::TimeDelta::FromMicroseconds(1); | 365 fake_input_timestamp_ += base::TimeDelta::FromMicroseconds(1); |
365 status = media_codec_->QueueInputBuffer( | 366 status = media_codec_->QueueInputBuffer( |
366 input_buf_index, NULL, queued_size, fake_input_timestamp_); | 367 input_buf_index, NULL, queued_size, fake_input_timestamp_); |
367 UMA_HISTOGRAM_TIMES("Media.AVEA.InputQueueTime", | 368 UMA_HISTOGRAM_TIMES("Media.AVEA.InputQueueTime", |
368 base::Time::Now() - get<2>(input)); | 369 base::Time::Now() - base::get<2>(input)); |
369 RETURN_ON_FAILURE(status == media::MEDIA_CODEC_OK, | 370 RETURN_ON_FAILURE(status == media::MEDIA_CODEC_OK, |
370 "Failed to QueueInputBuffer: " << status, | 371 "Failed to QueueInputBuffer: " << status, |
371 kPlatformFailureError); | 372 kPlatformFailureError); |
372 ++num_buffers_at_codec_; | 373 ++num_buffers_at_codec_; |
373 pending_frames_.pop(); | 374 pending_frames_.pop(); |
374 } | 375 } |
375 | 376 |
376 bool AndroidVideoEncodeAccelerator::DoOutputBuffersSuffice() { | 377 bool AndroidVideoEncodeAccelerator::DoOutputBuffersSuffice() { |
377 // If this returns false ever, then the VEA::Client interface will need to | 378 // If this returns false ever, then the VEA::Client interface will need to |
378 // grow a DismissBitstreamBuffer() call, and VEA::Client impls will have to be | 379 // grow a DismissBitstreamBuffer() call, and VEA::Client impls will have to be |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 base::MessageLoop::current()->PostTask( | 448 base::MessageLoop::current()->PostTask( |
448 FROM_HERE, | 449 FROM_HERE, |
449 base::Bind(&VideoEncodeAccelerator::Client::BitstreamBufferReady, | 450 base::Bind(&VideoEncodeAccelerator::Client::BitstreamBufferReady, |
450 client_ptr_factory_->GetWeakPtr(), | 451 client_ptr_factory_->GetWeakPtr(), |
451 bitstream_buffer.id(), | 452 bitstream_buffer.id(), |
452 size, | 453 size, |
453 key_frame)); | 454 key_frame)); |
454 } | 455 } |
455 | 456 |
456 } // namespace content | 457 } // namespace content |
OLD | NEW |