Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / common / gpu / media / gpu_video_decode_accelerator.h
blob05d9fb0a1b9322f1c905d31b0a7a2226cf273b3c
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 "ipc/ipc_listener.h"
18 #include "ipc/ipc_sender.h"
19 #include "media/video/video_decode_accelerator.h"
20 #include "ui/gfx/size.h"
22 namespace base {
23 class MessageLoopProxy;
26 namespace content {
28 class GpuVideoDecodeAccelerator
29 : public IPC::Listener,
30 public IPC::Sender,
31 public media::VideoDecodeAccelerator::Client,
32 public GpuCommandBufferStub::DestructionObserver {
33 public:
34 // Each of the arguments to the constructor must outlive this object.
35 // |stub->decoder()| will be made current around any operation that touches
36 // the underlying VDA so that it can make GL calls safely.
37 GpuVideoDecodeAccelerator(
38 int32 host_route_id,
39 GpuCommandBufferStub* stub,
40 const scoped_refptr<base::MessageLoopProxy>& io_message_loop);
42 // IPC::Listener implementation.
43 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
45 // media::VideoDecodeAccelerator::Client implementation.
46 virtual void ProvidePictureBuffers(uint32 requested_num_of_buffers,
47 const gfx::Size& dimensions,
48 uint32 texture_target) OVERRIDE;
49 virtual void DismissPictureBuffer(int32 picture_buffer_id) OVERRIDE;
50 virtual void PictureReady(const media::Picture& picture) OVERRIDE;
51 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE;
52 virtual void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id) OVERRIDE;
53 virtual void NotifyFlushDone() OVERRIDE;
54 virtual void NotifyResetDone() OVERRIDE;
56 // GpuCommandBufferStub::DestructionObserver implementation.
57 virtual void OnWillDestroyStub() OVERRIDE;
59 // Function to delegate sending to actual sender.
60 virtual bool Send(IPC::Message* message) OVERRIDE;
62 // Initialize the accelerator with the given profile and send the
63 // |init_done_msg| when done.
64 void Initialize(const media::VideoCodecProfile profile,
65 IPC::Message* init_done_msg);
67 private:
68 class MessageFilter;
70 // We only allow self-delete, from OnWillDestroyStub(), after cleanup there.
71 virtual ~GpuVideoDecodeAccelerator();
73 // Handlers for IPC messages.
74 void OnDecode(base::SharedMemoryHandle handle, int32 id, uint32 size);
75 void OnAssignPictureBuffers(const std::vector<int32>& buffer_ids,
76 const std::vector<uint32>& texture_ids);
77 void OnReusePictureBuffer(int32 picture_buffer_id);
78 void OnFlush();
79 void OnReset();
80 void OnDestroy();
82 // Called on IO thread when |filter_| has been removed.
83 void OnFilterRemoved();
85 // Sets the texture to cleared.
86 void SetTextureCleared(const media::Picture& picture);
88 // Helper for replying to the creation request.
89 void SendCreateDecoderReply(IPC::Message* message, bool succeeded);
91 // Route ID to communicate with the host.
92 int32 host_route_id_;
94 // Unowned pointer to the underlying GpuCommandBufferStub. |this| is
95 // registered as a DestuctionObserver of |stub_| and will self-delete when
96 // |stub_| is destroyed.
97 GpuCommandBufferStub* stub_;
99 // The underlying VideoDecodeAccelerator.
100 scoped_ptr<media::VideoDecodeAccelerator> video_decode_accelerator_;
102 // Callback for making the relevant context current for GL calls.
103 // Returns false if failed.
104 base::Callback<bool(void)> make_context_current_;
106 // The texture dimensions as requested by ProvidePictureBuffers().
107 gfx::Size texture_dimensions_;
109 // The texture target as requested by ProvidePictureBuffers().
110 uint32 texture_target_;
112 // The message filter to run VDA::Decode on IO thread if VDA supports it.
113 scoped_refptr<MessageFilter> filter_;
115 // Used to wait on for |filter_| to be removed, before we can safely
116 // destroy the VDA.
117 base::WaitableEvent filter_removed_;
119 // GPU child message loop.
120 scoped_refptr<base::MessageLoopProxy> child_message_loop_;
122 // GPU IO message loop.
123 scoped_refptr<base::MessageLoopProxy> io_message_loop_;
125 // Weak pointers will be invalidated on IO thread.
126 base::WeakPtrFactory<Client> weak_factory_for_io_;
128 // Protects |uncleared_textures_| when DCHECK is on. This is for debugging
129 // only. We don't want to hold a lock on IO thread. When DCHECK is off,
130 // |uncleared_textures_| is only accessed from the child thread.
131 base::Lock debug_uncleared_textures_lock_;
133 // A map from picture buffer ID to TextureRef that have not been cleared.
134 std::map<int32, scoped_refptr<gpu::gles2::TextureRef> > uncleared_textures_;
136 DISALLOW_IMPLICIT_CONSTRUCTORS(GpuVideoDecodeAccelerator);
139 } // namespace content
141 #endif // CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_H_