OLD | NEW |
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 <utility> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/cpu.h" | 13 #include "base/cpu.h" |
13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
16 #include "base/task_runner_util.h" | 17 #include "base/task_runner_util.h" |
17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
(...skipping 14 matching lines...) Expand all Loading... |
32 // Higher values allow better pipelining in the GPU, but also require more | 33 // Higher values allow better pipelining in the GPU, but also require more |
33 // resources. | 34 // resources. |
34 enum { kMaxInFlightDecodes = 4 }; | 35 enum { kMaxInFlightDecodes = 4 }; |
35 | 36 |
36 // Size of shared-memory segments we allocate. Since we reuse them we let them | 37 // Size of shared-memory segments we allocate. Since we reuse them we let them |
37 // be on the beefy side. | 38 // be on the beefy side. |
38 static const size_t kSharedMemorySegmentBytes = 100 << 10; | 39 static const size_t kSharedMemorySegmentBytes = 100 << 10; |
39 | 40 |
40 GpuVideoDecoder::SHMBuffer::SHMBuffer(scoped_ptr<base::SharedMemory> m, | 41 GpuVideoDecoder::SHMBuffer::SHMBuffer(scoped_ptr<base::SharedMemory> m, |
41 size_t s) | 42 size_t s) |
42 : shm(m.Pass()), size(s) { | 43 : shm(std::move(m)), size(s) {} |
43 } | |
44 | 44 |
45 GpuVideoDecoder::SHMBuffer::~SHMBuffer() {} | 45 GpuVideoDecoder::SHMBuffer::~SHMBuffer() {} |
46 | 46 |
47 GpuVideoDecoder::PendingDecoderBuffer::PendingDecoderBuffer( | 47 GpuVideoDecoder::PendingDecoderBuffer::PendingDecoderBuffer( |
48 SHMBuffer* s, | 48 SHMBuffer* s, |
49 const scoped_refptr<DecoderBuffer>& b, | 49 const scoped_refptr<DecoderBuffer>& b, |
50 const DecodeCB& done_cb) | 50 const DecodeCB& done_cb) |
51 : shm_buffer(s), buffer(b), done_cb(done_cb) { | 51 : shm_buffer(s), buffer(b), done_cb(done_cb) { |
52 } | 52 } |
53 | 53 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 output_cb_ = BindToCurrentLoop(output_cb); | 177 output_cb_ = BindToCurrentLoop(output_cb); |
178 | 178 |
179 if (previously_initialized) { | 179 if (previously_initialized) { |
180 // Reinitialization with a different config (but same codec and profile). | 180 // Reinitialization with a different config (but same codec and profile). |
181 // VDA should handle it by detecting this in-stream by itself, | 181 // VDA should handle it by detecting this in-stream by itself, |
182 // no need to notify it. | 182 // no need to notify it. |
183 bound_init_cb.Run(true); | 183 bound_init_cb.Run(true); |
184 return; | 184 return; |
185 } | 185 } |
186 | 186 |
187 vda_ = factories_->CreateVideoDecodeAccelerator().Pass(); | 187 vda_ = factories_->CreateVideoDecodeAccelerator(); |
188 | 188 |
189 VideoDecodeAccelerator::Config vda_config(config); | 189 VideoDecodeAccelerator::Config vda_config(config); |
190 | 190 |
191 if (!vda_ || !vda_->Initialize(vda_config, this)) { | 191 if (!vda_ || !vda_->Initialize(vda_config, this)) { |
192 DVLOG(1) << "VDA initialization failed."; | 192 DVLOG(1) << "VDA initialization failed."; |
193 bound_init_cb.Run(false); | 193 bound_init_cb.Run(false); |
194 return; | 194 return; |
195 } | 195 } |
196 | 196 |
197 if (config.is_encrypted()) { | 197 if (config.is_encrypted()) { |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 size_t min_size) { | 559 size_t min_size) { |
560 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 560 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
561 if (available_shm_segments_.empty() || | 561 if (available_shm_segments_.empty() || |
562 available_shm_segments_.back()->size < min_size) { | 562 available_shm_segments_.back()->size < min_size) { |
563 size_t size_to_allocate = std::max(min_size, kSharedMemorySegmentBytes); | 563 size_t size_to_allocate = std::max(min_size, kSharedMemorySegmentBytes); |
564 scoped_ptr<base::SharedMemory> shm = | 564 scoped_ptr<base::SharedMemory> shm = |
565 factories_->CreateSharedMemory(size_to_allocate); | 565 factories_->CreateSharedMemory(size_to_allocate); |
566 // CreateSharedMemory() can return NULL during Shutdown. | 566 // CreateSharedMemory() can return NULL during Shutdown. |
567 if (!shm) | 567 if (!shm) |
568 return NULL; | 568 return NULL; |
569 return make_scoped_ptr(new SHMBuffer(shm.Pass(), size_to_allocate)); | 569 return make_scoped_ptr(new SHMBuffer(std::move(shm), size_to_allocate)); |
570 } | 570 } |
571 scoped_ptr<SHMBuffer> ret(available_shm_segments_.back()); | 571 scoped_ptr<SHMBuffer> ret(available_shm_segments_.back()); |
572 available_shm_segments_.pop_back(); | 572 available_shm_segments_.pop_back(); |
573 return ret.Pass(); | 573 return ret; |
574 } | 574 } |
575 | 575 |
576 void GpuVideoDecoder::PutSHM(scoped_ptr<SHMBuffer> shm_buffer) { | 576 void GpuVideoDecoder::PutSHM(scoped_ptr<SHMBuffer> shm_buffer) { |
577 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 577 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
578 available_shm_segments_.push_back(shm_buffer.release()); | 578 available_shm_segments_.push_back(shm_buffer.release()); |
579 } | 579 } |
580 | 580 |
581 void GpuVideoDecoder::NotifyEndOfBitstreamBuffer(int32_t id) { | 581 void GpuVideoDecoder::NotifyEndOfBitstreamBuffer(int32_t id) { |
582 DVLOG(3) << "NotifyEndOfBitstreamBuffer(" << id << ")"; | 582 DVLOG(3) << "NotifyEndOfBitstreamBuffer(" << id << ")"; |
583 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 583 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 } | 673 } |
674 return false; | 674 return false; |
675 } | 675 } |
676 | 676 |
677 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 677 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
678 const { | 678 const { |
679 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 679 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
680 } | 680 } |
681 | 681 |
682 } // namespace media | 682 } // namespace media |
OLD | NEW |