OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 PPAPI_PROXY_VIDEO_ENCODER_RESOURCE_H_ | 5 #ifndef PPAPI_PROXY_VIDEO_ENCODER_RESOURCE_H_ |
6 #define PPAPI_PROXY_VIDEO_ENCODER_RESOURCE_H_ | 6 #define PPAPI_PROXY_VIDEO_ENCODER_RESOURCE_H_ |
7 | 7 |
8 #include <deque> | |
9 | |
8 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/memory/scoped_vector.h" | |
9 #include "ppapi/proxy/connection.h" | 13 #include "ppapi/proxy/connection.h" |
10 #include "ppapi/proxy/plugin_resource.h" | 14 #include "ppapi/proxy/plugin_resource.h" |
15 #include "ppapi/shared_impl/media_stream_buffer_manager.h" | |
11 #include "ppapi/shared_impl/resource.h" | 16 #include "ppapi/shared_impl/resource.h" |
12 #include "ppapi/thunk/ppb_video_encoder_api.h" | 17 #include "ppapi/thunk/ppb_video_encoder_api.h" |
13 | 18 |
19 namespace base { | |
20 class SharedMemory; | |
21 } | |
22 | |
14 namespace ppapi { | 23 namespace ppapi { |
15 | 24 |
16 class TrackedCallback; | 25 class TrackedCallback; |
17 | 26 |
18 namespace proxy { | 27 namespace proxy { |
19 | 28 |
29 class SerializedHandle; | |
30 class VideoFrameResource; | |
31 | |
20 class PPAPI_PROXY_EXPORT VideoEncoderResource | 32 class PPAPI_PROXY_EXPORT VideoEncoderResource |
21 : public PluginResource, | 33 : public PluginResource, |
22 public thunk::PPB_VideoEncoder_API { | 34 public thunk::PPB_VideoEncoder_API, |
35 public ppapi::MediaStreamBufferManager::Delegate { | |
23 public: | 36 public: |
24 VideoEncoderResource(Connection connection, PP_Instance instance); | 37 VideoEncoderResource(Connection connection, PP_Instance instance); |
25 ~VideoEncoderResource() override; | 38 ~VideoEncoderResource() override; |
26 | 39 |
27 thunk::PPB_VideoEncoder_API* AsPPB_VideoEncoder_API() override; | 40 thunk::PPB_VideoEncoder_API* AsPPB_VideoEncoder_API() override; |
28 | 41 |
29 private: | 42 private: |
43 struct ShmBuffer { | |
44 ShmBuffer(base::SharedMemoryHandle handle, uint32_t id, uint32_t size); | |
45 ~ShmBuffer(); | |
46 | |
47 scoped_ptr<base::SharedMemory> shm; | |
48 // Index of the buffer in the ScopedVector. Buffers have the id in | |
bbudge
2015/02/12 22:22:10
s/id/same id/
llandwerlin-old
2015/02/13 20:12:26
Done.
| |
49 // the plugin and the host. | |
50 uint32_t id; | |
51 uint32_t size; | |
52 }; | |
53 | |
54 struct BitstreamBuffer { | |
55 BitstreamBuffer(uint32_t id, uint32_t size, bool key_frame); | |
56 BitstreamBuffer(const BitstreamBuffer& other); | |
57 ~BitstreamBuffer(); | |
58 | |
59 // Index of the buffer in the ScopedVector. Same as ShmBuffer::id. | |
60 uint32_t id; | |
61 uint32_t size; | |
62 bool key_frame; | |
63 }; | |
64 | |
30 // PPB_VideoEncoder_API implementation. | 65 // PPB_VideoEncoder_API implementation. |
31 int32_t GetSupportedProfiles( | 66 int32_t GetSupportedProfiles( |
32 const PP_ArrayOutput& output, | 67 const PP_ArrayOutput& output, |
33 const scoped_refptr<TrackedCallback>& callback) override; | 68 const scoped_refptr<TrackedCallback>& callback) override; |
34 int32_t Initialize(PP_VideoFrame_Format input_format, | 69 int32_t Initialize(PP_VideoFrame_Format input_format, |
35 const PP_Size* input_visible_size, | 70 const PP_Size* input_visible_size, |
36 PP_VideoProfile output_profile, | 71 PP_VideoProfile output_profile, |
37 uint32_t initial_bitrate, | 72 uint32_t initial_bitrate, |
38 PP_HardwareAcceleration acceleration, | 73 PP_HardwareAcceleration acceleration, |
39 const scoped_refptr<TrackedCallback>& callback) override; | 74 const scoped_refptr<TrackedCallback>& callback) override; |
40 int32_t GetFramesRequired() override; | 75 int32_t GetFramesRequired() override; |
41 int32_t GetFrameCodedSize(PP_Size* size) override; | 76 int32_t GetFrameCodedSize(PP_Size* size) override; |
42 int32_t GetVideoFrame( | 77 int32_t GetVideoFrame( |
43 PP_Resource* video_frame, | 78 PP_Resource* video_frame, |
44 const scoped_refptr<TrackedCallback>& callback) override; | 79 const scoped_refptr<TrackedCallback>& callback) override; |
45 int32_t Encode(PP_Resource video_frame, | 80 int32_t Encode(PP_Resource video_frame, |
46 PP_Bool force_keyframe, | 81 PP_Bool force_keyframe, |
47 const scoped_refptr<TrackedCallback>& callback) override; | 82 const scoped_refptr<TrackedCallback>& callback) override; |
48 int32_t GetBitstreamBuffer( | 83 int32_t GetBitstreamBuffer( |
49 PP_BitstreamBuffer* picture, | 84 PP_BitstreamBuffer* picture, |
50 const scoped_refptr<TrackedCallback>& callback) override; | 85 const scoped_refptr<TrackedCallback>& callback) override; |
51 void RecycleBitstreamBuffer(const PP_BitstreamBuffer* picture) override; | 86 void RecycleBitstreamBuffer(const PP_BitstreamBuffer* picture) override; |
52 void RequestEncodingParametersChange(uint32_t bitrate, | 87 void RequestEncodingParametersChange(uint32_t bitrate, |
53 uint32_t framerate) override; | 88 uint32_t framerate) override; |
54 void Close() override; | 89 void Close() override; |
55 | 90 |
91 // PluginResource implementation. | |
92 void OnReplyReceived(const ResourceMessageReplyParams& params, | |
93 const IPC::Message& msg) override; | |
94 | |
95 // Reply message handlers for operations that are done in the host. | |
96 void OnPluginMsgGetSupportedProfilesReply( | |
97 const PP_ArrayOutput& output, | |
98 const ResourceMessageReplyParams& params, | |
99 const std::vector<PP_VideoProfileDescription>& profiles); | |
100 void OnPluginMsgInitializeReply(const ResourceMessageReplyParams& params); | |
101 void OnPluginMsgGetVideoFramesReply(const ResourceMessageReplyParams& params, | |
102 uint32_t frame_count, | |
103 uint32_t frame_length, | |
104 const PP_Size& frame_size); | |
105 void OnPluginMsgEncodeReply(const ResourceMessageReplyParams& params, | |
106 uint32_t frame_id); | |
107 | |
108 // Unsolicited reply message handlers. | |
109 void OnPluginMsgBitstreamBuffers(const ResourceMessageReplyParams& params, | |
110 uint32_t buffer_length, | |
111 uint32_t input_frame_count, | |
112 const PP_Size& input_coded_size); | |
113 void OnPluginMsgBitstreamBufferReady(const ResourceMessageReplyParams& params, | |
114 uint32_t buffer_id, | |
115 uint32_t buffer_size, | |
116 bool key_frame); | |
117 void OnPluginMsgNotifyError(const ResourceMessageReplyParams& params, | |
118 int32_t error); | |
119 | |
120 // Internal utility functions. | |
121 void NotifyError(int32_t error); | |
122 bool WriteVideoFrame(PP_Resource* output); | |
123 void NotifyGetVideoFrameCallbacksError(int32_t error); | |
124 void WriteBitstreamBuffer(PP_BitstreamBuffer* bitstream_buffer, | |
125 const BitstreamBuffer& buffer); | |
126 void ReleaseFrames(); | |
127 | |
128 bool initialized_; | |
129 bool closed_; | |
130 int32_t encoder_last_error_; | |
131 | |
132 int32_t input_frame_count_; | |
133 PP_Size input_coded_size_; | |
134 | |
135 | |
136 MediaStreamBufferManager buffer_manager_; | |
137 | |
138 typedef std::map<PP_Resource, scoped_refptr<VideoFrameResource> > | |
139 VideoFrameMap; | |
140 VideoFrameMap video_frames_; | |
141 | |
142 ScopedVector<ShmBuffer> shm_buffers_; | |
143 | |
144 std::deque<BitstreamBuffer> available_bitstream_buffers_; | |
145 typedef std::map<void*, uint32_t> BitstreamBufferMap; | |
146 BitstreamBufferMap bitstream_buffer_map_; | |
147 | |
148 scoped_refptr<TrackedCallback> get_supported_profiles_callback_; | |
149 scoped_refptr<TrackedCallback> initialize_callback_; | |
150 scoped_refptr<TrackedCallback> get_video_frame_callback_; | |
151 PP_Resource* get_video_frame_data_; | |
152 std::deque<scoped_refptr<TrackedCallback> > encode_callbacks_; | |
153 scoped_refptr<TrackedCallback> get_bitstream_buffer_callback_; | |
154 PP_BitstreamBuffer* get_bitstream_buffer_data_; | |
155 | |
56 DISALLOW_COPY_AND_ASSIGN(VideoEncoderResource); | 156 DISALLOW_COPY_AND_ASSIGN(VideoEncoderResource); |
57 }; | 157 }; |
58 | 158 |
59 } // namespace proxy | 159 } // namespace proxy |
60 } // namespace ppapi | 160 } // namespace ppapi |
61 | 161 |
62 #endif // PPAPI_PROXY_VIDEO_ENCODER_RESOURCE_H_ | 162 #endif // PPAPI_PROXY_VIDEO_ENCODER_RESOURCE_H_ |
OLD | NEW |