| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_DECODER_HOST_H_ | 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_DECODER_HOST_H_ |
| 6 #define CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_DECODER_HOST_H_ | 6 #define CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_DECODER_HOST_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
| 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 15 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 17 #include "gpu/command_buffer/common/mailbox.h" |
| 16 #include "media/video/video_decode_accelerator.h" | 18 #include "media/video/video_decode_accelerator.h" |
| 17 #include "ppapi/c/pp_codecs.h" | 19 #include "ppapi/c/pp_codecs.h" |
| 18 #include "ppapi/host/host_message_context.h" | 20 #include "ppapi/host/host_message_context.h" |
| 19 #include "ppapi/host/resource_host.h" | 21 #include "ppapi/host/resource_host.h" |
| 20 #include "ppapi/proxy/resource_message_params.h" | 22 #include "ppapi/proxy/resource_message_params.h" |
| 21 | 23 |
| 22 namespace base { | 24 namespace base { |
| 23 class SharedMemory; | 25 class SharedMemory; |
| 24 } | 26 } |
| 25 | 27 |
| 26 namespace content { | 28 namespace content { |
| 27 | 29 |
| 28 class PPB_Graphics3D_Impl; | 30 class PPB_Graphics3D_Impl; |
| 29 class RendererPpapiHost; | 31 class RendererPpapiHost; |
| 30 class RenderViewImpl; | 32 class RenderViewImpl; |
| 31 class VideoDecoderShim; | |
| 32 | 33 |
| 33 class CONTENT_EXPORT PepperVideoDecoderHost | 34 class CONTENT_EXPORT PepperVideoDecoderHost |
| 34 : public ppapi::host::ResourceHost, | 35 : public ppapi::host::ResourceHost, |
| 35 public media::VideoDecodeAccelerator::Client { | 36 public media::VideoDecodeAccelerator::Client { |
| 36 public: | 37 public: |
| 37 PepperVideoDecoderHost(RendererPpapiHost* host, | 38 PepperVideoDecoderHost(RendererPpapiHost* host, |
| 38 PP_Instance instance, | 39 PP_Instance instance, |
| 39 PP_Resource resource); | 40 PP_Resource resource); |
| 40 virtual ~PepperVideoDecoderHost(); | 41 virtual ~PepperVideoDecoderHost(); |
| 41 | 42 |
| 42 private: | 43 private: |
| 43 struct PendingDecode { | 44 struct PendingDecode { |
| 44 PendingDecode(uint32_t shm_id, | 45 PendingDecode(uint32_t shm_id, |
| 45 const ppapi::host::ReplyMessageContext& reply_context); | 46 const ppapi::host::ReplyMessageContext& reply_context); |
| 46 ~PendingDecode(); | 47 ~PendingDecode(); |
| 47 | 48 |
| 48 const uint32_t shm_id; | 49 const uint32_t shm_id; |
| 49 const ppapi::host::ReplyMessageContext reply_context; | 50 const ppapi::host::ReplyMessageContext reply_context; |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 friend class VideoDecoderShim; | |
| 53 | |
| 54 // ResourceHost implementation. | 53 // ResourceHost implementation. |
| 55 virtual int32_t OnResourceMessageReceived( | 54 virtual int32_t OnResourceMessageReceived( |
| 56 const IPC::Message& msg, | 55 const IPC::Message& msg, |
| 57 ppapi::host::HostMessageContext* context) OVERRIDE; | 56 ppapi::host::HostMessageContext* context) OVERRIDE; |
| 58 | 57 |
| 59 // media::VideoDecodeAccelerator::Client implementation. | 58 // media::VideoDecodeAccelerator::Client implementation. |
| 60 virtual void ProvidePictureBuffers(uint32 requested_num_of_buffers, | 59 virtual void ProvidePictureBuffers(uint32 requested_num_of_buffers, |
| 61 const gfx::Size& dimensions, | 60 const gfx::Size& dimensions, |
| 62 uint32 texture_target) OVERRIDE; | 61 uint32 texture_target) OVERRIDE; |
| 63 virtual void DismissPictureBuffer(int32 picture_buffer_id) OVERRIDE; | 62 virtual void DismissPictureBuffer(int32 picture_buffer_id) OVERRIDE; |
| 64 virtual void PictureReady(const media::Picture& picture) OVERRIDE; | 63 virtual void PictureReady(const media::Picture& picture) OVERRIDE; |
| 64 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE; |
| 65 virtual void NotifyFlushDone() OVERRIDE; |
| 65 virtual void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id) OVERRIDE; | 66 virtual void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id) OVERRIDE; |
| 66 virtual void NotifyFlushDone() OVERRIDE; | |
| 67 virtual void NotifyResetDone() OVERRIDE; | 67 virtual void NotifyResetDone() OVERRIDE; |
| 68 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE; | |
| 69 | 68 |
| 70 int32_t OnHostMsgInitialize(ppapi::host::HostMessageContext* context, | 69 int32_t OnHostMsgInitialize(ppapi::host::HostMessageContext* context, |
| 71 const ppapi::HostResource& graphics_context, | 70 const ppapi::HostResource& graphics_context, |
| 72 PP_VideoProfile profile, | 71 PP_VideoProfile profile, |
| 73 bool allow_software_fallback); | 72 bool allow_software_fallback); |
| 74 int32_t OnHostMsgGetShm(ppapi::host::HostMessageContext* context, | 73 int32_t OnHostMsgGetShm(ppapi::host::HostMessageContext* context, |
| 75 uint32_t shm_id, | 74 uint32_t shm_id, |
| 76 uint32_t shm_size); | 75 uint32_t shm_size); |
| 77 int32_t OnHostMsgDecode(ppapi::host::HostMessageContext* context, | 76 int32_t OnHostMsgDecode(ppapi::host::HostMessageContext* context, |
| 78 uint32_t shm_id, | 77 uint32_t shm_id, |
| 79 uint32_t size, | 78 uint32_t size, |
| 80 int32_t decode_id); | 79 int32_t decode_id); |
| 81 int32_t OnHostMsgAssignTextures(ppapi::host::HostMessageContext* context, | 80 int32_t OnHostMsgAssignTextures(ppapi::host::HostMessageContext* context, |
| 82 const PP_Size& size, | 81 const PP_Size& size, |
| 83 const std::vector<uint32_t>& texture_ids); | 82 const std::vector<uint32_t>& texture_ids); |
| 84 int32_t OnHostMsgRecyclePicture(ppapi::host::HostMessageContext* context, | 83 int32_t OnHostMsgRecyclePicture(ppapi::host::HostMessageContext* context, |
| 85 uint32_t picture_id); | 84 uint32_t picture_id); |
| 86 int32_t OnHostMsgFlush(ppapi::host::HostMessageContext* context); | 85 int32_t OnHostMsgFlush(ppapi::host::HostMessageContext* context); |
| 87 int32_t OnHostMsgReset(ppapi::host::HostMessageContext* context); | 86 int32_t OnHostMsgReset(ppapi::host::HostMessageContext* context); |
| 88 | 87 |
| 89 // These methods are needed by VideoDecodeShim, to look like a | |
| 90 // VideoDecodeAccelerator. | |
| 91 void OnInitializeComplete(int32_t result); | |
| 92 const uint8_t* DecodeIdToAddress(uint32_t decode_id); | |
| 93 void RequestTextures(uint32 requested_num_of_buffers, | |
| 94 const gfx::Size& dimensions, | |
| 95 uint32 texture_target, | |
| 96 const std::vector<gpu::Mailbox>& mailboxes); | |
| 97 | |
| 98 // Non-owning pointer. | 88 // Non-owning pointer. |
| 99 RendererPpapiHost* renderer_ppapi_host_; | 89 RendererPpapiHost* renderer_ppapi_host_; |
| 100 | 90 |
| 101 scoped_ptr<media::VideoDecodeAccelerator> decoder_; | 91 scoped_ptr<media::VideoDecodeAccelerator> decoder_; |
| 92 scoped_refptr<PPB_Graphics3D_Impl> graphics3d_; |
| 102 | 93 |
| 103 // A vector holding our shm buffers, in sync with a similar vector in the | 94 // A vector holding our shm buffers, in sync with a similar vector in the |
| 104 // resource. We use a buffer's index in these vectors as its id on both sides | 95 // resource. We use a buffer's index in these vectors as its id on both sides |
| 105 // of the proxy. Only add buffers or update them in place so as not to | 96 // of the proxy. Only add buffers or update them in place so as not to |
| 106 // invalidate these ids. | 97 // invalidate these ids. |
| 107 ScopedVector<base::SharedMemory> shm_buffers_; | 98 ScopedVector<base::SharedMemory> shm_buffers_; |
| 108 // A vector of true/false indicating if a shm buffer is in use by the decoder. | 99 // A vector of true/false indicating if a shm buffer is in use by the decoder. |
| 109 // This is parallel to |shm_buffers_|. | 100 // This is parallel to |shm_buffers_|. |
| 110 std::vector<uint8_t> shm_buffer_busy_; | 101 std::vector<uint8_t> shm_buffer_busy_; |
| 111 | 102 |
| 112 // Maps decode uid to PendingDecode info. | 103 // Maps decode uid to PendingDecode info. |
| 113 typedef base::hash_map<int32_t, PendingDecode> PendingDecodeMap; | 104 typedef base::hash_map<int32_t, PendingDecode> PendingDecodeMap; |
| 114 PendingDecodeMap pending_decodes_; | 105 PendingDecodeMap pending_decodes_; |
| 115 | 106 |
| 116 ppapi::host::ReplyMessageContext flush_reply_context_; | 107 ppapi::host::ReplyMessageContext flush_reply_context_; |
| 117 ppapi::host::ReplyMessageContext reset_reply_context_; | 108 ppapi::host::ReplyMessageContext reset_reply_context_; |
| 118 // Only used when in software fallback mode. | |
| 119 ppapi::host::ReplyMessageContext initialize_reply_context_; | |
| 120 | 109 |
| 121 bool initialized_; | 110 bool initialized_; |
| 122 | 111 |
| 123 DISALLOW_COPY_AND_ASSIGN(PepperVideoDecoderHost); | 112 DISALLOW_COPY_AND_ASSIGN(PepperVideoDecoderHost); |
| 124 }; | 113 }; |
| 125 | 114 |
| 126 } // namespace content | 115 } // namespace content |
| 127 | 116 |
| 128 #endif // CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_DECODER_HOST_H_ | 117 #endif // CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_DECODER_HOST_H_ |
| OLD | NEW |