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/shared_impl/scoped_pp_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 // Called only by unit tests. This bypasses Graphics3D setup, which doesn't |
| 64 // work in ppapi::proxy::PluginProxyTest. |
| 65 void SetForTest(); |
| 66 |
| 67 private: |
| 68 // Struct to hold a shared memory buffer. |
| 69 struct ShmBuffer { |
| 70 ShmBuffer(base::SharedMemory* shm, uint32_t size, uint32_t shm_id); |
| 71 ~ShmBuffer(); |
| 72 |
| 73 scoped_ptr<base::SharedMemory> shm; |
| 74 uint32_t size; |
| 75 void* addr; |
| 76 // Index into shm_buffers_ vector, used as an id. This should map 1:1 to |
| 77 // the index on the host side of the proxy. |
| 78 uint32_t shm_id; |
| 79 }; |
| 80 |
| 81 // Struct to hold texture information. |
| 82 struct Texture { |
| 83 Texture(uint32_t texture_target, const PP_Size& size); |
| 84 ~Texture(); |
| 85 |
| 86 uint32_t texture_target; |
| 87 PP_Size size; |
| 88 }; |
| 89 |
| 90 // Struct to hold a picture received from the decoder. |
| 91 struct Picture { |
| 92 Picture(int32_t decode_id, uint32_t texture_id); |
| 93 ~Picture(); |
| 94 |
| 95 uint32_t decode_id; |
| 96 uint32_t texture_id; |
| 97 }; |
| 98 |
| 99 int32_t InitializeInternal(PP_Resource graphics_context, |
| 100 PP_VideoProfile profile, |
| 101 PP_Bool allow_software_fallback, |
| 102 scoped_refptr<TrackedCallback> callback, |
| 103 bool testing); |
| 104 |
| 105 // Unsolicited reply message handlers. |
| 106 void OnPluginMsgRequestTextures(const ResourceMessageReplyParams& params, |
| 107 uint32_t num_textures, |
| 108 const PP_Size& size, |
| 109 uint32_t texture_target); |
| 110 void OnPluginMsgPictureReady(const ResourceMessageReplyParams& params, |
| 111 uint32_t decode_id, |
| 112 uint32_t texture_id); |
| 113 void OnPluginMsgDismissPicture(const ResourceMessageReplyParams& params, |
| 114 uint32_t texture_id); |
| 115 void OnPluginMsgNotifyError(const ResourceMessageReplyParams& params, |
| 116 int32_t error); |
| 117 |
| 118 // Reply message handlers for operations that are done in the host. |
| 119 void OnPluginMsgInitializeComplete(const ResourceMessageReplyParams& params); |
| 120 void OnPluginMsgGetShmComplete(const ResourceMessageReplyParams& params, |
| 121 uint32_t size); |
| 122 void OnPluginMsgDecodeComplete(const ResourceMessageReplyParams& params, |
| 123 uint32_t shm_id); |
| 124 void OnPluginMsgFlushComplete(const ResourceMessageReplyParams& params); |
| 125 void OnPluginMsgResetComplete(const ResourceMessageReplyParams& params); |
| 126 |
| 127 int32_t TryDecode(uint32_t decode_id, |
| 128 uint32_t size, |
| 129 const void* buffer, |
| 130 scoped_refptr<TrackedCallback> callback); |
| 131 void SendDecodeMessage(uint32_t shm_id); |
| 132 void RunDecodeCallback(int32_t result); |
| 133 |
| 134 void DeleteGLTexture(uint32_t texture_id); |
| 135 void WriteNextPicture(PP_VideoPicture* picture); |
| 136 |
| 137 // ScopedVector to own the shared memory buffers. |
| 138 ScopedVector<ShmBuffer> shm_buffers_; |
| 139 |
| 140 // List of available shared memory buffers. |
| 141 typedef std::vector<ShmBuffer*> ShmBufferList; |
| 142 ShmBufferList available_shm_buffers_; |
| 143 |
| 144 // Map of GL texture id to texture info. |
| 145 typedef base::hash_map<uint32_t, Texture> TextureMap; |
| 146 TextureMap textures_; |
| 147 |
| 148 // Queue of received pictures. |
| 149 typedef std::queue<Picture> PictureQueue; |
| 150 PictureQueue received_pictures_; |
| 151 |
| 152 // Pending callbacks. |
| 153 scoped_refptr<TrackedCallback> initialize_callback_; |
| 154 scoped_refptr<TrackedCallback> decode_callback_; |
| 155 scoped_refptr<TrackedCallback> get_picture_callback_; |
| 156 scoped_refptr<TrackedCallback> flush_callback_; |
| 157 scoped_refptr<TrackedCallback> reset_callback_; |
| 158 |
| 159 // State for pending decode_callback_. |
| 160 uint32_t decode_id_; |
| 161 uint32_t decode_size_; |
| 162 const void* decode_buffer_; |
| 163 uint32_t pending_decode_count_; |
| 164 bool get_shm_buffer_pending_; |
| 165 // State for pending get_picture_callback_. |
| 166 PP_VideoPicture* get_picture_; |
| 167 |
| 168 ScopedPPResource graphics3d_; |
| 169 gpu::gles2::GLES2Implementation* gles2_impl_; |
| 170 |
| 171 bool initialized_; |
| 172 bool testing_; |
| 173 int32_t decoder_last_error_; |
| 174 |
| 175 DISALLOW_COPY_AND_ASSIGN(VideoDecoderResource); |
| 176 }; |
| 177 |
| 178 } // namespace proxy |
| 179 } // namespace ppapi |
| 180 |
| 181 #endif // PPAPI_PROXY_VIDEO_DECODER_RESOURCE_H_ |
OLD | NEW |