| 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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 // Ideally MediaCodec would honor BUFFER_FLAG_SYNC_FRAME so we could | 328 // Ideally MediaCodec would honor BUFFER_FLAG_SYNC_FRAME so we could |
| 329 // indicate this in the QueueInputBuffer() call below and guarantee _this_ | 329 // indicate this in the QueueInputBuffer() call below and guarantee _this_ |
| 330 // frame be encoded as a key frame, but sadly that flag is ignored. | 330 // frame be encoded as a key frame, but sadly that flag is ignored. |
| 331 // Instead, we request a key frame "soon". | 331 // Instead, we request a key frame "soon". |
| 332 media_codec_->RequestKeyFrameSoon(); | 332 media_codec_->RequestKeyFrameSoon(); |
| 333 } | 333 } |
| 334 scoped_refptr<VideoFrame> frame = base::get<0>(input); | 334 scoped_refptr<VideoFrame> frame = base::get<0>(input); |
| 335 | 335 |
| 336 uint8_t* buffer = NULL; | 336 uint8_t* buffer = NULL; |
| 337 size_t capacity = 0; | 337 size_t capacity = 0; |
| 338 media_codec_->GetInputBuffer(input_buf_index, &buffer, &capacity); | 338 status = media_codec_->GetInputBuffer(input_buf_index, &buffer, &capacity); |
| 339 RETURN_ON_FAILURE(status == media::MEDIA_CODEC_OK, "GetInputBuffer failed.", |
| 340 kPlatformFailureError); |
| 339 | 341 |
| 340 size_t queued_size = | 342 size_t queued_size = |
| 341 VideoFrame::AllocationSize(media::PIXEL_FORMAT_I420, frame->coded_size()); | 343 VideoFrame::AllocationSize(media::PIXEL_FORMAT_I420, frame->coded_size()); |
| 342 RETURN_ON_FAILURE(capacity >= queued_size, | 344 RETURN_ON_FAILURE(capacity >= queued_size, |
| 343 "Failed to get input buffer: " << input_buf_index, | 345 "Failed to get input buffer: " << input_buf_index, |
| 344 kPlatformFailureError); | 346 kPlatformFailureError); |
| 345 | 347 |
| 346 uint8_t* dst_y = buffer; | 348 uint8_t* dst_y = buffer; |
| 347 int dst_stride_y = frame->stride(VideoFrame::kYPlane); | 349 int dst_stride_y = frame->stride(VideoFrame::kYPlane); |
| 348 uint8_t* dst_uv = | 350 uint8_t* dst_uv = |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 scoped_ptr<base::SharedMemory> shm( | 424 scoped_ptr<base::SharedMemory> shm( |
| 423 new base::SharedMemory(bitstream_buffer.handle(), false)); | 425 new base::SharedMemory(bitstream_buffer.handle(), false)); |
| 424 RETURN_ON_FAILURE(shm->Map(bitstream_buffer.size()), | 426 RETURN_ON_FAILURE(shm->Map(bitstream_buffer.size()), |
| 425 "Failed to map SHM", | 427 "Failed to map SHM", |
| 426 kPlatformFailureError); | 428 kPlatformFailureError); |
| 427 RETURN_ON_FAILURE(size <= shm->mapped_size(), | 429 RETURN_ON_FAILURE(size <= shm->mapped_size(), |
| 428 "Encoded buffer too large: " << size << ">" | 430 "Encoded buffer too large: " << size << ">" |
| 429 << shm->mapped_size(), | 431 << shm->mapped_size(), |
| 430 kPlatformFailureError); | 432 kPlatformFailureError); |
| 431 | 433 |
| 432 media_codec_->CopyFromOutputBuffer(buf_index, offset, shm->memory(), size); | 434 media::MediaCodecStatus status = media_codec_->CopyFromOutputBuffer( |
| 435 buf_index, offset, shm->memory(), size); |
| 436 RETURN_ON_FAILURE(status == media::MEDIA_CODEC_OK, |
| 437 "CopyFromOutputBuffer failed", kPlatformFailureError); |
| 433 media_codec_->ReleaseOutputBuffer(buf_index, false); | 438 media_codec_->ReleaseOutputBuffer(buf_index, false); |
| 434 --num_buffers_at_codec_; | 439 --num_buffers_at_codec_; |
| 435 | 440 |
| 436 UMA_HISTOGRAM_COUNTS_10000("Media.AVEA.EncodedBufferSizeKB", size / 1024); | 441 UMA_HISTOGRAM_COUNTS_10000("Media.AVEA.EncodedBufferSizeKB", size / 1024); |
| 437 base::MessageLoop::current()->PostTask( | 442 base::MessageLoop::current()->PostTask( |
| 438 FROM_HERE, | 443 FROM_HERE, |
| 439 base::Bind(&VideoEncodeAccelerator::Client::BitstreamBufferReady, | 444 base::Bind(&VideoEncodeAccelerator::Client::BitstreamBufferReady, |
| 440 client_ptr_factory_->GetWeakPtr(), | 445 client_ptr_factory_->GetWeakPtr(), |
| 441 bitstream_buffer.id(), | 446 bitstream_buffer.id(), |
| 442 size, | 447 size, |
| 443 key_frame)); | 448 key_frame)); |
| 444 } | 449 } |
| 445 | 450 |
| 446 } // namespace content | 451 } // namespace content |
| OLD | NEW |