OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/public/renderer/video_encode_accelerator.h" | 5 #include "content/public/renderer/video_encode_accelerator.h" |
6 | 6 |
7 #include "base/task_runner_util.h" | 7 #include "base/task_runner_util.h" |
8 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" | 8 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" |
9 #include "content/renderer/render_thread_impl.h" | 9 #include "content/renderer/render_thread_impl.h" |
10 #include "media/filters/gpu_video_accelerator_factories.h" | 10 #include "media/filters/gpu_video_accelerator_factories.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 static void GetSupportedVideoEncodeAcceleratorProfilesInternal( | |
15 scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories, | |
16 base::WaitableEvent* waiter, | |
17 std::vector<media::VideoEncodeAccelerator::SupportedProfile>* profiles) { | |
18 scoped_ptr<media::VideoEncodeAccelerator> video_encoder = | |
19 gpu_factories->CreateVideoEncodeAccelerator(); | |
20 if (video_encoder) | |
21 *profiles = video_encoder->GetSupportedProfiles(); | |
22 waiter->Signal(); | |
23 } | |
24 | |
14 void CreateVideoEncodeAccelerator( | 25 void CreateVideoEncodeAccelerator( |
15 const OnCreateVideoEncodeAcceleratorCallback& callback) { | 26 const OnCreateVideoEncodeAcceleratorCallback& callback) { |
16 DCHECK(!callback.is_null()); | 27 DCHECK(!callback.is_null()); |
17 | 28 |
18 scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories = | 29 scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories = |
19 RenderThreadImpl::current()->GetGpuFactories(); | 30 RenderThreadImpl::current()->GetGpuFactories(); |
20 if (!gpu_factories.get()) { | 31 if (!gpu_factories.get()) { |
21 callback.Run(NULL, scoped_ptr<media::VideoEncodeAccelerator>()); | 32 callback.Run(NULL, scoped_ptr<media::VideoEncodeAccelerator>()); |
22 return; | 33 return; |
23 } | 34 } |
24 | 35 |
25 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner = | 36 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner = |
26 gpu_factories->GetTaskRunner(); | 37 gpu_factories->GetTaskRunner(); |
27 base::PostTaskAndReplyWithResult( | 38 base::PostTaskAndReplyWithResult( |
28 encode_task_runner.get(), | 39 encode_task_runner.get(), |
29 FROM_HERE, | 40 FROM_HERE, |
30 base::Bind( | 41 base::Bind( |
31 &media::GpuVideoAcceleratorFactories::CreateVideoEncodeAccelerator, | 42 &media::GpuVideoAcceleratorFactories::CreateVideoEncodeAccelerator, |
32 gpu_factories), | 43 gpu_factories), |
33 base::Bind(callback, encode_task_runner)); | 44 base::Bind(callback, encode_task_runner)); |
34 } | 45 } |
35 | 46 |
36 std::vector<media::VideoEncodeAccelerator::SupportedProfile> | 47 std::vector<media::VideoEncodeAccelerator::SupportedProfile> |
37 GetSupportedVideoEncodeAcceleratorProfiles() { | 48 GetSupportedVideoEncodeAcceleratorProfiles() { |
38 return GpuVideoEncodeAcceleratorHost::GetSupportedProfiles(); | 49 scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories = |
50 RenderThreadImpl::current()->GetGpuFactories(); | |
51 base::WaitableEvent waiter(true, false); | |
52 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles; | |
53 gpu_factories->GetTaskRunner()->PostTask( | |
54 FROM_HERE, | |
55 base::Bind(&GetSupportedVideoEncodeAcceleratorProfilesInternal, | |
56 gpu_factories, | |
57 &waiter, | |
58 &profiles)); | |
59 waiter.Wait(); | |
60 return profiles; | |
piman
2014/09/18 18:11:51
I think you want to cache this. This function is c
wuchengli
2014/09/19 14:27:24
Done.
| |
39 } | 61 } |
40 | 62 |
41 } // namespace content | 63 } // namespace content |
OLD | NEW |