Respond with QuotaExceededError when IndexedDB has no disk space on open.
[chromium-blink-merge.git] / content / common / gpu / media / gpu_video_decode_accelerator.h
blob77946bc59a2083aac7ef4f4956716fd24d6f74f2
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 <vector>
10 #include "base/compiler_specific.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/shared_memory.h"
13 #include "content/common/gpu/gpu_command_buffer_stub.h"
14 #include "content/common/gpu/media/video_decode_accelerator_impl.h"
15 #include "ipc/ipc_listener.h"
16 #include "ipc/ipc_sender.h"
17 #include "media/video/video_decode_accelerator.h"
19 namespace base {
20 class MessageLoopProxy;
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::MessageLoopProxy>& io_message_loop);
38 virtual ~GpuVideoDecodeAccelerator();
40 // IPC::Listener implementation.
41 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
43 // media::VideoDecodeAccelerator::Client implementation.
44 virtual void ProvidePictureBuffers(uint32 requested_num_of_buffers,
45 const gfx::Size& dimensions,
46 uint32 texture_target) OVERRIDE;
47 virtual void DismissPictureBuffer(int32 picture_buffer_id) OVERRIDE;
48 virtual void PictureReady(const media::Picture& picture) OVERRIDE;
49 virtual void NotifyInitializeDone() OVERRIDE;
50 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE;
51 virtual void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id) OVERRIDE;
52 virtual void NotifyFlushDone() OVERRIDE;
53 virtual void NotifyResetDone() OVERRIDE;
55 // GpuCommandBufferStub::DestructionObserver implementation.
56 virtual void OnWillDestroyStub() OVERRIDE;
58 // Function to delegate sending to actual sender.
59 virtual bool Send(IPC::Message* message) OVERRIDE;
61 // Initialize the accelerator with the given profile and send the
62 // |init_done_msg| when done.
63 // The renderer process handle is valid as long as we have a channel between
64 // GPU process and the renderer.
65 void Initialize(const media::VideoCodecProfile profile,
66 IPC::Message* init_done_msg);
68 private:
69 class MessageFilter;
71 // Handlers for IPC messages.
72 void OnDecode(base::SharedMemoryHandle handle, int32 id, uint32 size);
73 void OnAssignPictureBuffers(
74 const std::vector<int32>& buffer_ids,
75 const std::vector<uint32>& texture_ids,
76 const std::vector<gfx::Size>& sizes);
77 void OnReusePictureBuffer(
78 int32 picture_buffer_id);
79 void OnFlush();
80 void OnReset();
81 void OnDestroy();
83 // Called on IO thread when |filter_| has been removed.
84 void OnFilterRemoved();
86 // Message to Send() when initialization is done. Is only non-NULL during
87 // initialization and is owned by the IPC channel underlying the
88 // GpuCommandBufferStub.
89 IPC::Message* init_done_msg_;
91 // Route ID to communicate with the host.
92 int32 host_route_id_;
94 // Unowned pointer to the underlying GpuCommandBufferStub.
95 GpuCommandBufferStub* stub_;
97 // The underlying VideoDecodeAccelerator.
98 scoped_ptr<VideoDecodeAcceleratorImpl> video_decode_accelerator_;
100 // Callback for making the relevant context current for GL calls.
101 // Returns false if failed.
102 base::Callback<bool(void)> make_context_current_;
104 // The texture target as requested by ProvidePictureBuffers().
105 uint32 texture_target_;
107 // The message filter to run VDA::Decode on IO thread if VDA supports it.
108 scoped_refptr<MessageFilter> filter_;
110 // GPU child message loop.
111 scoped_refptr<base::MessageLoopProxy> child_message_loop_;
113 // GPU IO message loop.
114 scoped_refptr<base::MessageLoopProxy> io_message_loop_;
116 // Weak pointers will be invalidated on IO thread.
117 base::WeakPtrFactory<Client> weak_factory_for_io_;
119 DISALLOW_IMPLICIT_CONSTRUCTORS(GpuVideoDecodeAccelerator);
122 } // namespace content
124 #endif // CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_H_