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

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

Issue 859313002: Pepper: Define PPB_VideoEncoder API + Implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « ppapi/proxy/resource_creation_proxy.cc ('k') | ppapi/proxy/video_encoder_resource.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 PPAPI_PROXY_VIDEO_ENCODER_RESOURCE_API_H_
6 #define PPAPI_PROXY_VIDEO_ENCODER_RESOURCE_API_H_
7
8 #include <deque>
9
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
13 #include "ppapi/proxy/connection.h"
14 #include "ppapi/proxy/plugin_resource.h"
15 #include "ppapi/shared_impl/media_stream_buffer_manager.h"
16 #include "ppapi/shared_impl/resource.h"
17 #include "ppapi/thunk/ppb_video_encoder_api.h"
18
19 namespace base {
20 class SharedMemory;
21 }
22
23 namespace ppapi {
24
25 class TrackedCallback;
26
27 namespace proxy {
28
29 class SerializedHandle;
30 class VideoFrameResource;
31
32 class PPAPI_PROXY_EXPORT VideoEncoderResource
33 : public PluginResource,
34 public thunk::PPB_VideoEncoder_API {
35 public:
36 VideoEncoderResource(Connection connection, PP_Instance instance);
37 ~VideoEncoderResource() override;
38
39 thunk::PPB_VideoEncoder_API* AsPPB_VideoEncoder_API() override;
40
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;
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;
57 uint32_t size;
58 bool key_frame;
59 };
60
61 // PPB_VideoEncoder_API implementation.
62 int32_t GetSupportedProfiles(
63 const PP_ArrayOutput& output,
64 const scoped_refptr<TrackedCallback>& callback) override;
65 int32_t Initialize(PP_VideoFrame_Format input_format,
66 const PP_Size* input_visible_size,
67 PP_VideoProfile output_profile,
68 uint32_t initial_bitrate,
69 PP_HardwareAcceleration acceleration,
70 const scoped_refptr<TrackedCallback>& callback) override;
71 int32_t GetFramesRequired() override;
72 int32_t GetFrameCodedSize(PP_Size* size) override;
73 int32_t GetVideoFrame(
74 PP_Resource* video_frame,
75 const scoped_refptr<TrackedCallback>& callback) override;
76 int32_t Encode(PP_Resource video_frame,
77 PP_Bool force_keyframe,
78 const scoped_refptr<TrackedCallback>& callback) override;
79 int32_t GetBitstreamBuffer(
80 PP_BitstreamBuffer* picture,
81 const scoped_refptr<TrackedCallback>& callback) override;
82 void RecycleBitstreamBuffer(const PP_BitstreamBuffer* picture) override;
83 void RequestEncodingParametersChange(uint32_t bitrate,
84 uint32_t framerate) override;
85
86 // PluginResource implementation.
87 void OnReplyReceived(const ResourceMessageReplyParams& params,
88 const IPC::Message& msg) override;
89
90 // Reply message handlers for operations that are done in the host.
91 void OnPluginMsgGetSupportedProfilesReply(
92 const PP_ArrayOutput& output,
93 const scoped_refptr<TrackedCallback>& callback,
94 const ResourceMessageReplyParams& params,
95 const std::vector<PP_SupportedVideoProfile>& profiles);
96 void OnPluginMsgInitializeReply(const ResourceMessageReplyParams& params,
97 uint32_t buffer_count,
98 uint32_t buffer_length,
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 scoped_refptr<TrackedCallback>& callback,
106 const ResourceMessageReplyParams& params,
107 uint32_t frame_id);
108
109 // Unsolicited reply message handlers.
110 void OnPluginMsgBitstreamBufferReady(const ResourceMessageReplyParams& params,
111 uint32_t buffer_id,
112 uint32_t buffer_size,
113 bool key_frame);
114 void OnPluginMsgNotifyError(const ResourceMessageReplyParams& params,
115 int32_t error);
116
117 // Internal utility functions.
118 void NotifyGetVideoFrameCallbacks();
119 void NotifyGetVideoFrameCallbacksError(int32_t error);
120 void WriteBitstreamerBuffer(PP_BitstreamBuffer* bitstream_buffer,
121 const BitstreamBuffer& buffer);
122
123 bool initialized_;
124 int32_t encoder_last_error_;
125
126 int32_t encoder_frame_count_;
127 PP_Size encoder_coded_size_;
128
129 bool waiting_for_video_frames_;
130
131 scoped_ptr<MediaStreamBufferManager::Delegate> buffer_manager_delegate_;
132 scoped_ptr<MediaStreamBufferManager> media_stream_buffer_manager_;
133
134 typedef std::map<uint32_t, scoped_refptr<VideoFrameResource>> VideoFrameMap;
135 VideoFrameMap video_frames_;
136
137 std::deque<std::pair<PP_Resource*, scoped_refptr<TrackedCallback>>>
138 get_video_frame_cbs_;
139
140 ScopedVector<ShmBuffer> bitstream_buffers_;
141
142 std::deque<BitstreamBuffer> available_bitstream_buffers_;
143 typedef std::map<void*, uint32_t> BitstreamBufferMap;
144 BitstreamBufferMap bitstream_buffers_map_;
145
146 scoped_refptr<TrackedCallback> initialize_callback_;
147 scoped_refptr<TrackedCallback> get_bitstreamer_buffer_callback_;
148 PP_BitstreamBuffer* get_bitstreamer_buffer_data_;
149
150 DISALLOW_COPY_AND_ASSIGN(VideoEncoderResource);
151 };
152
153 } // namespace proxy
154 } // namespace ppapi
155
156 #endif // PPAPI_PROXY_VIDEO_ENCODER_RESOURCE_API_H_
OLDNEW
« no previous file with comments | « ppapi/proxy/resource_creation_proxy.cc ('k') | ppapi/proxy/video_encoder_resource.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698