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 // The supported profiles of video encode accelerator. | |
15 static std::vector<media::VideoEncodeAccelerator::SupportedProfile>* | |
16 g_supported_profiles = NULL; | |
17 | |
18 static void GetSupportedVideoEncodeAcceleratorProfilesInternal( | |
19 scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories, | |
20 base::WaitableEvent* waiter, | |
21 std::vector<media::VideoEncodeAccelerator::SupportedProfile>* profiles) { | |
22 scoped_ptr<media::VideoEncodeAccelerator> video_encoder = | |
23 gpu_factories->CreateVideoEncodeAccelerator(); | |
24 if (video_encoder) | |
25 *profiles = video_encoder->GetSupportedProfiles(); | |
26 waiter->Signal(); | |
27 } | |
28 | |
14 void CreateVideoEncodeAccelerator( | 29 void CreateVideoEncodeAccelerator( |
15 const OnCreateVideoEncodeAcceleratorCallback& callback) { | 30 const OnCreateVideoEncodeAcceleratorCallback& callback) { |
16 DCHECK(!callback.is_null()); | 31 DCHECK(!callback.is_null()); |
17 | 32 |
18 scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories = | 33 scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories = |
19 RenderThreadImpl::current()->GetGpuFactories(); | 34 RenderThreadImpl::current()->GetGpuFactories(); |
20 if (!gpu_factories.get()) { | 35 if (!gpu_factories.get()) { |
21 callback.Run(NULL, scoped_ptr<media::VideoEncodeAccelerator>()); | 36 callback.Run(NULL, scoped_ptr<media::VideoEncodeAccelerator>()); |
22 return; | 37 return; |
23 } | 38 } |
24 | 39 |
25 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner = | 40 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner = |
26 gpu_factories->GetTaskRunner(); | 41 gpu_factories->GetTaskRunner(); |
27 base::PostTaskAndReplyWithResult( | 42 base::PostTaskAndReplyWithResult( |
28 encode_task_runner.get(), | 43 encode_task_runner.get(), |
29 FROM_HERE, | 44 FROM_HERE, |
30 base::Bind( | 45 base::Bind( |
31 &media::GpuVideoAcceleratorFactories::CreateVideoEncodeAccelerator, | 46 &media::GpuVideoAcceleratorFactories::CreateVideoEncodeAccelerator, |
32 gpu_factories), | 47 gpu_factories), |
33 base::Bind(callback, encode_task_runner)); | 48 base::Bind(callback, encode_task_runner)); |
34 } | 49 } |
35 | 50 |
36 std::vector<media::VideoEncodeAccelerator::SupportedProfile> | 51 std::vector<media::VideoEncodeAccelerator::SupportedProfile> |
kcwu
2014/09/19 11:15:54
Since you cached the result to global variable, ch
| |
37 GetSupportedVideoEncodeAcceleratorProfiles() { | 52 GetSupportedVideoEncodeAcceleratorProfiles() { |
38 return GpuVideoEncodeAcceleratorHost::GetSupportedProfiles(); | 53 if (!g_supported_profiles) { |
54 g_supported_profiles = | |
55 new std::vector<media::VideoEncodeAccelerator::SupportedProfile>(); | |
56 scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories = | |
57 RenderThreadImpl::current()->GetGpuFactories(); | |
58 base::WaitableEvent waiter(true, false); | |
59 gpu_factories->GetTaskRunner()->PostTask( | |
60 FROM_HERE, | |
61 base::Bind(&GetSupportedVideoEncodeAcceleratorProfilesInternal, | |
62 gpu_factories, | |
63 &waiter, | |
64 g_supported_profiles)); | |
65 waiter.Wait(); | |
66 } | |
67 return *g_supported_profiles; | |
39 } | 68 } |
40 | 69 |
41 } // namespace content | 70 } // namespace content |
OLD | NEW |