Update broken references to image assets
[chromium-blink-merge.git] / content / common / gpu / media / gpu_video_decode_accelerator.h
blobcab2a2285cd346add4ea6ddbbfe3793a39fc05dc
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.
5 #ifndef CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_H_
6 #define CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_H_
8 #include <map>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/shared_memory.h"
14 #include "base/synchronization/waitable_event.h"
15 #include "content/common/gpu/gpu_command_buffer_stub.h"
16 #include "gpu/command_buffer/service/texture_manager.h"
17 #include "gpu/config/gpu_info.h"
18 #include "ipc/ipc_listener.h"
19 #include "ipc/ipc_sender.h"
20 #include "media/video/video_decode_accelerator.h"
21 #include "ui/gfx/geometry/size.h"
23 namespace content {
25 class GpuVideoDecodeAccelerator
26 : public IPC::Listener,
27 public IPC::Sender,
28 public media::VideoDecodeAccelerator::Client,
29 public GpuCommandBufferStub::DestructionObserver {
30 public:
31 // Each of the arguments to the constructor must outlive this object.
32 // |stub->decoder()| will be made current around any operation that touches
33 // the underlying VDA so that it can make GL calls safely.
34 GpuVideoDecodeAccelerator(
35 int32 host_route_id,
36 GpuCommandBufferStub* stub,
37 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner);
39 // IPC::Listener implementation.
40 bool OnMessageReceived(const IPC::Message& message) override;
42 // media::VideoDecodeAccelerator::Client implementation.
43 void ProvidePictureBuffers(uint32 requested_num_of_buffers,
44 const gfx::Size& dimensions,
45 uint32 texture_target) override;
46 void DismissPictureBuffer(int32 picture_buffer_id) override;
47 void PictureReady(const media::Picture& picture) override;
48 void NotifyError(media::VideoDecodeAccelerator::Error error) override;
49 void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id) override;
50 void NotifyFlushDone() override;
51 void NotifyResetDone() override;
53 // GpuCommandBufferStub::DestructionObserver implementation.
54 void OnWillDestroyStub() override;
56 // Function to delegate sending to actual sender.
57 bool Send(IPC::Message* message) override;
59 // Initialize VDAs from the set of VDAs supported for current platform until
60 // one of them succeeds for given |profile|. Send the |init_done_msg| when
61 // done. filter_ is passed to GpuCommandBufferStub channel only if the chosen
62 // VDA can decode on IO thread.
63 void Initialize(const media::VideoCodecProfile profile,
64 IPC::Message* init_done_msg);
66 // Static query for supported profiles. This query calls the appropriate
67 // platform-specific version. The returned supported profiles vector will
68 // not contain duplicates.
69 static gpu::VideoDecodeAcceleratorSupportedProfiles GetSupportedProfiles();
71 private:
72 typedef scoped_ptr<media::VideoDecodeAccelerator>(
73 GpuVideoDecodeAccelerator::*CreateVDAFp)();
75 class MessageFilter;
77 scoped_ptr<media::VideoDecodeAccelerator> CreateDXVAVDA();
78 scoped_ptr<media::VideoDecodeAccelerator> CreateV4L2VDA();
79 scoped_ptr<media::VideoDecodeAccelerator> CreateV4L2SliceVDA();
80 scoped_ptr<media::VideoDecodeAccelerator> CreateVaapiVDA();
81 scoped_ptr<media::VideoDecodeAccelerator> CreateVTVDA();
82 scoped_ptr<media::VideoDecodeAccelerator> CreateOzoneVDA();
83 scoped_ptr<media::VideoDecodeAccelerator> CreateAndroidVDA();
85 // We only allow self-delete, from OnWillDestroyStub(), after cleanup there.
86 ~GpuVideoDecodeAccelerator() override;
88 // Handlers for IPC messages.
89 void OnDecode(base::SharedMemoryHandle handle, int32 id, uint32 size);
90 void OnAssignPictureBuffers(const std::vector<int32>& buffer_ids,
91 const std::vector<uint32>& texture_ids);
92 void OnReusePictureBuffer(int32 picture_buffer_id);
93 void OnFlush();
94 void OnReset();
95 void OnDestroy();
97 // Called on IO thread when |filter_| has been removed.
98 void OnFilterRemoved();
100 // Sets the texture to cleared.
101 void SetTextureCleared(const media::Picture& picture);
103 // Helper for replying to the creation request.
104 void SendCreateDecoderReply(IPC::Message* message, bool succeeded);
106 // Helper to bind |image| to the texture specified by |client_texture_id|.
107 void BindImage(uint32 client_texture_id,
108 uint32 texture_target,
109 scoped_refptr<gfx::GLImage> image);
111 // Route ID to communicate with the host.
112 const int32 host_route_id_;
114 // Unowned pointer to the underlying GpuCommandBufferStub. |this| is
115 // registered as a DestuctionObserver of |stub_| and will self-delete when
116 // |stub_| is destroyed.
117 GpuCommandBufferStub* const stub_;
119 // The underlying VideoDecodeAccelerator.
120 scoped_ptr<media::VideoDecodeAccelerator> video_decode_accelerator_;
122 // Callback for making the relevant context current for GL calls.
123 // Returns false if failed.
124 base::Callback<bool(void)> make_context_current_;
126 // The texture dimensions as requested by ProvidePictureBuffers().
127 gfx::Size texture_dimensions_;
129 // The texture target as requested by ProvidePictureBuffers().
130 uint32 texture_target_;
132 // The message filter to run VDA::Decode on IO thread if VDA supports it.
133 scoped_refptr<MessageFilter> filter_;
135 // Used to wait on for |filter_| to be removed, before we can safely
136 // destroy the VDA.
137 base::WaitableEvent filter_removed_;
139 // GPU child thread task runner.
140 const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_;
142 // GPU IO thread task runner.
143 const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
145 // Weak pointers will be invalidated on IO thread.
146 base::WeakPtrFactory<Client> weak_factory_for_io_;
148 // Protects |uncleared_textures_| when DCHECK is on. This is for debugging
149 // only. We don't want to hold a lock on IO thread. When DCHECK is off,
150 // |uncleared_textures_| is only accessed from the child thread.
151 base::Lock debug_uncleared_textures_lock_;
153 // A map from picture buffer ID to TextureRef that have not been cleared.
154 std::map<int32, scoped_refptr<gpu::gles2::TextureRef> > uncleared_textures_;
156 DISALLOW_IMPLICIT_CONSTRUCTORS(GpuVideoDecodeAccelerator);
159 } // namespace content
161 #endif // CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_H_