OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 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 | 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_CPP_VIDEO_ENCODER_H_ | 5 #ifndef PPAPI_CPP_VIDEO_ENCODER_H_ |
6 #define PPAPI_CPP_VIDEO_ENCODER_H_ | 6 #define PPAPI_CPP_VIDEO_ENCODER_H_ |
7 | 7 |
8 #include "ppapi/c/pp_codecs.h" | 8 #include "ppapi/c/pp_codecs.h" |
9 #include "ppapi/c/pp_size.h" | 9 #include "ppapi/c/pp_size.h" |
10 #include "ppapi/cpp/completion_callback.h" | 10 #include "ppapi/cpp/completion_callback.h" |
11 #include "ppapi/cpp/graphics_3d.h" | |
12 #include "ppapi/cpp/resource.h" | 11 #include "ppapi/cpp/resource.h" |
13 #include "ppapi/cpp/size.h" | 12 #include "ppapi/cpp/size.h" |
14 #include "ppapi/cpp/video_frame.h" | 13 #include "ppapi/cpp/video_frame.h" |
15 | 14 |
16 /// @file | 15 /// @file |
17 /// This file defines the API to create and use a VideoEncoder resource. | 16 /// This file defines the API to create and use a VideoEncoder resource. |
18 | 17 |
19 namespace pp { | 18 namespace pp { |
20 | 19 |
21 class InstanceHandle; | 20 class InstanceHandle; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 /// @return If >= 0, the number of supported profiles returned, otherwise an | 66 /// @return If >= 0, the number of supported profiles returned, otherwise an |
68 /// error code from <code>pp_errors.h</code>. | 67 /// error code from <code>pp_errors.h</code>. |
69 int32_t GetSupportedProfiles(const CompletionCallbackWithOutput< | 68 int32_t GetSupportedProfiles(const CompletionCallbackWithOutput< |
70 std::vector<PP_VideoProfileDescription> >& cc); | 69 std::vector<PP_VideoProfileDescription> >& cc); |
71 | 70 |
72 /// Initializes a video encoder resource. This should be called after | 71 /// Initializes a video encoder resource. This should be called after |
73 /// GetSupportedProfiles() and before any functions below. | 72 /// GetSupportedProfiles() and before any functions below. |
74 /// | 73 /// |
75 /// @param[in] input_format The <code>PP_VideoFrame_Format</code> of the | 74 /// @param[in] input_format The <code>PP_VideoFrame_Format</code> of the |
76 /// frames which will be encoded. | 75 /// frames which will be encoded. |
77 /// @param[in] input_visible_size A <code>PP_Size</code> specifying the | 76 /// @param[in] input_visible_size A <code>Size</code> specifying the |
78 /// dimensions of the visible part of the input frames. | 77 /// dimensions of the visible part of the input frames. |
79 /// @param[in] output_profile A <code>PP_VideoProfile</code> specifying the | 78 /// @param[in] output_profile A <code>PP_VideoProfile</code> specifying the |
80 /// codec profile of the encoded output stream. | 79 /// codec profile of the encoded output stream. |
81 /// @param[in] acceleration A <code>PP_HardwareAcceleration</code> specifying | 80 /// @param[in] acceleration A <code>PP_HardwareAcceleration</code> specifying |
82 /// whether to use a hardware accelerated or a software implementation. | 81 /// whether to use a hardware accelerated or a software implementation. |
83 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | 82 /// @param[in] callback A <code>CompletionCallback</code> to be called upon |
84 /// completion. | 83 /// completion. |
85 /// | 84 /// |
86 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | 85 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. |
87 /// Returns PP_ERROR_NOTSUPPORTED if video encoding is not available, or the | 86 /// Returns PP_ERROR_NOTSUPPORTED if video encoding is not available, or the |
88 /// requested codec profile is not supported. | 87 /// requested codec profile is not supported. |
89 /// Returns PP_ERROR_NOMEMORY if frame and bitstream buffers can't be created. | 88 /// Returns PP_ERROR_NOMEMORY if frame and bitstream buffers can't be created. |
90 int32_t Initialize(const PP_VideoFrame_Format& input_format, | 89 int32_t Initialize(const PP_VideoFrame_Format& input_format, |
91 const PP_Size& input_visible_size, | 90 const Size& input_visible_size, |
92 const PP_VideoProfile& output_profile, | 91 const PP_VideoProfile& output_profile, |
93 const uint32_t initial_bitrate, | 92 const uint32_t initial_bitrate, |
94 PP_HardwareAcceleration acceleration, | 93 PP_HardwareAcceleration acceleration, |
95 const CompletionCallback& cc); | 94 const CompletionCallback& cc); |
96 | 95 |
97 /// Gets the number of input video frames that the encoder may hold while | 96 /// Gets the number of input video frames that the encoder may hold while |
98 /// encoding. If the plugin is providing the video frames, it should have at | 97 /// encoding. If the plugin is providing the video frames, it should have at |
99 /// least this many available. | 98 /// least this many available. |
100 /// | 99 /// |
101 /// @return An int32_t containing the number of frames required, or an error | 100 /// @return An int32_t containing the number of frames required, or an error |
102 /// code from <code>pp_errors.h</code>. | 101 /// code from <code>pp_errors.h</code>. |
103 /// Returns PP_ERROR_FAILED if Initialize() has not successfully completed. | 102 /// Returns PP_ERROR_FAILED if Initialize() has not successfully completed. |
104 int32_t GetFramesRequired(); | 103 int32_t GetFramesRequired(); |
105 | 104 |
106 /// Gets the coded size of the video frames required by the encoder. Coded | 105 /// Gets the coded size of the video frames required by the encoder. Coded |
107 /// size is the logical size of the input frames, in pixels. The encoder may | 106 /// size is the logical size of the input frames, in pixels. The encoder may |
108 /// have hardware alignment requirements that make this different from | 107 /// have hardware alignment requirements that make this different from |
109 /// |input_visible_size|, as requested in the call to Initialize(). | 108 /// |input_visible_size|, as requested in the call to Initialize(). |
110 /// | 109 /// |
111 /// @param[in] coded_size A <code>PP_Size</code> to hold the coded size. | 110 /// @param[in] coded_size A <code>Size</code> to hold the coded size. |
| 111 /// |
112 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. | 112 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. |
113 /// Returns PP_ERROR_FAILED if Initialize() has not successfully completed. | 113 /// Returns PP_ERROR_FAILED if Initialize() has not successfully completed. |
114 int32_t GetFrameCodedSize(PP_Size* coded_size); | 114 int32_t GetFrameCodedSize(Size* coded_size); |
115 | 115 |
116 /// Gets a blank video frame which can be filled with video data and passed | 116 /// Gets a blank video frame which can be filled with video data and passed |
117 /// to the encoder. | 117 /// to the encoder. |
118 /// | 118 /// |
119 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be | 119 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be |
120 /// called upon completion with the blank <code>VideoFrame</code> resource. | 120 /// called upon completion with the blank <code>VideoFrame</code> resource. |
121 /// | 121 /// |
122 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | 122 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. |
123 int32_t GetVideoFrame(const CompletionCallbackWithOutput<VideoFrame>& cc); | 123 int32_t GetVideoFrame(const CompletionCallbackWithOutput<VideoFrame>& cc); |
124 | 124 |
125 /// Encodes a video frame. | 125 /// Encodes a video frame. |
126 /// | 126 /// |
127 /// @param[in] video_frame The <code>VideoFrame</code> to be encoded. | 127 /// @param[in] video_frame The <code>VideoFrame</code> to be encoded. |
128 /// @param[in] force_keyframe A <code>PP_Bool> specifying whether the encoder | 128 /// @param[in] force_keyframe A <code>PP_Bool> specifying whether the encoder |
129 /// should emit a key frame for this video frame. | 129 /// should emit a key frame for this video frame. |
130 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | 130 /// @param[in] callback A <code>CompletionCallback</code> to be called upon |
131 /// completion. Plugins that pass <code>VideoFrame</code> resources owned | 131 /// completion. Plugins that pass <code>VideoFrame</code> resources owned |
132 /// by other resources should wait for completion before reusing them. | 132 /// by other resources should wait for completion before reusing them. |
133 /// | 133 /// |
134 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | 134 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 135 /// Returns PP_ERROR_FAILED if Initialize() has not successfully completed. |
135 int32_t Encode(const VideoFrame& video_frame, | 136 int32_t Encode(const VideoFrame& video_frame, |
136 bool force_keyframe, | 137 bool force_keyframe, |
137 const CompletionCallback& cc); | 138 const CompletionCallback& cc); |
138 | 139 |
139 /// Gets the next encoded bitstream buffer from the encoder. | 140 /// Gets the next encoded bitstream buffer from the encoder. |
140 /// | 141 /// |
141 /// @param[out] bitstream_buffer A <code>PP_BitstreamBuffer</code> containing | 142 /// @param[out] bitstream_buffer A <code>PP_BitstreamBuffer</code> containing |
142 /// encoded video data. | 143 /// encoded video data. |
143 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be | 144 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be |
144 /// called upon completion with the next bitstream buffer. The plugin can call | 145 /// called upon completion with the next bitstream buffer. The plugin can call |
145 /// GetBitstreamBuffer from the callback in order to continuously "pull" | 146 /// GetBitstreamBuffer from the callback in order to continuously "pull" |
146 /// bitstream buffers from the encoder. | 147 /// bitstream buffers from the encoder. |
147 /// | 148 /// |
148 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | 149 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 150 /// Returns PP_ERROR_FAILED if Initialize() has not successfully completed. |
| 151 /// Returns PP_ERROR_INPROGRESS if a prior call to GetBitstreamBuffer() has |
| 152 /// not completed. |
149 int32_t GetBitstreamBuffer( | 153 int32_t GetBitstreamBuffer( |
150 const CompletionCallbackWithOutput<PP_BitstreamBuffer>& cc); | 154 const CompletionCallbackWithOutput<PP_BitstreamBuffer>& cc); |
151 | 155 |
152 /// Recycles a bitstream buffer back to the encoder. | 156 /// Recycles a bitstream buffer back to the encoder. |
153 /// | 157 /// |
154 /// @param[in] bitstream_buffer A <code>PP_BitstreamBuffer</code> that is no | 158 /// @param[in] bitstream_buffer A <code>PP_BitstreamBuffer</code> that is no |
155 /// longer needed by the plugin. | 159 /// longer needed by the plugin. |
156 void RecycleBitstreamBuffer(const PP_BitstreamBuffer& bitstream_buffer); | 160 void RecycleBitstreamBuffer(const PP_BitstreamBuffer& bitstream_buffer); |
157 | 161 |
158 /// Requests a change to encoding parameters. This is only a request, | 162 /// Requests a change to encoding parameters. This is only a request, |
159 /// fulfilled on a best-effort basis. | 163 /// fulfilled on a best-effort basis. |
160 /// | 164 /// |
161 /// @param[in] bitrate The requested new bitrate, in bits per second. | 165 /// @param[in] bitrate The requested new bitrate, in bits per second. |
162 /// @param[in] framerate The requested new framerate, in frames per second. | 166 /// @param[in] framerate The requested new framerate, in frames per second. |
163 void RequestEncodingParametersChange(uint32_t bitrate, uint32_t framerate); | 167 void RequestEncodingParametersChange(uint32_t bitrate, uint32_t framerate); |
164 | 168 |
165 /// Closes the video encoder, and cancels any pending encodes. Any pending | 169 /// Closes the video encoder, and cancels any pending encodes. Any pending |
166 /// callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> . It is | 170 /// callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> . It is |
167 /// not valid to call any encoder functions after a call to this method. | 171 /// not valid to call any encoder functions after a call to this method. |
168 /// <strong>Note:</strong> Destroying the video encoder closes it implicitly, | 172 /// <strong>Note:</strong> Destroying the video encoder closes it implicitly, |
169 /// so you are not required to call Close(). | 173 /// so you are not required to call Close(). |
170 void Close(); | 174 void Close(); |
171 }; | 175 }; |
172 | 176 |
173 } // namespace pp | 177 } // namespace pp |
174 | 178 |
175 #endif // PPAPI_CPP_VIDEO_ENCODER_H_ | 179 #endif // PPAPI_CPP_VIDEO_ENCODER_H_ |
OLD | NEW |