OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2015 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 CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_ENCODER_HOST_H_ | |
6 #define CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_ENCODER_HOST_H_ | |
7 | |
8 #include "base/memory/ref_counted.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/memory/scoped_vector.h" | |
11 #include "content/common/content_export.h" | |
12 #include "gpu/command_buffer/common/mailbox_holder.h" | |
13 #include "media/video/video_encode_accelerator.h" | |
14 #include "ppapi/c/pp_codecs.h" | |
15 #include "ppapi/c/ppb_video_frame.h" | |
16 #include "ppapi/host/host_message_context.h" | |
17 #include "ppapi/host/resource_host.h" | |
18 #include "ppapi/proxy/resource_message_params.h" | |
19 #include "ppapi/shared_impl/media_stream_buffer_manager.h" | |
20 | |
21 namespace media { | |
22 class GpuVideoAcceleratorFactories; | |
23 } | |
24 | |
25 namespace content { | |
26 | |
27 class CommandBufferProxyImpl; | |
28 class GpuChannelHost; | |
29 class RendererPpapiHost; | |
30 class RenderViewImpl; | |
31 | |
32 class CONTENT_EXPORT PepperVideoEncoderHost | |
33 : public ppapi::host::ResourceHost, | |
34 public media::VideoEncodeAccelerator::Client { | |
35 public: | |
36 PepperVideoEncoderHost(RendererPpapiHost* host, | |
37 PP_Instance instance, | |
38 PP_Resource resource); | |
39 ~PepperVideoEncoderHost() override; | |
40 | |
41 private: | |
42 // media::VideoEncodeAccelerator implementation. | |
43 virtual void RequireBitstreamBuffers(unsigned int input_count, | |
44 const gfx::Size& input_coded_size, | |
45 size_t output_buffer_size) override; | |
46 virtual void BitstreamBufferReady(int32 bitstream_buffer_id, | |
47 size_t payload_size, | |
48 bool key_frame) override; | |
49 virtual void NotifyError(media::VideoEncodeAccelerator::Error error) override; | |
50 | |
51 // ResourceHost implementation. | |
52 virtual int32_t OnResourceMessageReceived( | |
53 const IPC::Message& msg, | |
54 ppapi::host::HostMessageContext* context) override; | |
55 | |
56 // Plugin's IPC calls. | |
57 int32_t OnHostMsgGetSupportedProfiles( | |
58 ppapi::host::HostMessageContext* context); | |
59 int32_t OnHostMsgInitialize(ppapi::host::HostMessageContext* context, | |
60 PP_VideoFrame_Format input_format, | |
61 const PP_Size& input_visible_size, | |
62 PP_VideoProfile output_profile, | |
63 uint32_t initial_bitrate, | |
64 PP_HardwareAcceleration acceleration); | |
65 int32_t OnHostMsgGetVideoFrames(ppapi::host::HostMessageContext* context); | |
66 int32_t OnHostMsgEncode(ppapi::host::HostMessageContext* context, | |
67 uint32_t frame_id, | |
68 bool force_keyframe); | |
69 int32_t OnHostMsgRecycleBitstreamBuffer( | |
70 ppapi::host::HostMessageContext* context, | |
71 uint32_t buffer_id); | |
72 int32_t OnHostMsgRequestEncodingParametersChange( | |
73 ppapi::host::HostMessageContext* context, | |
74 uint32_t bitrate, | |
75 uint32_t framerate); | |
76 int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context); | |
77 | |
78 // Internal methods. | |
79 // void* BufferIdToAddress(int32_t buffer_id); | |
80 scoped_refptr<media::VideoFrame> CreateVideoFrame( | |
81 uint32_t frame_id, | |
82 const ppapi::host::ReplyMessageContext& reply_context); | |
83 void EncodeVideoFrameDone( | |
84 const ppapi::host::ReplyMessageContext& reply_context, | |
85 uint32_t frame_id); | |
86 void NotifyPepperError(int32_t error); | |
87 | |
88 // Non-owning pointer. | |
89 RendererPpapiHost* renderer_ppapi_host_; | |
90 | |
91 ppapi::host::ReplyMessageContext initialize_reply_context_; | |
92 | |
93 // Shared memory buffers. | |
94 class ShmBuffer { | |
95 public: | |
96 ShmBuffer(int32_t id, scoped_ptr<base::SharedMemory> memory, size_t size); | |
97 ~ShmBuffer(); | |
98 | |
99 media::BitstreamBuffer toBitstreamBuffer(); | |
100 | |
101 int32_t id; | |
102 scoped_ptr<base::SharedMemory> shm; | |
103 bool in_use; | |
104 }; | |
105 | |
106 // Bitstream buffers. | |
107 ScopedVector<ShmBuffer> buffers_; | |
108 size_t buffer_count_hint_; | |
109 | |
110 // Video frames. | |
111 scoped_ptr<ppapi::MediaStreamBufferManager::Delegate> | |
112 buffer_manager_delegate_; | |
bbudge
2015/02/10 01:31:07
Why not make the host implement the Delegate inter
llandwerlin-old
2015/02/10 14:28:12
Done.
| |
113 scoped_ptr<ppapi::MediaStreamBufferManager> buffer_manager_; | |
bbudge
2015/02/10 01:31:07
Since this is owned by the host and not shared, yo
llandwerlin-old
2015/02/10 14:28:12
Done.
| |
114 | |
115 scoped_ptr<media::VideoEncodeAccelerator> encoder_; | |
116 | |
117 // Global state | |
118 bool initialized_; | |
119 int32_t encoder_last_error_; | |
120 gfx::Size input_coded_size_; | |
121 int32_t frame_count_; | |
122 media::VideoFrame::Format media_format_; | |
123 | |
124 scoped_refptr<GpuChannelHost> channel_; | |
125 CommandBufferProxyImpl* command_buffer_; | |
126 | |
127 base::WeakPtrFactory<PepperVideoEncoderHost> weak_ptr_factory_; | |
128 | |
129 DISALLOW_COPY_AND_ASSIGN(PepperVideoEncoderHost); | |
130 }; | |
131 | |
132 } // namespace content | |
133 | |
134 #endif // CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_ENCODER_HOST_H_ | |
OLD | NEW |