[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / content / renderer / pepper / pepper_video_decoder_host.h
blob7a200838f3dcdd824389c1f53ef37f1717fda5a3
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.
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_DECODER_HOST_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_DECODER_HOST_H_
8 #include <map>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/containers/hash_tables.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
15 #include "content/common/content_export.h"
16 #include "media/video/video_decode_accelerator.h"
17 #include "ppapi/c/pp_codecs.h"
18 #include "ppapi/host/host_message_context.h"
19 #include "ppapi/host/resource_host.h"
20 #include "ppapi/proxy/resource_message_params.h"
22 namespace base {
23 class SharedMemory;
26 namespace content {
28 class PPB_Graphics3D_Impl;
29 class RendererPpapiHost;
30 class RenderViewImpl;
31 class VideoDecoderShim;
33 class CONTENT_EXPORT PepperVideoDecoderHost
34 : public ppapi::host::ResourceHost,
35 public media::VideoDecodeAccelerator::Client {
36 public:
37 PepperVideoDecoderHost(RendererPpapiHost* host,
38 PP_Instance instance,
39 PP_Resource resource);
40 ~PepperVideoDecoderHost() override;
42 private:
43 struct PendingDecode {
44 PendingDecode(uint32_t shm_id,
45 const ppapi::host::ReplyMessageContext& reply_context);
46 ~PendingDecode();
48 const uint32_t shm_id;
49 const ppapi::host::ReplyMessageContext reply_context;
52 friend class VideoDecoderShim;
54 // ResourceHost implementation.
55 int32_t OnResourceMessageReceived(
56 const IPC::Message& msg,
57 ppapi::host::HostMessageContext* context) override;
59 // media::VideoDecodeAccelerator::Client implementation.
60 void ProvidePictureBuffers(uint32 requested_num_of_buffers,
61 const gfx::Size& dimensions,
62 uint32 texture_target) override;
63 void DismissPictureBuffer(int32 picture_buffer_id) override;
64 void PictureReady(const media::Picture& picture) override;
65 void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id) override;
66 void NotifyFlushDone() override;
67 void NotifyResetDone() override;
68 void NotifyError(media::VideoDecodeAccelerator::Error error) override;
70 int32_t OnHostMsgInitialize(ppapi::host::HostMessageContext* context,
71 const ppapi::HostResource& graphics_context,
72 PP_VideoProfile profile,
73 PP_HardwareAcceleration acceleration,
74 uint32_t min_picture_count);
75 int32_t OnHostMsgGetShm(ppapi::host::HostMessageContext* context,
76 uint32_t shm_id,
77 uint32_t shm_size);
78 int32_t OnHostMsgDecode(ppapi::host::HostMessageContext* context,
79 uint32_t shm_id,
80 uint32_t size,
81 int32_t decode_id);
82 int32_t OnHostMsgAssignTextures(ppapi::host::HostMessageContext* context,
83 const PP_Size& size,
84 const std::vector<uint32_t>& texture_ids);
85 int32_t OnHostMsgRecyclePicture(ppapi::host::HostMessageContext* context,
86 uint32_t picture_id);
87 int32_t OnHostMsgFlush(ppapi::host::HostMessageContext* context);
88 int32_t OnHostMsgReset(ppapi::host::HostMessageContext* context);
90 // These methods are needed by VideoDecodeShim, to look like a
91 // VideoDecodeAccelerator.
92 void OnInitializeComplete(int32_t result);
93 const uint8_t* DecodeIdToAddress(uint32_t decode_id);
94 void RequestTextures(uint32 requested_num_of_buffers,
95 const gfx::Size& dimensions,
96 uint32 texture_target,
97 const std::vector<gpu::Mailbox>& mailboxes);
99 // Non-owning pointer.
100 RendererPpapiHost* renderer_ppapi_host_;
102 scoped_ptr<media::VideoDecodeAccelerator> decoder_;
104 // A vector holding our shm buffers, in sync with a similar vector in the
105 // resource. We use a buffer's index in these vectors as its id on both sides
106 // of the proxy. Only add buffers or update them in place so as not to
107 // invalidate these ids.
108 ScopedVector<base::SharedMemory> shm_buffers_;
109 // A vector of true/false indicating if a shm buffer is in use by the decoder.
110 // This is parallel to |shm_buffers_|.
111 std::vector<uint8_t> shm_buffer_busy_;
113 uint32_t min_picture_count_;
114 typedef std::set<uint32_t> TextureSet;
115 TextureSet pictures_in_use_;
116 TextureSet dismissed_pictures_in_use_;
118 // Maps decode uid to PendingDecode info.
119 typedef base::hash_map<int32_t, PendingDecode> PendingDecodeMap;
120 PendingDecodeMap pending_decodes_;
122 ppapi::host::ReplyMessageContext flush_reply_context_;
123 ppapi::host::ReplyMessageContext reset_reply_context_;
124 // Only used when in software fallback mode.
125 ppapi::host::ReplyMessageContext initialize_reply_context_;
127 bool initialized_;
129 DISALLOW_COPY_AND_ASSIGN(PepperVideoDecoderHost);
132 } // namespace content
134 #endif // CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_DECODER_HOST_H_