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

Side by Side Diff: media/filters/gpu_video_decoder.cc

Issue 2365103002: Send the h264 SPS and PPS configuration parameters to AVDA (Closed)
Patch Set: Moved parsing to the renderer Created 4 years, 2 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/filters/gpu_video_decoder.h" 5 #include "media/filters/gpu_video_decoder.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <array>
8 #include <utility> 9 #include <utility>
9 10
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/cpu.h" 14 #include "base/cpu.h"
14 #include "base/location.h" 15 #include "base/location.h"
15 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
16 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
17 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
18 #include "base/stl_util.h" 19 #include "base/stl_util.h"
19 #include "base/task_runner_util.h" 20 #include "base/task_runner_util.h"
20 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
21 #include "build/build_config.h" 22 #include "build/build_config.h"
22 #include "gpu/command_buffer/common/mailbox_holder.h" 23 #include "gpu/command_buffer/common/mailbox_holder.h"
23 #include "media/base/bind_to_current_loop.h" 24 #include "media/base/bind_to_current_loop.h"
24 #include "media/base/cdm_context.h" 25 #include "media/base/cdm_context.h"
25 #include "media/base/decoder_buffer.h" 26 #include "media/base/decoder_buffer.h"
26 #include "media/base/media_log.h" 27 #include "media/base/media_log.h"
27 #include "media/base/media_switches.h" 28 #include "media/base/media_switches.h"
28 #include "media/base/pipeline_status.h" 29 #include "media/base/pipeline_status.h"
29 #include "media/base/surface_manager.h" 30 #include "media/base/surface_manager.h"
30 #include "media/base/video_decoder_config.h" 31 #include "media/base/video_decoder_config.h"
32 #include "media/formats/mp4/box_definitions.h"
31 #include "media/renderers/gpu_video_accelerator_factories.h" 33 #include "media/renderers/gpu_video_accelerator_factories.h"
32 #include "third_party/skia/include/core/SkBitmap.h" 34 #include "third_party/skia/include/core/SkBitmap.h"
33 35
34 namespace media { 36 namespace media {
37 namespace {
38
39 // Size of shared-memory segments we allocate. Since we reuse them we let them
40 // be on the beefy side.
41 static const size_t kSharedMemorySegmentBytes = 100 << 10;
42
43 // Extract the SPS and PPS lists from |extra_data|. Each SPS and PPS is prefixed
44 // with 0x0001, the Annex B framing bytes. The out parameters are not modified
45 // on failure.
46 void ExtractSpsAndPps(const std::vector<uint8_t>& extra_data,
47 std::vector<uint8_t>* sps_out,
48 std::vector<uint8_t>* pps_out) {
49 mp4::AVCDecoderConfigurationRecord record;
50 if (!record.Parse(extra_data.data(), extra_data.size())) {
51 DVLOG(1) << "Failed to extract the SPS and PPS from extra_data";
52 return;
53 }
54
55 constexpr std::array<uint8_t, 4> prefix = {{0, 0, 0, 1}};
56 for (const std::vector<uint8_t>& sps : record.sps_list) {
57 sps_out->insert(sps_out->end(), prefix.begin(), prefix.end());
58 sps_out->insert(sps_out->end(), sps.begin(), sps.end());
59 }
60
61 for (const std::vector<uint8_t>& pps : record.pps_list) {
62 pps_out->insert(pps_out->end(), prefix.begin(), prefix.end());
63 pps_out->insert(pps_out->end(), pps.begin(), pps.end());
64 }
65 }
66
67 } // namespace
35 68
36 const char GpuVideoDecoder::kDecoderName[] = "GpuVideoDecoder"; 69 const char GpuVideoDecoder::kDecoderName[] = "GpuVideoDecoder";
37 70
38 // Maximum number of concurrent VDA::Decode() operations GVD will maintain. 71 // Maximum number of concurrent VDA::Decode() operations GVD will maintain.
39 // Higher values allow better pipelining in the GPU, but also require more 72 // Higher values allow better pipelining in the GPU, but also require more
40 // resources. 73 // resources.
41 enum { kMaxInFlightDecodes = 4 }; 74 enum { kMaxInFlightDecodes = 4 };
42 75
43 // Size of shared-memory segments we allocate. Since we reuse them we let them
44 // be on the beefy side.
45 static const size_t kSharedMemorySegmentBytes = 100 << 10;
46
47 GpuVideoDecoder::SHMBuffer::SHMBuffer(std::unique_ptr<base::SharedMemory> m, 76 GpuVideoDecoder::SHMBuffer::SHMBuffer(std::unique_ptr<base::SharedMemory> m,
48 size_t s) 77 size_t s)
49 : shm(std::move(m)), size(s) {} 78 : shm(std::move(m)), size(s) {}
50 79
51 GpuVideoDecoder::SHMBuffer::~SHMBuffer() {} 80 GpuVideoDecoder::SHMBuffer::~SHMBuffer() {}
52 81
53 GpuVideoDecoder::PendingDecoderBuffer::PendingDecoderBuffer( 82 GpuVideoDecoder::PendingDecoderBuffer::PendingDecoderBuffer(
54 SHMBuffer* s, 83 SHMBuffer* s,
55 const scoped_refptr<DecoderBuffer>& b, 84 const scoped_refptr<DecoderBuffer>& b,
56 const DecodeCB& done_cb) 85 const DecodeCB& done_cb)
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 return; 321 return;
293 } 322 }
294 323
295 VideoDecodeAccelerator::Config vda_config; 324 VideoDecodeAccelerator::Config vda_config;
296 vda_config.profile = config_.profile(); 325 vda_config.profile = config_.profile();
297 vda_config.cdm_id = cdm_id; 326 vda_config.cdm_id = cdm_id;
298 vda_config.is_encrypted = config_.is_encrypted(); 327 vda_config.is_encrypted = config_.is_encrypted();
299 vda_config.surface_id = surface_id; 328 vda_config.surface_id = surface_id;
300 vda_config.is_deferred_initialization_allowed = true; 329 vda_config.is_deferred_initialization_allowed = true;
301 vda_config.initial_expected_coded_size = config_.coded_size(); 330 vda_config.initial_expected_coded_size = config_.coded_size();
331
332 #if defined(OS_ANDROID)
333 // We pass the SPS and PPS on Android because it lets us initialize
334 // MediaCodec more reliably (http://crbug.com/649185).
335 if (config_.codec() == kCodecH264)
336 ExtractSpsAndPps(config_.extra_data(), &vda_config.sps, &vda_config.pps);
337 #endif
338
302 if (!vda_->Initialize(vda_config, this)) { 339 if (!vda_->Initialize(vda_config, this)) {
303 DVLOG(1) << "VDA::Initialize failed."; 340 DVLOG(1) << "VDA::Initialize failed.";
304 base::ResetAndReturn(&init_cb_).Run(false); 341 base::ResetAndReturn(&init_cb_).Run(false);
305 return; 342 return;
306 } 343 }
307 344
308 // If deferred initialization is not supported, initialization is complete. 345 // If deferred initialization is not supported, initialization is complete.
309 // Otherwise, a call to NotifyInitializationComplete will follow with the 346 // Otherwise, a call to NotifyInitializationComplete will follow with the
310 // result of deferred initialization. 347 // result of deferred initialization.
311 if (!supports_deferred_initialization_) 348 if (!supports_deferred_initialization_)
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 } 865 }
829 return false; 866 return false;
830 } 867 }
831 868
832 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() 869 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent()
833 const { 870 const {
834 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); 871 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread());
835 } 872 }
836 873
837 } // namespace media 874 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698