OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #ifndef MEDIA_GPU_IPC_SERVICE_GPU_VIDEO_ENCODE_ACCELERATOR_H_ | 5 #ifndef MEDIA_GPU_IPC_SERVICE_GPU_VIDEO_ENCODE_ACCELERATOR_H_ |
6 #define MEDIA_GPU_IPC_SERVICE_GPU_VIDEO_ENCODE_ACCELERATOR_H_ | 6 #define MEDIA_GPU_IPC_SERVICE_GPU_VIDEO_ENCODE_ACCELERATOR_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/synchronization/waitable_event.h" | |
16 #include "gpu/config/gpu_info.h" | 17 #include "gpu/config/gpu_info.h" |
17 #include "gpu/ipc/service/gpu_command_buffer_stub.h" | 18 #include "gpu/ipc/service/gpu_command_buffer_stub.h" |
18 #include "ipc/ipc_listener.h" | 19 #include "ipc/ipc_listener.h" |
19 #include "media/video/video_encode_accelerator.h" | 20 #include "media/video/video_encode_accelerator.h" |
20 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" |
21 | 22 |
22 struct AcceleratedVideoEncoderMsg_Encode_Params; | 23 struct AcceleratedVideoEncoderMsg_Encode_Params; |
23 | 24 |
24 namespace base { | 25 namespace base { |
25 class SharedMemory; | 26 class SharedMemory; |
26 } // namespace base | 27 } // namespace base |
27 | 28 |
28 namespace gpu { | 29 namespace gpu { |
29 struct GpuPreferences; | 30 struct GpuPreferences; |
30 } // namespace gpu | 31 } // namespace gpu |
31 | 32 |
32 namespace media { | 33 namespace media { |
33 | 34 |
34 // This class encapsulates the GPU process view of a VideoEncodeAccelerator, | 35 // This class encapsulates the GPU process view of a VideoEncodeAccelerator, |
35 // wrapping the platform-specific VideoEncodeAccelerator instance. It handles | 36 // wrapping the platform-specific VideoEncodeAccelerator instance. It handles |
36 // IPC coming in from the renderer and passes it to the underlying VEA. | 37 // IPC coming in from the renderer and passes it to the underlying VEA. |
37 class GpuVideoEncodeAccelerator | 38 class GpuVideoEncodeAccelerator |
38 : public IPC::Listener, | 39 : public IPC::Listener, |
39 public VideoEncodeAccelerator::Client, | 40 public VideoEncodeAccelerator::Client, |
40 public gpu::GpuCommandBufferStub::DestructionObserver { | 41 public gpu::GpuCommandBufferStub::DestructionObserver { |
41 public: | 42 public: |
42 GpuVideoEncodeAccelerator(int32_t host_route_id, | 43 GpuVideoEncodeAccelerator( |
43 gpu::GpuCommandBufferStub* stub); | 44 int32_t host_route_id, |
45 gpu::GpuCommandBufferStub* stub, | |
46 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | |
44 ~GpuVideoEncodeAccelerator() override; | 47 ~GpuVideoEncodeAccelerator() override; |
45 | 48 |
46 // Initialize this accelerator with the given parameters and send | 49 // Initialize this accelerator with the given parameters and send |
47 // |init_done_msg| when complete. | 50 // |init_done_msg| when complete. |
48 bool Initialize(VideoPixelFormat input_format, | 51 bool Initialize(VideoPixelFormat input_format, |
49 const gfx::Size& input_visible_size, | 52 const gfx::Size& input_visible_size, |
50 VideoCodecProfile output_profile, | 53 VideoCodecProfile output_profile, |
51 uint32_t initial_bitrate); | 54 uint32_t initial_bitrate); |
52 | 55 |
53 // IPC::Listener implementation | 56 // IPC::Listener implementation |
(...skipping 11 matching lines...) Expand all Loading... | |
65 | 68 |
66 // gpu::GpuCommandBufferStub::DestructionObserver implementation. | 69 // gpu::GpuCommandBufferStub::DestructionObserver implementation. |
67 void OnWillDestroyStub() override; | 70 void OnWillDestroyStub() override; |
68 | 71 |
69 // Static query for supported profiles. This query calls the appropriate | 72 // Static query for supported profiles. This query calls the appropriate |
70 // platform-specific version. The returned supported profiles vector will | 73 // platform-specific version. The returned supported profiles vector will |
71 // not contain duplicates. | 74 // not contain duplicates. |
72 static gpu::VideoEncodeAcceleratorSupportedProfiles GetSupportedProfiles( | 75 static gpu::VideoEncodeAcceleratorSupportedProfiles GetSupportedProfiles( |
73 const gpu::GpuPreferences& gpu_preferences); | 76 const gpu::GpuPreferences& gpu_preferences); |
74 | 77 |
78 // Called on IO thread when |filter_| has been removed. | |
79 void OnFilterRemoved(); | |
80 | |
75 private: | 81 private: |
76 // Returns a vector of VEAFactoryFunctions for the current platform. | 82 // Returns a vector of VEAFactoryFunctions for the current platform. |
77 using VEAFactoryFunction = | 83 using VEAFactoryFunction = |
78 base::Callback<std::unique_ptr<VideoEncodeAccelerator>()>; | 84 base::Callback<std::unique_ptr<VideoEncodeAccelerator>()>; |
79 static std::vector<VEAFactoryFunction> GetVEAFactoryFunctions( | 85 static std::vector<VEAFactoryFunction> GetVEAFactoryFunctions( |
80 const gpu::GpuPreferences& gpu_preferences); | 86 const gpu::GpuPreferences& gpu_preferences); |
81 | 87 |
88 class MessageFilter; | |
89 | |
82 // IPC handlers, proxying VideoEncodeAccelerator for the renderer | 90 // IPC handlers, proxying VideoEncodeAccelerator for the renderer |
83 // process. | 91 // process. |
84 void OnEncode(const AcceleratedVideoEncoderMsg_Encode_Params& params); | 92 void OnEncode(const AcceleratedVideoEncoderMsg_Encode_Params& params); |
85 void OnUseOutputBitstreamBuffer(int32_t buffer_id, | 93 void OnUseOutputBitstreamBuffer(int32_t buffer_id, |
86 base::SharedMemoryHandle buffer_handle, | 94 base::SharedMemoryHandle buffer_handle, |
87 uint32_t buffer_size); | 95 uint32_t buffer_size); |
88 void OnRequestEncodingParametersChange(uint32_t bitrate, uint32_t framerate); | 96 void OnRequestEncodingParametersChange(uint32_t bitrate, uint32_t framerate); |
89 | 97 |
90 void OnDestroy(); | 98 void OnDestroy(); |
91 | 99 |
92 void EncodeFrameFinished(int32_t frame_id, | 100 void EncodeFrameFinished(int32_t frame_id, |
93 std::unique_ptr<base::SharedMemory> shm); | 101 std::unique_ptr<base::SharedMemory> shm); |
94 void Send(IPC::Message* message); | 102 bool Send(IPC::Message* message); |
103 | |
104 // Checks that function is called on the correct thread. If MessageFilter is | |
105 // used, checks if it is called on |io_task_runner_|. If not, checks if it is | |
106 // called on |main_task_runner_|. | |
107 bool CheckCalledOnMessageFilterThread(); | |
Pawel Osciak
2016/10/25 01:44:05
Since this checks whether we are on message filter
emircan
2016/10/25 21:57:51
Done.
| |
95 | 108 |
96 // Route ID to communicate with the host. | 109 // Route ID to communicate with the host. |
97 const uint32_t host_route_id_; | 110 const uint32_t host_route_id_; |
98 | 111 |
99 // Unowned pointer to the underlying gpu::GpuCommandBufferStub. |this| is | 112 // Unowned pointer to the underlying gpu::GpuCommandBufferStub. |this| is |
100 // registered as a DestuctionObserver of |stub_| and will self-delete when | 113 // registered as a DestuctionObserver of |stub_| and will self-delete when |
101 // |stub_| is destroyed. | 114 // |stub_| is destroyed. |
102 gpu::GpuCommandBufferStub* const stub_; | 115 gpu::GpuCommandBufferStub* const stub_; |
103 | 116 |
104 // Owned pointer to the underlying VideoEncodeAccelerator. | 117 // Owned pointer to the underlying VideoEncodeAccelerator. |
105 std::unique_ptr<VideoEncodeAccelerator> encoder_; | 118 std::unique_ptr<VideoEncodeAccelerator> encoder_; |
106 base::Callback<bool(void)> make_context_current_; | 119 base::Callback<bool(void)> make_context_current_; |
107 | 120 |
108 // Video encoding parameters. | 121 // Video encoding parameters. |
109 VideoPixelFormat input_format_; | 122 VideoPixelFormat input_format_; |
110 gfx::Size input_visible_size_; | 123 gfx::Size input_visible_size_; |
111 gfx::Size input_coded_size_; | 124 gfx::Size input_coded_size_; |
112 size_t output_buffer_size_; | 125 size_t output_buffer_size_; |
113 | 126 |
127 // The message filter to run VDA::Decode on IO thread if VDA supports it. | |
Pawel Osciak
2016/10/25 01:44:05
"VDA::Decode", "VDA"...
emircan
2016/10/25 21:57:51
Done.
| |
128 scoped_refptr<MessageFilter> filter_; | |
129 | |
130 // Used to wait on for |filter_| to be removed, before we can safely | |
131 // destroy the VEA. | |
132 base::WaitableEvent filter_removed_; | |
133 | |
134 // GPU main thread task runner. | |
135 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | |
136 | |
137 // GPU IO thread task runner. | |
138 const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | |
139 | |
114 // Weak pointer for VideoFrames that refer back to |this|. | 140 // Weak pointer for VideoFrames that refer back to |this|. |
115 base::WeakPtrFactory<GpuVideoEncodeAccelerator> weak_this_factory_; | 141 base::WeakPtrFactory<GpuVideoEncodeAccelerator> weak_this_factory_; |
116 | 142 |
117 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAccelerator); | 143 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAccelerator); |
118 }; | 144 }; |
119 | 145 |
120 } // namespace media | 146 } // namespace media |
121 | 147 |
122 #endif // MEDIA_GPU_IPC_SERVICE_GPU_VIDEO_ENCODE_ACCELERATOR_H_ | 148 #endif // MEDIA_GPU_IPC_SERVICE_GPU_VIDEO_ENCODE_ACCELERATOR_H_ |
OLD | NEW |