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 { |
23 public: | 35 public: |
24 VideoEncoderResource(Connection connection, PP_Instance instance); | 36 VideoEncoderResource(Connection connection, PP_Instance instance); |
25 ~VideoEncoderResource() override; | 37 ~VideoEncoderResource() override; |
26 | 38 |
27 thunk::PPB_VideoEncoder_API* AsPPB_VideoEncoder_API() override; | 39 thunk::PPB_VideoEncoder_API* AsPPB_VideoEncoder_API() override; |
28 | 40 |
29 private: | 41 private: |
42 struct ShmBuffer { | |
43 ShmBuffer(base::SharedMemoryHandle handle, uint32_t id, uint32_t size); | |
44 ~ShmBuffer(); | |
45 | |
46 scoped_ptr<base::SharedMemory> shm; | |
47 uint32_t id; | |
bbudge
2015/02/10 01:31:08
There should be a comment somewhere that this is t
llandwerlin-old
2015/02/10 14:28:13
Done.
| |
48 uint32_t size; | |
49 }; | |
50 | |
51 struct BitstreamBuffer { | |
52 BitstreamBuffer(uint32_t id, uint32_t size, bool key_frame); | |
53 BitstreamBuffer(const BitstreamBuffer& other); | |
54 ~BitstreamBuffer(); | |
55 | |
56 uint32_t id; | |
bbudge
2015/02/10 01:31:08
I think this id has the same meaning as above, rig
llandwerlin-old
2015/02/10 14:28:13
Adding a comment too.
| |
57 uint32_t size; | |
58 bool key_frame; | |
59 }; | |
60 | |
30 // PPB_VideoEncoder_API implementation. | 61 // PPB_VideoEncoder_API implementation. |
31 int32_t GetSupportedProfiles( | 62 int32_t GetSupportedProfiles( |
32 const PP_ArrayOutput& output, | 63 const PP_ArrayOutput& output, |
33 const scoped_refptr<TrackedCallback>& callback) override; | 64 const scoped_refptr<TrackedCallback>& callback) override; |
34 int32_t Initialize(PP_VideoFrame_Format input_format, | 65 int32_t Initialize(PP_VideoFrame_Format input_format, |
35 const PP_Size* input_visible_size, | 66 const PP_Size* input_visible_size, |
36 PP_VideoProfile output_profile, | 67 PP_VideoProfile output_profile, |
37 uint32_t initial_bitrate, | 68 uint32_t initial_bitrate, |
38 PP_HardwareAcceleration acceleration, | 69 PP_HardwareAcceleration acceleration, |
39 const scoped_refptr<TrackedCallback>& callback) override; | 70 const scoped_refptr<TrackedCallback>& callback) override; |
40 int32_t GetFramesRequired() override; | 71 int32_t GetFramesRequired() override; |
41 int32_t GetFrameCodedSize(PP_Size* size) override; | 72 int32_t GetFrameCodedSize(PP_Size* size) override; |
42 int32_t GetVideoFrame( | 73 int32_t GetVideoFrame( |
43 PP_Resource* video_frame, | 74 PP_Resource* video_frame, |
44 const scoped_refptr<TrackedCallback>& callback) override; | 75 const scoped_refptr<TrackedCallback>& callback) override; |
45 int32_t Encode(PP_Resource video_frame, | 76 int32_t Encode(PP_Resource video_frame, |
46 PP_Bool force_keyframe, | 77 PP_Bool force_keyframe, |
47 const scoped_refptr<TrackedCallback>& callback) override; | 78 const scoped_refptr<TrackedCallback>& callback) override; |
48 int32_t GetBitstreamBuffer( | 79 int32_t GetBitstreamBuffer( |
49 PP_BitstreamBuffer* picture, | 80 PP_BitstreamBuffer* picture, |
50 const scoped_refptr<TrackedCallback>& callback) override; | 81 const scoped_refptr<TrackedCallback>& callback) override; |
51 void RecycleBitstreamBuffer(const PP_BitstreamBuffer* picture) override; | 82 void RecycleBitstreamBuffer(const PP_BitstreamBuffer* picture) override; |
52 void RequestEncodingParametersChange(uint32_t bitrate, | 83 void RequestEncodingParametersChange(uint32_t bitrate, |
53 uint32_t framerate) override; | 84 uint32_t framerate) override; |
54 void Close() override; | 85 void Close() override; |
55 | 86 |
87 // PluginResource implementation. | |
88 void OnReplyReceived(const ResourceMessageReplyParams& params, | |
89 const IPC::Message& msg) override; | |
90 | |
91 // Reply message handlers for operations that are done in the host. | |
92 void OnPluginMsgGetSupportedProfilesReply( | |
93 const PP_ArrayOutput& output, | |
94 const scoped_refptr<TrackedCallback>& callback, | |
95 const ResourceMessageReplyParams& params, | |
96 const std::vector<PP_VideoProfileDescription>& profiles); | |
97 void OnPluginMsgInitializeReply(const ResourceMessageReplyParams& params, | |
98 uint32_t buffer_count, | |
99 uint32_t buffer_length, | |
100 uint32_t input_frame_count, | |
101 const PP_Size& input_coded_size); | |
102 void OnPluginMsgGetVideoFramesReply(const ResourceMessageReplyParams& params, | |
bbudge
2015/02/10 01:31:08
This name is a little confusing to me, since it so
llandwerlin-old
2015/02/10 14:28:13
We're actually getting the shm buffer too.
It feel
| |
103 uint32_t frame_count, | |
104 uint32_t frame_length, | |
105 const PP_Size& frame_size); | |
106 void OnPluginMsgEncodeReply(const scoped_refptr<TrackedCallback>& callback, | |
107 const ResourceMessageReplyParams& params, | |
108 uint32_t frame_id); | |
109 | |
110 // Unsolicited reply message handlers. | |
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 NotifyGetVideoFrameCallbacks(); | |
121 void NotifyGetVideoFrameCallbacksError(int32_t error); | |
122 void WriteBitstreamerBuffer(PP_BitstreamBuffer* bitstream_buffer, | |
bbudge
2015/02/10 01:31:08
s/WriteBitstreamerBuffer/WriteBitstreamBuffer
llandwerlin-old
2015/02/10 14:28:13
Oh dear... Done.
| |
123 const BitstreamBuffer& buffer); | |
124 void ReleaseFrames(); | |
125 | |
126 bool initialized_; | |
127 int32_t encoder_last_error_; | |
128 | |
129 int32_t encoder_frame_count_; | |
130 PP_Size encoder_coded_size_; | |
131 | |
132 bool waiting_for_video_frames_; | |
133 | |
134 scoped_ptr<MediaStreamBufferManager::Delegate> buffer_manager_delegate_; | |
135 scoped_ptr<MediaStreamBufferManager> buffer_manager_; | |
bbudge
2015/02/10 01:31:08
Same comments as on PepperVideoEncoderHost to elim
llandwerlin-old
2015/02/10 14:28:13
Done.
| |
136 | |
137 typedef std::map<PP_Resource, scoped_refptr<VideoFrameResource> > | |
bbudge
2015/02/10 01:31:08
Since we only use C++11 toolchains when we build t
llandwerlin-old
2015/02/10 14:28:14
I might be wrong, but I think the GCC version used
| |
138 VideoFrameMap; | |
139 VideoFrameMap video_frames_; | |
140 | |
141 std::deque<std::pair<PP_Resource*, scoped_refptr<TrackedCallback> > > | |
142 get_video_frame_cbs_; | |
bbudge
2015/02/10 01:31:08
get_video_frame_cbs_ sounds like a function or met
llandwerlin-old
2015/02/10 14:28:13
Done.
| |
143 | |
144 ScopedVector<ShmBuffer> bitstream_buffers_; | |
bbudge
2015/02/10 01:31:08
Could we name this shm_buffers_?
llandwerlin-old
2015/02/10 14:28:13
Sure.
| |
145 | |
146 std::deque<BitstreamBuffer> available_bitstream_buffers_; | |
147 typedef std::map<void*, uint32_t> BitstreamBufferMap; | |
148 BitstreamBufferMap bitstream_buffers_map_; | |
149 | |
150 scoped_refptr<TrackedCallback> initialize_callback_; | |
151 scoped_refptr<TrackedCallback> get_bitstreamer_buffer_callback_; | |
bbudge
2015/02/10 01:31:08
s/get_bitstreamer_buffer_callback_/get_bitstream_b
llandwerlin-old
2015/02/10 14:28:13
Done.
| |
152 PP_BitstreamBuffer* get_bitstreamer_buffer_data_; | |
bbudge
2015/02/10 01:31:08
s/get_bitstreamer_buffer_data_/get_bitstream_buffe
llandwerlin-old
2015/02/10 14:28:13
Done.
| |
153 | |
56 DISALLOW_COPY_AND_ASSIGN(VideoEncoderResource); | 154 DISALLOW_COPY_AND_ASSIGN(VideoEncoderResource); |
57 }; | 155 }; |
58 | 156 |
59 } // namespace proxy | 157 } // namespace proxy |
60 } // namespace ppapi | 158 } // namespace ppapi |
61 | 159 |
62 #endif // PPAPI_PROXY_VIDEO_ENCODER_RESOURCE_H_ | 160 #endif // PPAPI_PROXY_VIDEO_ENCODER_RESOURCE_H_ |
OLD | NEW |