Chromium Code Reviews| 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(scoped_ptr<base::SharedMemory> shm, | |
| 71 uint32_t size, | |
| 72 uint32_t shm_id); | |
| 73 ~ShmBuffer(); | |
| 74 | |
| 75 scoped_ptr<base::SharedMemory> shm; | |
| 76 uint32_t size; | |
|
dmichael (off chromium)
2014/05/20 22:40:38
is this different that SharedMemory::actual_size()
bbudge
2014/05/22 18:34:55
This is just shm->mapped_size().
Removed the extra
| |
| 77 void* addr; | |
| 78 // Index into shm_buffers_ vector, used as an id. This should map 1:1 to | |
| 79 // the index on the host side of the proxy. | |
| 80 uint32_t shm_id; | |
| 81 }; | |
| 82 | |
| 83 // Struct to hold texture information. | |
| 84 struct Texture { | |
| 85 Texture(uint32_t texture_target, const PP_Size& size); | |
| 86 ~Texture(); | |
| 87 | |
| 88 uint32_t texture_target; | |
| 89 PP_Size size; | |
| 90 }; | |
| 91 | |
| 92 // Struct to hold a picture received from the decoder. | |
| 93 struct Picture { | |
| 94 Picture(int32_t decode_id, uint32_t texture_id); | |
| 95 ~Picture(); | |
| 96 | |
| 97 uint32_t decode_id; | |
| 98 uint32_t texture_id; | |
| 99 }; | |
| 100 | |
| 101 int32_t InitializeInternal(PP_Resource graphics_context, | |
| 102 PP_VideoProfile profile, | |
| 103 PP_Bool allow_software_fallback, | |
| 104 scoped_refptr<TrackedCallback> callback, | |
| 105 bool testing); | |
| 106 | |
| 107 // Unsolicited reply message handlers. | |
| 108 void OnPluginMsgRequestTextures(const ResourceMessageReplyParams& params, | |
| 109 uint32_t num_textures, | |
| 110 const PP_Size& size, | |
| 111 uint32_t texture_target); | |
| 112 void OnPluginMsgPictureReady(const ResourceMessageReplyParams& params, | |
| 113 uint32_t decode_id, | |
| 114 uint32_t texture_id); | |
| 115 void OnPluginMsgDismissPicture(const ResourceMessageReplyParams& params, | |
| 116 uint32_t texture_id); | |
| 117 void OnPluginMsgNotifyError(const ResourceMessageReplyParams& params, | |
| 118 int32_t error); | |
| 119 | |
| 120 // Reply message handlers for operations that are done in the host. | |
| 121 void OnPluginMsgInitializeComplete(const ResourceMessageReplyParams& params); | |
| 122 void OnPluginMsgGetShmComplete(const ResourceMessageReplyParams& params, | |
| 123 uint32_t size); | |
| 124 void OnPluginMsgDecodeComplete(const ResourceMessageReplyParams& params, | |
| 125 uint32_t shm_id); | |
| 126 void OnPluginMsgFlushComplete(const ResourceMessageReplyParams& params); | |
| 127 void OnPluginMsgResetComplete(const ResourceMessageReplyParams& params); | |
| 128 | |
| 129 int32_t TryDecode(uint32_t size, | |
| 130 const void* buffer, | |
| 131 scoped_refptr<TrackedCallback> callback); | |
| 132 void SendDecodeMessage(uint32_t shm_id); | |
| 133 void RunDecodeCallback(int32_t result); | |
| 134 | |
| 135 void DeleteGLTexture(uint32_t texture_id); | |
| 136 void WriteNextPicture(PP_VideoPicture* picture); | |
| 137 | |
| 138 // ScopedVector to own the shared memory buffers. | |
| 139 ScopedVector<ShmBuffer> shm_buffers_; | |
| 140 | |
| 141 // List of available shared memory buffers. | |
| 142 typedef std::vector<ShmBuffer*> ShmBufferList; | |
| 143 ShmBufferList available_shm_buffers_; | |
| 144 | |
| 145 // Map of GL texture id to texture info. | |
| 146 typedef base::hash_map<uint32_t, Texture> TextureMap; | |
| 147 TextureMap textures_; | |
| 148 | |
| 149 // Queue of received pictures. | |
| 150 typedef std::queue<Picture> PictureQueue; | |
| 151 PictureQueue received_pictures_; | |
| 152 | |
| 153 // Pending callbacks. | |
| 154 scoped_refptr<TrackedCallback> initialize_callback_; | |
| 155 scoped_refptr<TrackedCallback> decode_callback_; | |
| 156 scoped_refptr<TrackedCallback> get_picture_callback_; | |
| 157 scoped_refptr<TrackedCallback> flush_callback_; | |
| 158 scoped_refptr<TrackedCallback> reset_callback_; | |
| 159 | |
| 160 // The maximum delay (in Decode calls) before we receive a picture. If we | |
| 161 // haven't received a picture from a Decode call after this many successive | |
| 162 // calls to Decode, then we will never receive a picture from the call. | |
| 163 // Note that this isn't guaranteed by H264 or other codecs. In practice, this | |
| 164 // number is less than 16. We make it much larger since the cost of tracking | |
| 165 // this is low. | |
| 166 static const int kMaximumPictureLatency = 128; | |
|
dmichael (off chromium)
2014/05/20 22:40:38
nit: I'm used to Latency meaning time. Maybe there
bbudge
2014/05/22 18:34:55
Renamed to kMaximumPictureDelay. Unfortunately for
| |
| 167 // Counter modulo kMaximumPictureLatency to generate decode ids. | |
| 168 uint32_t next_decode_id_; | |
| 169 uint32_t decode_ids_[kMaximumPictureLatency]; | |
| 170 | |
| 171 // State for pending decode_callback_. | |
| 172 scoped_ptr<char[]> temp_buffer_; | |
|
dmichael (off chromium)
2014/05/20 22:40:38
scoped_ptr<uint8_t[]>?
bbudge
2014/05/22 18:34:55
Done.
| |
| 173 uint32_t decode_size_; | |
| 174 const void* decode_buffer_; | |
| 175 bool get_shm_buffer_pending_; | |
| 176 uint32_t pending_shm_id_; | |
| 177 // State for pending get_picture_callback_. | |
| 178 PP_VideoPicture* get_picture_; | |
| 179 | |
| 180 ScopedPPResource graphics3d_; | |
| 181 gpu::gles2::GLES2Implementation* gles2_impl_; | |
| 182 | |
| 183 bool initialized_; | |
| 184 bool testing_; | |
| 185 int32_t decoder_last_error_; | |
| 186 | |
| 187 DISALLOW_COPY_AND_ASSIGN(VideoDecoderResource); | |
| 188 }; | |
| 189 | |
| 190 } // namespace proxy | |
| 191 } // namespace ppapi | |
| 192 | |
| 193 #endif // PPAPI_PROXY_VIDEO_DECODER_RESOURCE_H_ | |
| OLD | NEW |