OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 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 PPAPI_PROXY_VIDEO_DECODER_RESOURCE_H_ | |
6 #define PPAPI_PROXY_VIDEO_DECODER_RESOURCE_H_ | |
7 | |
8 #include <queue> | |
9 | |
10 #include "base/containers/hash_tables.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/memory/scoped_vector.h" | |
14 #include "ppapi/proxy/connection.h" | |
15 #include "ppapi/proxy/plugin_resource.h" | |
16 #include "ppapi/proxy/ppapi_proxy_export.h" | |
17 #include "ppapi/shared_impl/resource.h" | |
18 #include "ppapi/thunk/ppb_video_decoder_api.h" | |
19 | |
20 namespace gpu { | |
21 namespace gles2 { | |
22 class GLES2Implementation; | |
23 } | |
24 } | |
25 | |
26 namespace ppapi { | |
27 | |
28 class PPB_Graphics3D_Shared; | |
29 class TrackedCallback; | |
30 | |
31 namespace proxy { | |
32 | |
33 class PPAPI_PROXY_EXPORT VideoDecoderResource | |
34 : public PluginResource, | |
35 public thunk::PPB_VideoDecoder_API { | |
36 public: | |
37 VideoDecoderResource(Connection connection, PP_Instance instance); | |
38 virtual ~VideoDecoderResource(); | |
39 | |
40 // Resource overrides. | |
41 virtual thunk::PPB_VideoDecoder_API* AsPPB_VideoDecoder_API() OVERRIDE; | |
42 | |
43 // PPB_VideoDecoder_API implementation. | |
44 virtual int32_t Initialize(PP_Resource graphics_context, | |
45 PP_VideoProfile profile, | |
46 PP_Bool allow_software_fallback, | |
47 scoped_refptr<TrackedCallback> callback) OVERRIDE; | |
48 virtual int32_t Decode(uint32_t decode_id, | |
49 uint32_t size, | |
50 const void* buffer, | |
51 scoped_refptr<TrackedCallback> callback) OVERRIDE; | |
52 virtual int32_t GetPicture(PP_VideoPicture* picture, | |
53 scoped_refptr<TrackedCallback> callback) OVERRIDE; | |
54 virtual void RecyclePicture(const PP_VideoPicture* picture) OVERRIDE; | |
55 virtual int32_t Flush(scoped_refptr<TrackedCallback> callback) OVERRIDE; | |
56 virtual int32_t Reset(scoped_refptr<TrackedCallback> callback) OVERRIDE; | |
57 | |
58 // PluginResource implementation. | |
59 virtual void OnReplyReceived(const ResourceMessageReplyParams& params, | |
60 const IPC::Message& msg) OVERRIDE; | |
61 | |
62 // Called only by unit tests. This bypasses Graphics3D setup, which doesn't | |
63 // work in ppapi::proxy::PluginProxyTest. | |
64 void SetForTest(); | |
65 | |
66 private: | |
67 // Struct to hold a shared memory buffer. | |
68 struct ShmBuffer { | |
69 ShmBuffer(base::SharedMemory* shm, uint32_t size, uint32_t shm_id); | |
70 ~ShmBuffer(); | |
71 | |
72 scoped_ptr<base::SharedMemory> shm_; | |
yzshen1
2014/05/14 18:08:23
I think public struct members don't need '_' suffi
bbudge
2014/05/14 19:35:04
Done.
| |
73 uint32_t size_; | |
74 void* addr_; | |
75 // Index into shm_buffers_ vector, used as an id. This should map 1:1 to | |
76 // the index on the host side of the proxy. | |
77 uint32_t shm_id_; | |
78 }; | |
79 | |
80 // Struct to hold texture information. | |
81 struct Texture { | |
82 Texture(uint32_t texture_target, const PP_Size& size); | |
83 ~Texture(); | |
84 | |
85 uint32_t texture_target_; | |
86 PP_Size size_; | |
87 }; | |
88 | |
89 // Struct to hold a picture received from the decoder. | |
90 struct Picture { | |
91 Picture(int32_t decode_id, uint32_t texture_id); | |
92 ~Picture(); | |
93 | |
94 uint32_t decode_id_; | |
95 uint32_t texture_id_; | |
96 }; | |
97 | |
98 int32_t InitializeInternal(PP_Resource graphics_context, | |
99 PP_VideoProfile profile, | |
100 PP_Bool allow_software_fallback, | |
101 scoped_refptr<TrackedCallback> callback, | |
102 bool testing); | |
103 | |
104 // Unsolicited reply message handlers. | |
105 void OnPluginMsgRequestTextures(const ResourceMessageReplyParams& params, | |
106 uint32_t num_textures, | |
107 PP_Size size, | |
yzshen1
2014/05/14 18:08:23
const &?
bbudge
2014/05/14 19:35:04
Done.
| |
108 uint32_t texture_target); | |
109 void OnPluginMsgPictureReady(const ResourceMessageReplyParams& params, | |
110 uint32_t decode_id, | |
111 uint32_t texture_id); | |
112 void OnPluginMsgDismissPicture(const ResourceMessageReplyParams& params, | |
113 uint32_t texture_id); | |
114 void OnPluginMsgNotifyError(const ResourceMessageReplyParams& params, | |
115 int32_t error); | |
116 | |
117 // Reply message handlers for operations that are done in the host. | |
118 void OnPluginMsgInitializeComplete(const ResourceMessageReplyParams& params); | |
119 void OnPluginMsgGetShmComplete(const ResourceMessageReplyParams& params, | |
120 uint32_t size); | |
121 void OnPluginMsgDecodeComplete(const ResourceMessageReplyParams& params, | |
122 uint32_t shm_id); | |
123 void OnPluginMsgFlushComplete(const ResourceMessageReplyParams& params); | |
124 void OnPluginMsgResetComplete(const ResourceMessageReplyParams& params); | |
125 | |
126 int32_t TryDecode(uint32_t decode_id, | |
127 uint32_t size, | |
128 const void* buffer, | |
129 scoped_refptr<TrackedCallback> callback); | |
130 void SendDecodeMessage(uint32_t shm_id); | |
131 void RunDecodeCallback(int32_t result); | |
132 | |
133 void DeleteGLTexture(uint32_t texture_id); | |
134 void WriteNextPicture(PP_VideoPicture* picture); | |
135 | |
136 // ScopedVector to own the shared memory buffers. | |
137 ScopedVector<ShmBuffer> shm_buffers_; | |
138 | |
139 // List of available shared memory buffers. | |
140 typedef std::vector<ShmBuffer*> ShmBufferList; | |
141 ShmBufferList available_shm_buffers_; | |
142 | |
143 // Map of GL texture id to texture info. | |
144 typedef base::hash_map<uint32_t, Texture> TextureMap; | |
145 TextureMap textures_; | |
146 | |
147 // Queue of received pictures. | |
148 typedef std::queue<Picture> PictureQueue; | |
149 PictureQueue received_pictures_; | |
150 | |
151 // Pending callbacks. | |
152 scoped_refptr<TrackedCallback> initialize_callback_; | |
153 scoped_refptr<TrackedCallback> decode_callback_; | |
154 scoped_refptr<TrackedCallback> get_picture_callback_; | |
155 scoped_refptr<TrackedCallback> flush_callback_; | |
156 scoped_refptr<TrackedCallback> reset_callback_; | |
157 | |
158 // State for pending decode_callback_. | |
159 uint32_t decode_id_; | |
160 uint32_t decode_size_; | |
161 const void* decode_buffer_; | |
162 uint32_t pending_decode_count_; | |
163 bool get_shm_buffer_pending_; | |
164 // State for pending get_picture_callback_. | |
165 PP_VideoPicture* get_picture_; | |
166 | |
167 scoped_refptr<PPB_Graphics3D_Shared> graphics3d_; | |
168 gpu::gles2::GLES2Implementation* gles2_impl_; | |
169 | |
170 bool initialized_; | |
171 bool testing_; | |
172 int32_t decoder_last_error_; | |
173 | |
174 DISALLOW_COPY_AND_ASSIGN(VideoDecoderResource); | |
175 }; | |
176 | |
177 } // namespace proxy | |
178 } // namespace ppapi | |
179 | |
180 #endif // PPAPI_PROXY_VIDEO_DECODER_RESOURCE_H_ | |
OLD | NEW |