| 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 "media/gpu/android_video_encode_accelerator.h" | 5 #include "media/gpu/android_video_encode_accelerator.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <tuple> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 14 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 15 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 15 #include "gpu/ipc/service/gpu_channel.h" | 16 #include "gpu/ipc/service/gpu_channel.h" |
| 16 #include "media/base/android/media_codec_util.h" | 17 #include "media/base/android/media_codec_util.h" |
| 17 #include "media/base/bitstream_buffer.h" | 18 #include "media/base/bitstream_buffer.h" |
| 18 #include "media/base/limits.h" | 19 #include "media/base/limits.h" |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 frame->stride(VideoFrame::kYPlane) && | 241 frame->stride(VideoFrame::kYPlane) && |
| 241 frame->row_bytes(VideoFrame::kUPlane) == | 242 frame->row_bytes(VideoFrame::kUPlane) == |
| 242 frame->stride(VideoFrame::kUPlane) && | 243 frame->stride(VideoFrame::kUPlane) && |
| 243 frame->row_bytes(VideoFrame::kVPlane) == | 244 frame->row_bytes(VideoFrame::kVPlane) == |
| 244 frame->stride(VideoFrame::kVPlane) && | 245 frame->stride(VideoFrame::kVPlane) && |
| 245 frame->coded_size() == frame->visible_rect().size(), | 246 frame->coded_size() == frame->visible_rect().size(), |
| 246 "Non-packed frame, or visible_rect != coded_size", | 247 "Non-packed frame, or visible_rect != coded_size", |
| 247 kInvalidArgumentError); | 248 kInvalidArgumentError); |
| 248 | 249 |
| 249 pending_frames_.push( | 250 pending_frames_.push( |
| 250 base::MakeTuple(frame, force_keyframe, base::Time::Now())); | 251 std::make_tuple(frame, force_keyframe, base::Time::Now())); |
| 251 DoIOTask(); | 252 DoIOTask(); |
| 252 } | 253 } |
| 253 | 254 |
| 254 void AndroidVideoEncodeAccelerator::UseOutputBitstreamBuffer( | 255 void AndroidVideoEncodeAccelerator::UseOutputBitstreamBuffer( |
| 255 const media::BitstreamBuffer& buffer) { | 256 const media::BitstreamBuffer& buffer) { |
| 256 DVLOG(3) << __PRETTY_FUNCTION__ << ": bitstream_buffer_id=" << buffer.id(); | 257 DVLOG(3) << __PRETTY_FUNCTION__ << ": bitstream_buffer_id=" << buffer.id(); |
| 257 DCHECK(thread_checker_.CalledOnValidThread()); | 258 DCHECK(thread_checker_.CalledOnValidThread()); |
| 258 available_bitstream_buffers_.push_back(buffer); | 259 available_bitstream_buffers_.push_back(buffer); |
| 259 DoIOTask(); | 260 DoIOTask(); |
| 260 } | 261 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 media_codec_->DequeueInputBuffer(NoWaitTimeOut(), &input_buf_index); | 304 media_codec_->DequeueInputBuffer(NoWaitTimeOut(), &input_buf_index); |
| 304 if (status != media::MEDIA_CODEC_OK) { | 305 if (status != media::MEDIA_CODEC_OK) { |
| 305 DCHECK(status == media::MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER || | 306 DCHECK(status == media::MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER || |
| 306 status == media::MEDIA_CODEC_ERROR); | 307 status == media::MEDIA_CODEC_ERROR); |
| 307 RETURN_ON_FAILURE(status != media::MEDIA_CODEC_ERROR, "MediaCodec error", | 308 RETURN_ON_FAILURE(status != media::MEDIA_CODEC_ERROR, "MediaCodec error", |
| 308 kPlatformFailureError); | 309 kPlatformFailureError); |
| 309 return; | 310 return; |
| 310 } | 311 } |
| 311 | 312 |
| 312 const PendingFrames::value_type& input = pending_frames_.front(); | 313 const PendingFrames::value_type& input = pending_frames_.front(); |
| 313 bool is_key_frame = base::get<1>(input); | 314 bool is_key_frame = std::get<1>(input); |
| 314 if (is_key_frame) { | 315 if (is_key_frame) { |
| 315 // Ideally MediaCodec would honor BUFFER_FLAG_SYNC_FRAME so we could | 316 // Ideally MediaCodec would honor BUFFER_FLAG_SYNC_FRAME so we could |
| 316 // indicate this in the QueueInputBuffer() call below and guarantee _this_ | 317 // indicate this in the QueueInputBuffer() call below and guarantee _this_ |
| 317 // frame be encoded as a key frame, but sadly that flag is ignored. | 318 // frame be encoded as a key frame, but sadly that flag is ignored. |
| 318 // Instead, we request a key frame "soon". | 319 // Instead, we request a key frame "soon". |
| 319 media_codec_->RequestKeyFrameSoon(); | 320 media_codec_->RequestKeyFrameSoon(); |
| 320 } | 321 } |
| 321 scoped_refptr<VideoFrame> frame = base::get<0>(input); | 322 scoped_refptr<VideoFrame> frame = std::get<0>(input); |
| 322 | 323 |
| 323 uint8_t* buffer = NULL; | 324 uint8_t* buffer = NULL; |
| 324 size_t capacity = 0; | 325 size_t capacity = 0; |
| 325 status = media_codec_->GetInputBuffer(input_buf_index, &buffer, &capacity); | 326 status = media_codec_->GetInputBuffer(input_buf_index, &buffer, &capacity); |
| 326 RETURN_ON_FAILURE(status == media::MEDIA_CODEC_OK, "GetInputBuffer failed.", | 327 RETURN_ON_FAILURE(status == media::MEDIA_CODEC_OK, "GetInputBuffer failed.", |
| 327 kPlatformFailureError); | 328 kPlatformFailureError); |
| 328 | 329 |
| 329 size_t queued_size = | 330 size_t queued_size = |
| 330 VideoFrame::AllocationSize(media::PIXEL_FORMAT_I420, frame->coded_size()); | 331 VideoFrame::AllocationSize(media::PIXEL_FORMAT_I420, frame->coded_size()); |
| 331 RETURN_ON_FAILURE(capacity >= queued_size, | 332 RETURN_ON_FAILURE(capacity >= queued_size, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 345 frame->data(VideoFrame::kUPlane), frame->stride(VideoFrame::kUPlane), | 346 frame->data(VideoFrame::kUPlane), frame->stride(VideoFrame::kUPlane), |
| 346 frame->data(VideoFrame::kVPlane), frame->stride(VideoFrame::kVPlane), | 347 frame->data(VideoFrame::kVPlane), frame->stride(VideoFrame::kVPlane), |
| 347 dst_y, dst_stride_y, dst_uv, dst_stride_uv, frame->coded_size().width(), | 348 dst_y, dst_stride_y, dst_uv, dst_stride_uv, frame->coded_size().width(), |
| 348 frame->coded_size().height()); | 349 frame->coded_size().height()); |
| 349 RETURN_ON_FAILURE(converted, "Failed to I420ToNV12!", kPlatformFailureError); | 350 RETURN_ON_FAILURE(converted, "Failed to I420ToNV12!", kPlatformFailureError); |
| 350 | 351 |
| 351 fake_input_timestamp_ += base::TimeDelta::FromMicroseconds(1); | 352 fake_input_timestamp_ += base::TimeDelta::FromMicroseconds(1); |
| 352 status = media_codec_->QueueInputBuffer(input_buf_index, NULL, queued_size, | 353 status = media_codec_->QueueInputBuffer(input_buf_index, NULL, queued_size, |
| 353 fake_input_timestamp_); | 354 fake_input_timestamp_); |
| 354 UMA_HISTOGRAM_TIMES("Media.AVDA.InputQueueTime", | 355 UMA_HISTOGRAM_TIMES("Media.AVDA.InputQueueTime", |
| 355 base::Time::Now() - base::get<2>(input)); | 356 base::Time::Now() - std::get<2>(input)); |
| 356 RETURN_ON_FAILURE(status == media::MEDIA_CODEC_OK, | 357 RETURN_ON_FAILURE(status == media::MEDIA_CODEC_OK, |
| 357 "Failed to QueueInputBuffer: " << status, | 358 "Failed to QueueInputBuffer: " << status, |
| 358 kPlatformFailureError); | 359 kPlatformFailureError); |
| 359 ++num_buffers_at_codec_; | 360 ++num_buffers_at_codec_; |
| 360 pending_frames_.pop(); | 361 pending_frames_.pop(); |
| 361 } | 362 } |
| 362 | 363 |
| 363 void AndroidVideoEncodeAccelerator::DequeueOutput() { | 364 void AndroidVideoEncodeAccelerator::DequeueOutput() { |
| 364 if (!client_ptr_factory_->GetWeakPtr() || | 365 if (!client_ptr_factory_->GetWeakPtr() || |
| 365 available_bitstream_buffers_.empty() || num_buffers_at_codec_ == 0) { | 366 available_bitstream_buffers_.empty() || num_buffers_at_codec_ == 0) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 --num_buffers_at_codec_; | 418 --num_buffers_at_codec_; |
| 418 | 419 |
| 419 base::MessageLoop::current()->PostTask( | 420 base::MessageLoop::current()->PostTask( |
| 420 FROM_HERE, | 421 FROM_HERE, |
| 421 base::Bind(&VideoEncodeAccelerator::Client::BitstreamBufferReady, | 422 base::Bind(&VideoEncodeAccelerator::Client::BitstreamBufferReady, |
| 422 client_ptr_factory_->GetWeakPtr(), bitstream_buffer.id(), size, | 423 client_ptr_factory_->GetWeakPtr(), bitstream_buffer.id(), size, |
| 423 key_frame, base::Time::Now() - base::Time())); | 424 key_frame, base::Time::Now() - base::Time())); |
| 424 } | 425 } |
| 425 | 426 |
| 426 } // namespace media | 427 } // namespace media |
| OLD | NEW |