Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: content/common/gpu/media/gpu_video_decode_accelerator.h

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

Powered by Google App Engine
This is Rietveld 408576698