| OLD | NEW | 
|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_decode_accelerator.h" | 5 #include "content/common/gpu/media/android_video_decode_accelerator.h" | 
| 6 | 6 | 
| 7 #include <stddef.h> | 7 #include <stddef.h> | 
| 8 | 8 | 
| 9 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" | 
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" | 
| 11 #include "base/bind.h" | 11 #include "base/bind.h" | 
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" | 
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" | 
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" | 
| 15 #include "base/logging.h" | 15 #include "base/logging.h" | 
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" | 
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" | 
| 18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" | 
| 19 #include "content/common/gpu/gpu_channel.h" | 19 #include "content/common/gpu/gpu_channel.h" | 
| 20 #include "content/common/gpu/media/android_copying_backing_strategy.h" | 20 #include "content/common/gpu/media/android_copying_backing_strategy.h" | 
| 21 #include "content/common/gpu/media/android_deferred_rendering_backing_strategy.h
      " | 21 #include "content/common/gpu/media/android_deferred_rendering_backing_strategy.h
      " | 
|  | 22 #include "content/common/gpu/media/shared_memory_region.h" | 
| 22 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" | 
| 23 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 24 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 
| 24 #include "gpu/command_buffer/service/gpu_switches.h" | 25 #include "gpu/command_buffer/service/gpu_switches.h" | 
| 25 #include "gpu/command_buffer/service/mailbox_manager.h" | 26 #include "gpu/command_buffer/service/mailbox_manager.h" | 
| 26 #include "media/base/android/media_codec_bridge.h" | 27 #include "media/base/android/media_codec_bridge.h" | 
| 27 #include "media/base/android/media_codec_util.h" | 28 #include "media/base/android/media_codec_util.h" | 
| 28 #include "media/base/bind_to_current_loop.h" | 29 #include "media/base/bind_to_current_loop.h" | 
| 29 #include "media/base/bitstream_buffer.h" | 30 #include "media/base/bitstream_buffer.h" | 
| 30 #include "media/base/limits.h" | 31 #include "media/base/limits.h" | 
| 31 #include "media/base/media.h" | 32 #include "media/base/media.h" | 
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 469     pending_bitstream_buffers_.pop(); | 470     pending_bitstream_buffers_.pop(); | 
| 470     TRACE_COUNTER1("media", "AVDA::PendingBitstreamBufferCount", | 471     TRACE_COUNTER1("media", "AVDA::PendingBitstreamBufferCount", | 
| 471                    pending_bitstream_buffers_.size()); | 472                    pending_bitstream_buffers_.size()); | 
| 472 | 473 | 
| 473     DCHECK_NE(state_, ERROR); | 474     DCHECK_NE(state_, ERROR); | 
| 474     state_ = WAITING_FOR_EOS; | 475     state_ = WAITING_FOR_EOS; | 
| 475     media_codec_->QueueEOS(input_buf_index); | 476     media_codec_->QueueEOS(input_buf_index); | 
| 476     return true; | 477     return true; | 
| 477   } | 478   } | 
| 478 | 479 | 
| 479   scoped_ptr<base::SharedMemory> shm; | 480   scoped_ptr<SharedMemoryRegion> shm; | 
| 480 | 481 | 
| 481   if (pending_input_buf_index_ != -1) { | 482   if (pending_input_buf_index_ == -1) { | 
| 482     // The buffer is already dequeued from MediaCodec, filled with data and | 483     // When |pending_input_buf_index_| is not -1, the buffer is already dequeued | 
| 483     // bitstream_buffer.handle() is closed. | 484     // from MediaCodec, filled with data and bitstream_buffer.handle() is | 
| 484     shm.reset(new base::SharedMemory()); | 485     // closed. | 
| 485   } else { | 486     shm.reset(new SharedMemoryRegion(bitstream_buffer, true)); | 
| 486     shm.reset(new base::SharedMemory(bitstream_buffer.handle(), true)); |  | 
| 487 | 487 | 
| 488     if (!shm->Map(bitstream_buffer.size())) { | 488     if (!shm->Map()) { | 
| 489       POST_ERROR(UNREADABLE_INPUT, "Failed to SharedMemory::Map()"); | 489       POST_ERROR(UNREADABLE_INPUT, "Failed to SharedMemoryRegion::Map()"); | 
| 490       return false; | 490       return false; | 
| 491     } | 491     } | 
| 492   } | 492   } | 
| 493 | 493 | 
| 494   const base::TimeDelta presentation_timestamp = | 494   const base::TimeDelta presentation_timestamp = | 
| 495       bitstream_buffer.presentation_timestamp(); | 495       bitstream_buffer.presentation_timestamp(); | 
| 496   DCHECK(presentation_timestamp != media::kNoTimestamp()) | 496   DCHECK(presentation_timestamp != media::kNoTimestamp()) | 
| 497       << "Bitstream buffers must have valid presentation timestamps"; | 497       << "Bitstream buffers must have valid presentation timestamps"; | 
| 498 | 498 | 
| 499   // There may already be a bitstream buffer with this timestamp, e.g., VP9 alt | 499   // There may already be a bitstream buffer with this timestamp, e.g., VP9 alt | 
| 500   // ref frames, but it's OK to overwrite it because we only expect a single | 500   // ref frames, but it's OK to overwrite it because we only expect a single | 
| 501   // output frame to have that timestamp. AVDA clients only use the bitstream | 501   // output frame to have that timestamp. AVDA clients only use the bitstream | 
| 502   // buffer id in the returned Pictures to map a bitstream buffer back to a | 502   // buffer id in the returned Pictures to map a bitstream buffer back to a | 
| 503   // timestamp on their side, so either one of the bitstream buffer ids will | 503   // timestamp on their side, so either one of the bitstream buffer ids will | 
| 504   // result in them finding the right timestamp. | 504   // result in them finding the right timestamp. | 
| 505   bitstream_buffers_in_decoder_[presentation_timestamp] = bitstream_buffer.id(); | 505   bitstream_buffers_in_decoder_[presentation_timestamp] = bitstream_buffer.id(); | 
| 506 | 506 | 
| 507   // Notice that |memory| will be null if we repeatedly enqueue the same buffer, | 507   // Notice that |memory| will be null if we repeatedly enqueue the same buffer, | 
| 508   // this happens after MEDIA_CODEC_NO_KEY. | 508   // this happens after MEDIA_CODEC_NO_KEY. | 
| 509   const uint8_t* memory = static_cast<const uint8_t*>(shm->memory()); | 509   const uint8_t* memory = | 
|  | 510       shm ? static_cast<const uint8_t*>(shm->memory()) : nullptr; | 
| 510   const std::string& key_id = bitstream_buffer.key_id(); | 511   const std::string& key_id = bitstream_buffer.key_id(); | 
| 511   const std::string& iv = bitstream_buffer.iv(); | 512   const std::string& iv = bitstream_buffer.iv(); | 
| 512   const std::vector<media::SubsampleEntry>& subsamples = | 513   const std::vector<media::SubsampleEntry>& subsamples = | 
| 513       bitstream_buffer.subsamples(); | 514       bitstream_buffer.subsamples(); | 
| 514 | 515 | 
| 515   media::MediaCodecStatus status; | 516   media::MediaCodecStatus status; | 
| 516   if (key_id.empty() || iv.empty()) { | 517   if (key_id.empty() || iv.empty()) { | 
| 517     status = media_codec_->QueueInputBuffer(input_buf_index, memory, | 518     status = media_codec_->QueueInputBuffer(input_buf_index, memory, | 
| 518                                             bitstream_buffer.size(), | 519                                             bitstream_buffer.size(), | 
| 519                                             presentation_timestamp); | 520                                             presentation_timestamp); | 
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1166     capabilities.flags = media::VideoDecodeAccelerator::Capabilities:: | 1167     capabilities.flags = media::VideoDecodeAccelerator::Capabilities:: | 
| 1167                              NEEDS_ALL_PICTURE_BUFFERS_TO_DECODE | | 1168                              NEEDS_ALL_PICTURE_BUFFERS_TO_DECODE | | 
| 1168                          media::VideoDecodeAccelerator::Capabilities:: | 1169                          media::VideoDecodeAccelerator::Capabilities:: | 
| 1169                              SUPPORTS_EXTERNAL_OUTPUT_SURFACE; | 1170                              SUPPORTS_EXTERNAL_OUTPUT_SURFACE; | 
| 1170   } | 1171   } | 
| 1171 | 1172 | 
| 1172   return capabilities; | 1173   return capabilities; | 
| 1173 } | 1174 } | 
| 1174 | 1175 | 
| 1175 }  // namespace content | 1176 }  // namespace content | 
| OLD | NEW | 
|---|