Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: content/common/gpu/media/android_video_decode_accelerator.cc

Issue 1541353002: Add offset support to BitstreamBuffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address dcheng's comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_util.h" 27 #include "media/base/android/media_codec_util.h"
27 #include "media/base/bind_to_current_loop.h" 28 #include "media/base/bind_to_current_loop.h"
28 #include "media/base/bitstream_buffer.h" 29 #include "media/base/bitstream_buffer.h"
29 #include "media/base/limits.h" 30 #include "media/base/limits.h"
30 #include "media/base/media.h" 31 #include "media/base/media.h"
31 #include "media/base/media_switches.h" 32 #include "media/base/media_switches.h"
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 pending_bitstream_buffers_.pop(); 456 pending_bitstream_buffers_.pop();
456 TRACE_COUNTER1("media", "AVDA::PendingBitstreamBufferCount", 457 TRACE_COUNTER1("media", "AVDA::PendingBitstreamBufferCount",
457 pending_bitstream_buffers_.size()); 458 pending_bitstream_buffers_.size());
458 459
459 DCHECK_NE(state_, ERROR); 460 DCHECK_NE(state_, ERROR);
460 state_ = WAITING_FOR_EOS; 461 state_ = WAITING_FOR_EOS;
461 media_codec_->QueueEOS(input_buf_index); 462 media_codec_->QueueEOS(input_buf_index);
462 return true; 463 return true;
463 } 464 }
464 465
465 scoped_ptr<base::SharedMemory> shm; 466 scoped_ptr<SharedMemoryRegion> shm;
466 467
467 if (pending_input_buf_index_ != -1) { 468 if (pending_input_buf_index_ == -1) {
468 // The buffer is already dequeued from MediaCodec, filled with data and 469 // When |pending_input_buf_index_| is not -1, the buffer is already dequeued
469 // bitstream_buffer.handle() is closed. 470 // from MediaCodec, filled with data and bitstream_buffer.handle() is
470 shm.reset(new base::SharedMemory()); 471 // closed.
471 } else { 472 shm.reset(new SharedMemoryRegion(bitstream_buffer, true));
472 shm.reset(new base::SharedMemory(bitstream_buffer.handle(), true));
473 473
474 if (!shm->Map(bitstream_buffer.size())) { 474 if (!shm->Map()) {
475 POST_ERROR(UNREADABLE_INPUT, "Failed to SharedMemory::Map()"); 475 POST_ERROR(UNREADABLE_INPUT, "Failed to SharedMemoryRegion::Map()");
476 return false; 476 return false;
477 } 477 }
478 } 478 }
479 479
480 const base::TimeDelta presentation_timestamp = 480 const base::TimeDelta presentation_timestamp =
481 bitstream_buffer.presentation_timestamp(); 481 bitstream_buffer.presentation_timestamp();
482 DCHECK(presentation_timestamp != media::kNoTimestamp()) 482 DCHECK(presentation_timestamp != media::kNoTimestamp())
483 << "Bitstream buffers must have valid presentation timestamps"; 483 << "Bitstream buffers must have valid presentation timestamps";
484 484
485 // There may already be a bitstream buffer with this timestamp, e.g., VP9 alt 485 // There may already be a bitstream buffer with this timestamp, e.g., VP9 alt
486 // ref frames, but it's OK to overwrite it because we only expect a single 486 // ref frames, but it's OK to overwrite it because we only expect a single
487 // output frame to have that timestamp. AVDA clients only use the bitstream 487 // output frame to have that timestamp. AVDA clients only use the bitstream
488 // buffer id in the returned Pictures to map a bitstream buffer back to a 488 // buffer id in the returned Pictures to map a bitstream buffer back to a
489 // timestamp on their side, so either one of the bitstream buffer ids will 489 // timestamp on their side, so either one of the bitstream buffer ids will
490 // result in them finding the right timestamp. 490 // result in them finding the right timestamp.
491 bitstream_buffers_in_decoder_[presentation_timestamp] = bitstream_buffer.id(); 491 bitstream_buffers_in_decoder_[presentation_timestamp] = bitstream_buffer.id();
492 492
493 // Notice that |memory| will be null if we repeatedly enqueue the same buffer, 493 // Notice that |memory| will be null if we repeatedly enqueue the same buffer,
494 // this happens after MEDIA_CODEC_NO_KEY. 494 // this happens after MEDIA_CODEC_NO_KEY.
495 const uint8_t* memory = static_cast<const uint8_t*>(shm->memory()); 495 const uint8_t* memory =
496 shm ? static_cast<const uint8_t*>(shm->memory()) : nullptr;
496 const std::string& key_id = bitstream_buffer.key_id(); 497 const std::string& key_id = bitstream_buffer.key_id();
497 const std::string& iv = bitstream_buffer.iv(); 498 const std::string& iv = bitstream_buffer.iv();
498 const std::vector<media::SubsampleEntry>& subsamples = 499 const std::vector<media::SubsampleEntry>& subsamples =
499 bitstream_buffer.subsamples(); 500 bitstream_buffer.subsamples();
500 501
501 media::MediaCodecStatus status; 502 media::MediaCodecStatus status;
502 if (key_id.empty() || iv.empty()) { 503 if (key_id.empty() || iv.empty()) {
503 status = media_codec_->QueueInputBuffer(input_buf_index, memory, 504 status = media_codec_->QueueInputBuffer(input_buf_index, memory,
504 bitstream_buffer.size(), 505 bitstream_buffer.size(),
505 presentation_timestamp); 506 presentation_timestamp);
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 capabilities.flags = media::VideoDecodeAccelerator::Capabilities:: 1146 capabilities.flags = media::VideoDecodeAccelerator::Capabilities::
1146 NEEDS_ALL_PICTURE_BUFFERS_TO_DECODE | 1147 NEEDS_ALL_PICTURE_BUFFERS_TO_DECODE |
1147 media::VideoDecodeAccelerator::Capabilities:: 1148 media::VideoDecodeAccelerator::Capabilities::
1148 SUPPORTS_EXTERNAL_OUTPUT_SURFACE; 1149 SUPPORTS_EXTERNAL_OUTPUT_SURFACE;
1149 } 1150 }
1150 1151
1151 return capabilities; 1152 return capabilities;
1152 } 1153 }
1153 1154
1154 } // namespace content 1155 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698