Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: ppapi/proxy/video_encoder_resource.h

Issue 905023005: Pepper: PPB_VideoEncoder implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after bbudge's review Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 scoped_refptr<TrackedCallback>& callback,
99 const ResourceMessageReplyParams& params,
100 const std::vector<PP_VideoProfileDescription>& profiles);
101 void OnPluginMsgInitializeReply(const ResourceMessageReplyParams& params,
102 uint32_t buffer_length,
103 uint32_t input_frame_count,
104 const PP_Size& input_coded_size);
105 void OnPluginMsgGetVideoFramesReply(const ResourceMessageReplyParams& params,
106 uint32_t frame_count,
107 uint32_t frame_length,
108 const PP_Size& frame_size);
109 void OnPluginMsgEncodeReply(const scoped_refptr<TrackedCallback>& callback,
110 const ResourceMessageReplyParams& params,
111 uint32_t frame_id);
112
113 // Unsolicited reply message handlers.
114 void OnPluginMsgBitstreamBufferReady(const ResourceMessageReplyParams& params,
115 uint32_t buffer_id,
116 uint32_t buffer_size,
117 bool key_frame);
118 void OnPluginMsgNotifyError(const ResourceMessageReplyParams& params,
119 int32_t error);
120
121 // Internal utility functions.
122 void NotifyError(int32_t error);
123 void NotifyGetVideoFrameCallbacks();
124 void NotifyGetVideoFrameCallbacksError(int32_t error);
125 void WriteBitstreamBuffer(PP_BitstreamBuffer* bitstream_buffer,
126 const BitstreamBuffer& buffer);
127 void ReleaseFrames();
128
129 bool initialized_;
130 int32_t encoder_last_error_;
131
132 int32_t input_frame_count_;
133 PP_Size input_coded_size_;
134
135 bool waiting_for_video_frames_;
136
137 MediaStreamBufferManager buffer_manager_;
138
139 typedef std::map<PP_Resource, scoped_refptr<VideoFrameResource> >
140 VideoFrameMap;
141 VideoFrameMap video_frames_;
142
143 std::deque<std::pair<PP_Resource*, scoped_refptr<TrackedCallback> > >
144 pending_get_video_frame_calls_;
145
146 ScopedVector<ShmBuffer> shm_buffers_;
147
148 std::deque<BitstreamBuffer> available_bitstream_buffers_;
149 typedef std::map<void*, uint32_t> BitstreamBufferMap;
150 BitstreamBufferMap bitstream_buffers_map_;
bbudge 2015/02/10 22:47:39 nit: s/bitstream_buffers_map_/bitstream_buffer_map
llandwerlin-old 2015/02/11 18:42:25 Done.
151
152 scoped_refptr<TrackedCallback> initialize_callback_;
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698