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

Side by Side Diff: ppapi/proxy/video_decoder_resource.h

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

Powered by Google App Engine
This is Rietveld 408576698