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(uint32_t id, scoped_ptr<base::SharedMemory> shm); | |
45 ~ShmBuffer(); | |
46 | |
47 // Index of the buffer in the ScopedVector. Buffers have the same id in | |
48 // the plugin and the host. | |
49 uint32_t id; | |
50 scoped_ptr<base::SharedMemory> shm; | |
51 }; | |
52 | |
53 struct BitstreamBuffer { | |
54 BitstreamBuffer(uint32_t id, uint32_t size, bool key_frame); | |
55 ~BitstreamBuffer(); | |
56 | |
57 // Index of the buffer in the ScopedVector. Same as ShmBuffer::id. | |
58 uint32_t id; | |
59 uint32_t size; | |
60 bool key_frame; | |
61 }; | |
62 | |
30 // PPB_VideoEncoder_API implementation. | 63 // PPB_VideoEncoder_API implementation. |
31 int32_t GetSupportedProfiles( | 64 int32_t GetSupportedProfiles( |
32 const PP_ArrayOutput& output, | 65 const PP_ArrayOutput& output, |
33 const scoped_refptr<TrackedCallback>& callback) override; | 66 const scoped_refptr<TrackedCallback>& callback) override; |
34 int32_t Initialize(PP_VideoFrame_Format input_format, | 67 int32_t Initialize(PP_VideoFrame_Format input_format, |
35 const PP_Size* input_visible_size, | 68 const PP_Size* input_visible_size, |
36 PP_VideoProfile output_profile, | 69 PP_VideoProfile output_profile, |
37 uint32_t initial_bitrate, | 70 uint32_t initial_bitrate, |
38 PP_HardwareAcceleration acceleration, | 71 PP_HardwareAcceleration acceleration, |
39 const scoped_refptr<TrackedCallback>& callback) override; | 72 const scoped_refptr<TrackedCallback>& callback) override; |
40 int32_t GetFramesRequired() override; | 73 int32_t GetFramesRequired() override; |
41 int32_t GetFrameCodedSize(PP_Size* size) override; | 74 int32_t GetFrameCodedSize(PP_Size* size) override; |
42 int32_t GetVideoFrame( | 75 int32_t GetVideoFrame( |
43 PP_Resource* video_frame, | 76 PP_Resource* video_frame, |
44 const scoped_refptr<TrackedCallback>& callback) override; | 77 const scoped_refptr<TrackedCallback>& callback) override; |
45 int32_t Encode(PP_Resource video_frame, | 78 int32_t Encode(PP_Resource video_frame, |
46 PP_Bool force_keyframe, | 79 PP_Bool force_keyframe, |
47 const scoped_refptr<TrackedCallback>& callback) override; | 80 const scoped_refptr<TrackedCallback>& callback) override; |
48 int32_t GetBitstreamBuffer( | 81 int32_t GetBitstreamBuffer( |
49 PP_BitstreamBuffer* picture, | 82 PP_BitstreamBuffer* picture, |
50 const scoped_refptr<TrackedCallback>& callback) override; | 83 const scoped_refptr<TrackedCallback>& callback) override; |
51 void RecycleBitstreamBuffer(const PP_BitstreamBuffer* picture) override; | 84 void RecycleBitstreamBuffer(const PP_BitstreamBuffer* picture) override; |
52 void RequestEncodingParametersChange(uint32_t bitrate, | 85 void RequestEncodingParametersChange(uint32_t bitrate, |
53 uint32_t framerate) override; | 86 uint32_t framerate) override; |
54 void Close() override; | 87 void Close() override; |
55 | 88 |
89 // PluginResource implementation. | |
90 void OnReplyReceived(const ResourceMessageReplyParams& params, | |
91 const IPC::Message& msg) override; | |
92 | |
93 // Reply message handlers for operations that are done in the host. | |
94 void OnPluginMsgGetSupportedProfilesReply( | |
95 const PP_ArrayOutput& output, | |
96 const ResourceMessageReplyParams& params, | |
97 const std::vector<PP_VideoProfileDescription>& profiles); | |
98 void OnPluginMsgInitializeReply(const ResourceMessageReplyParams& params, | |
99 uint32_t input_frame_count, | |
100 const PP_Size& input_coded_size); | |
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 void OnPluginMsgBitstreamBufferReady(const ResourceMessageReplyParams& params, | |
112 uint32_t buffer_id, | |
113 uint32_t buffer_size, | |
114 bool key_frame); | |
115 void OnPluginMsgNotifyError(const ResourceMessageReplyParams& params, | |
116 int32_t error); | |
117 | |
118 // Internal utility functions. | |
119 void NotifyError(int32_t error); | |
120 void TryWriteVideoFrame(); | |
121 void WriteBitstreamBuffer(const BitstreamBuffer& buffer); | |
122 void ReleaseFrames(); | |
123 | |
124 bool initialized_; | |
125 bool closed_; | |
126 int32_t encoder_last_error_; | |
bbudge
2015/02/18 22:53:01
Need a comment similar to the one in the host abou
| |
127 | |
128 int32_t input_frame_count_; | |
129 PP_Size input_coded_size_; | |
130 | |
131 | |
132 MediaStreamBufferManager buffer_manager_; | |
133 | |
134 typedef std::map<PP_Resource, scoped_refptr<VideoFrameResource> > | |
135 VideoFrameMap; | |
136 VideoFrameMap video_frames_; | |
137 | |
138 ScopedVector<ShmBuffer> shm_buffers_; | |
139 | |
140 std::deque<BitstreamBuffer> available_bitstream_buffers_; | |
141 typedef std::map<void*, uint32_t> BitstreamBufferMap; | |
142 BitstreamBufferMap bitstream_buffer_map_; | |
143 | |
144 scoped_refptr<TrackedCallback> get_supported_profiles_callback_; | |
145 scoped_refptr<TrackedCallback> initialize_callback_; | |
146 scoped_refptr<TrackedCallback> get_video_frame_callback_; | |
147 PP_Resource* get_video_frame_data_; | |
148 std::deque<scoped_refptr<TrackedCallback> > encode_callbacks_; | |
149 scoped_refptr<TrackedCallback> get_bitstream_buffer_callback_; | |
150 PP_BitstreamBuffer* get_bitstream_buffer_data_; | |
151 | |
56 DISALLOW_COPY_AND_ASSIGN(VideoEncoderResource); | 152 DISALLOW_COPY_AND_ASSIGN(VideoEncoderResource); |
57 }; | 153 }; |
58 | 154 |
59 } // namespace proxy | 155 } // namespace proxy |
60 } // namespace ppapi | 156 } // namespace ppapi |
61 | 157 |
62 #endif // PPAPI_PROXY_VIDEO_ENCODER_RESOURCE_H_ | 158 #endif // PPAPI_PROXY_VIDEO_ENCODER_RESOURCE_H_ |
OLD | NEW |