OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_H_ | |
6 #define CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <map> | |
11 #include <vector> | |
12 | |
13 #include "base/compiler_specific.h" | |
14 #include "base/macros.h" | |
15 #include "base/memory/ref_counted.h" | |
16 #include "base/memory/shared_memory.h" | |
17 #include "base/synchronization/waitable_event.h" | |
18 #include "content/common/gpu/media/gpu_video_decode_accelerator_helpers.h" | |
19 #include "gpu/command_buffer/service/texture_manager.h" | |
20 #include "gpu/config/gpu_info.h" | |
21 #include "gpu/ipc/service/gpu_command_buffer_stub.h" | |
22 #include "gpu/ipc/service/gpu_command_buffer_stub.h" | |
23 #include "ipc/ipc_listener.h" | |
24 #include "ipc/ipc_sender.h" | |
25 #include "media/video/video_decode_accelerator.h" | |
26 #include "ui/gfx/geometry/size.h" | |
27 | |
28 namespace gpu { | |
29 struct GpuPreferences; | |
30 } // namespace gpu | |
31 | |
32 namespace content { | |
33 | |
34 class GpuVideoDecodeAccelerator | |
35 : public IPC::Listener, | |
36 public IPC::Sender, | |
37 public media::VideoDecodeAccelerator::Client, | |
38 public gpu::GpuCommandBufferStub::DestructionObserver { | |
39 public: | |
40 // Each of the arguments to the constructor must outlive this object. | |
41 // |stub->decoder()| will be made current around any operation that touches | |
42 // the underlying VDA so that it can make GL calls safely. | |
43 GpuVideoDecodeAccelerator( | |
44 int32_t host_route_id, | |
45 gpu::GpuCommandBufferStub* stub, | |
46 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | |
47 | |
48 // Static query for the capabilities, which includes the supported profiles. | |
49 // This query calls the appropriate platform-specific version. The returned | |
50 // capabilities will not contain duplicate supported profile entries. | |
51 static gpu::VideoDecodeAcceleratorCapabilities GetCapabilities( | |
52 const gpu::GpuPreferences& gpu_preferences); | |
53 | |
54 // IPC::Listener implementation. | |
55 bool OnMessageReceived(const IPC::Message& message) override; | |
56 | |
57 // media::VideoDecodeAccelerator::Client implementation. | |
58 void NotifyInitializationComplete(bool success) override; | |
59 void ProvidePictureBuffers(uint32_t requested_num_of_buffers, | |
60 uint32_t textures_per_buffer, | |
61 const gfx::Size& dimensions, | |
62 uint32_t texture_target) override; | |
63 void DismissPictureBuffer(int32_t picture_buffer_id) override; | |
64 void PictureReady(const media::Picture& picture) override; | |
65 void NotifyEndOfBitstreamBuffer(int32_t bitstream_buffer_id) override; | |
66 void NotifyFlushDone() override; | |
67 void NotifyResetDone() override; | |
68 void NotifyError(media::VideoDecodeAccelerator::Error error) override; | |
69 | |
70 // GpuCommandBufferStub::DestructionObserver implementation. | |
71 void OnWillDestroyStub() override; | |
72 | |
73 // Function to delegate sending to actual sender. | |
74 bool Send(IPC::Message* message) override; | |
75 | |
76 // Initialize VDAs from the set of VDAs supported for current platform until | |
77 // one of them succeeds for given |config|. Send the |init_done_msg| when | |
78 // done. filter_ is passed to gpu::GpuCommandBufferStub channel only if the | |
79 // chosen VDA can decode on IO thread. | |
80 bool Initialize(const media::VideoDecodeAccelerator::Config& config); | |
81 | |
82 private: | |
83 class MessageFilter; | |
84 | |
85 // We only allow self-delete, from OnWillDestroyStub(), after cleanup there. | |
86 ~GpuVideoDecodeAccelerator() override; | |
87 | |
88 // Handlers for IPC messages. | |
89 void OnSetCdm(int cdm_id); | |
90 void OnDecode(const media::BitstreamBuffer& bitstream_buffer); | |
91 void OnAssignPictureBuffers( | |
92 const std::vector<int32_t>& buffer_ids, | |
93 const std::vector<media::PictureBuffer::TextureIds>& texture_ids); | |
94 void OnReusePictureBuffer(int32_t picture_buffer_id); | |
95 void OnFlush(); | |
96 void OnReset(); | |
97 void OnDestroy(); | |
98 | |
99 // Called on IO thread when |filter_| has been removed. | |
100 void OnFilterRemoved(); | |
101 | |
102 // Sets the texture to cleared. | |
103 void SetTextureCleared(const media::Picture& picture); | |
104 | |
105 // Route ID to communicate with the host. | |
106 const int32_t host_route_id_; | |
107 | |
108 // Unowned pointer to the underlying gpu::GpuCommandBufferStub. |this| is | |
109 // registered as a DestuctionObserver of |stub_| and will self-delete when | |
110 // |stub_| is destroyed. | |
111 gpu::GpuCommandBufferStub* const stub_; | |
112 | |
113 // The underlying VideoDecodeAccelerator. | |
114 std::unique_ptr<media::VideoDecodeAccelerator> video_decode_accelerator_; | |
115 | |
116 // Callback to return current GLContext, if available. | |
117 GetGLContextCallback get_gl_context_cb_; | |
118 | |
119 // Callback for making the relevant context current for GL calls. | |
120 MakeGLContextCurrentCallback make_context_current_cb_; | |
121 | |
122 // Callback to bind a GLImage to a given texture id and target. | |
123 BindGLImageCallback bind_image_cb_; | |
124 | |
125 // Callback to return a WeakPtr to GLES2Decoder. | |
126 GetGLES2DecoderCallback get_gles2_decoder_cb_; | |
127 | |
128 // The texture dimensions as requested by ProvidePictureBuffers(). | |
129 gfx::Size texture_dimensions_; | |
130 | |
131 // The texture target as requested by ProvidePictureBuffers(). | |
132 uint32_t texture_target_; | |
133 | |
134 // The number of textures per picture buffer as requests by | |
135 // ProvidePictureBuffers() | |
136 uint32_t textures_per_buffer_; | |
137 | |
138 // The message filter to run VDA::Decode on IO thread if VDA supports it. | |
139 scoped_refptr<MessageFilter> filter_; | |
140 | |
141 // Used to wait on for |filter_| to be removed, before we can safely | |
142 // destroy the VDA. | |
143 base::WaitableEvent filter_removed_; | |
144 | |
145 // GPU child thread task runner. | |
146 const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; | |
147 | |
148 // GPU IO thread task runner. | |
149 const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | |
150 | |
151 // Weak pointers will be invalidated on IO thread. | |
152 base::WeakPtrFactory<Client> weak_factory_for_io_; | |
153 | |
154 // Protects |uncleared_textures_| when DCHECK is on. This is for debugging | |
155 // only. We don't want to hold a lock on IO thread. When DCHECK is off, | |
156 // |uncleared_textures_| is only accessed from the child thread. | |
157 base::Lock debug_uncleared_textures_lock_; | |
158 | |
159 // A map from picture buffer ID to set of TextureRefs that have not been | |
160 // cleared. | |
161 std::map<int32_t, std::vector<scoped_refptr<gpu::gles2::TextureRef>>> | |
162 uncleared_textures_; | |
163 | |
164 DISALLOW_IMPLICIT_CONSTRUCTORS(GpuVideoDecodeAccelerator); | |
165 }; | |
166 | |
167 } // namespace content | |
168 | |
169 #endif // CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_H_ | |
OLD | NEW |