OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2014 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 |
| 6 /* From ppb_video_encoder.idl modified Thu Jul 10 15:27:41 2014. */ |
| 7 |
| 8 #ifndef PPAPI_C_PPB_VIDEO_ENCODER_H_ |
| 9 #define PPAPI_C_PPB_VIDEO_ENCODER_H_ |
| 10 |
| 11 #include "ppapi/c/pp_bool.h" |
| 12 #include "ppapi/c/pp_codecs.h" |
| 13 #include "ppapi/c/pp_completion_callback.h" |
| 14 #include "ppapi/c/pp_instance.h" |
| 15 #include "ppapi/c/pp_macros.h" |
| 16 #include "ppapi/c/pp_resource.h" |
| 17 #include "ppapi/c/pp_size.h" |
| 18 #include "ppapi/c/pp_stdint.h" |
| 19 |
| 20 #define PPB_VIDEOENCODER_INTERFACE_0_1 "PPB_VideoEncoder;0.1" /* dev */ |
| 21 /** |
| 22 * @file |
| 23 * This file defines the <code>PPB_VideoEncoder</code> interface. |
| 24 */ |
| 25 |
| 26 |
| 27 /** |
| 28 * @addtogroup Typedefs |
| 29 * @{ |
| 30 */ |
| 31 /** |
| 32 * This typedef defines the signature that you implement to receive the |
| 33 * encoder's initialization result. |
| 34 * |
| 35 * @param[in] encoder The encoder being initialized. |
| 36 * @param[in] result If result is 0 (PP_OK), the operation succeeded. Negative |
| 37 * values (other than -1 or PP_OK_COMPLETE) indicate error and are specified |
| 38 * in pp_errors.h. |
| 39 * @param[in] input_frames_count A number of video frames the caller needs to |
| 40 * allocate in order to make sure it's always capable of feeding the encoder. |
| 41 * @param[in] input_coded_size The size of the video frames the caller should |
| 42 * allocate to match the hardware constrains. |
| 43 * @param[inout] user_data An opaque pointer that was passed into |
| 44 * <code>PPB_VideoEncoder.Initialize()</code>. |
| 45 */ |
| 46 typedef void (*PPB_VideoEncoder_Ready_Func)( |
| 47 PP_Resource encoder, |
| 48 int32_t result, |
| 49 uint32_t input_frames_count, |
| 50 const struct PP_Size* input_coded_size, |
| 51 void* user_data); |
| 52 /** |
| 53 * @} |
| 54 */ |
| 55 |
| 56 /** |
| 57 * @addtogroup Structs |
| 58 * @{ |
| 59 */ |
| 60 /** |
| 61 * The <code>PPB_VideoEncoderParams</code> struct contains the parameters |
| 62 * given to the video encoder to initialize itself. |
| 63 */ |
| 64 struct PP_VideoEncoderParams { /* dev */ |
| 65 /** |
| 66 * A <code>PP_Size</code> specifying the size of the frames to encode. |
| 67 */ |
| 68 struct PP_Size input_size; |
| 69 /** |
| 70 * A <code>PP_VideoProfile</code> specifying the video codec profile. |
| 71 */ |
| 72 PP_VideoProfile profile; |
| 73 /** |
| 74 * The bitrate of the video encoding. |
| 75 */ |
| 76 uint32_t bitrate; |
| 77 /** |
| 78 * A <code>PP_Bool</code> specifying whether the encoder can fall back to |
| 79 * software encoding if a suitable hardware encoder isn't available. |
| 80 */ |
| 81 PP_Bool allow_software_fallback; |
| 82 }; |
| 83 |
| 84 /** |
| 85 * Struct describing a video picture to encode. |
| 86 */ |
| 87 struct PP_VideoEncoderPicture { /* dev */ |
| 88 /** |
| 89 * Texture ID of the picture to encode in the plugin's GL context. |
| 90 */ |
| 91 uint32_t texture_id; |
| 92 /** |
| 93 * The GL texture target for the picture to encode. |
| 94 * Possible values are: |
| 95 * GL_TEXTURE_2D (normalized texture coordinates) |
| 96 * GL_TEXTURE_RECTANGLE_ARB (dimension dependent texture coordinates) |
| 97 * |
| 98 * The pixel format of the texture is GL_RGBA. |
| 99 */ |
| 100 uint32_t texture_target; |
| 101 /** |
| 102 * Dimensions of the texture holding the picture to encode. |
| 103 */ |
| 104 struct PP_Size texture_size; |
| 105 }; |
| 106 /** |
| 107 * @} |
| 108 */ |
| 109 |
| 110 /** |
| 111 * @addtogroup Interfaces |
| 112 * @{ |
| 113 */ |
| 114 /** |
| 115 * Video encoder interface. |
| 116 * |
| 117 * Typical usage: |
| 118 * - Call Create() to create a new video encoder resource. |
| 119 * - Call Initialize() to initialize it with a 3d graphics context and the |
| 120 * desired codec profile. |
| 121 * - Call Encode() continuously (waiting for each previous call to complete) to |
| 122 * push video frames to the encoder. |
| 123 * - Call Reset() to quickly stop the encoder (e.g. to implement Seek) and wait |
| 124 * for the callback before restarting decoding at another point. |
| 125 * - To destroy the encoder, the plugin should release all of its references to |
| 126 * it. Any pending callbacks will abort before the encoder is destroyed. |
| 127 * |
| 128 * Available video codecs vary by platform. |
| 129 * All: vp8, vp9. |
| 130 */ |
| 131 struct PPB_VideoEncoder_0_1 { /* dev */ |
| 132 /** |
| 133 * Creates a new video encoder resource. |
| 134 * |
| 135 * @param[in] instance A <code>PP_Instance</code> identifying the instance |
| 136 * with the video encoder. |
| 137 * |
| 138 * @return A <code>PP_Resource</code> corresponding to a video encoder if |
| 139 * successful or 0 otherwise. |
| 140 */ |
| 141 PP_Resource (*Create)(PP_Instance instance); |
| 142 /** |
| 143 * Determines if the given resource is a video encoder. |
| 144 * |
| 145 * @param[in] resource A <code>PP_Resource</code> identifying a resource. |
| 146 * |
| 147 * @return <code>PP_TRUE</code> if the resource is a |
| 148 * <code>PPB_VideoEncoder</code>, <code>PP_FALSE</code> if the resource is |
| 149 * invalid or some other type. |
| 150 */ |
| 151 PP_Bool (*IsVideoEncoder)(PP_Resource resource); |
| 152 /** |
| 153 * Initializes a video encoder resource. This should be called after |
| 154 * Create() and before any other functions. |
| 155 * |
| 156 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 157 * encoder. |
| 158 * @param[in] params A <code>PP_VideoEncoderParams</code> specifying the |
| 159 * parameters to initialize the video encoder. |
| 160 * @param[inout] user_data An opaque pointer that will be passed into |
| 161 * <code>callback</code>. |
| 162 * @param[in] callback A <code>PPB_VideoEncoder_Ready_Func</code> to be |
| 163 * called upon completion. |
| 164 * |
| 165 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 166 * Returns PP_ERROR_FAILED if the video encoder has already been initialized |
| 167 * or the submitted 3d context is invalid. |
| 168 * Returns PP_ERROR_NOTSUPPORTED if video encoding is not available, or the |
| 169 * requested profile is not supported. In this case, the client may call |
| 170 * Initialize() again with different parameters to find a good configuration. |
| 171 */ |
| 172 int32_t (*Initialize)(PP_Resource video_encoder, |
| 173 PP_Resource graphics3d_context, |
| 174 const struct PP_VideoEncoderParams* params, |
| 175 void* user_data, |
| 176 PPB_VideoEncoder_Ready_Func callback); |
| 177 /** |
| 178 * Encodes a video frame. The plugin should wait until the encoder signals |
| 179 * completion by returning PP_OK or by running |callback| before calling |
| 180 * Encode() again. The plugin will be notified by the |
| 181 * <code>PPP_VideoEncoder</code> interface when video bitstream buffer are |
| 182 * ready. |
| 183 * |
| 184 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 185 * encoder. |
| 186 * @param[in] picture A <code>PP_VideoEncoderPicture</code> picture. |
| 187 * @param[in] force_keyframe Forces the encoding of a keyframe for this |
| 188 * picture. |
| 189 * @param[in] callback A <code>PP_CompletionCallback_Dev</code> to be called |
| 190 on |
| 191 * completion. |
| 192 * |
| 193 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 194 * Returns PP_ERROR_BADARGUMENT if the |picture| argument is invalid. |
| 195 * Returns PP_ERROR_FAILED if the encoder isn't initialized or the picture |
| 196 * buffer submitted is already used by the encoder. |
| 197 * Returns PP_ERROR_INPROGRESS if this function has already been called and is |
| 198 * already for an encoding operation to complete. |
| 199 */ |
| 200 int32_t (*Encode)(PP_Resource video_encoder, |
| 201 uint32_t encode_id, |
| 202 const struct PP_VideoEncoderPicture* picture, |
| 203 PP_Bool force_keyframe, |
| 204 struct PP_CompletionCallback callback); |
| 205 /** |
| 206 * Resets the encoder as quickly as possible. The plugin can call Reset() to |
| 207 * skip to another position in the video stream. After Reset() returns, any |
| 208 * pending calls to Encode() abort, causing their callbacks to run with |
| 209 * PP_ERROR_ABORTED. The plugin should not make further calls to the encoder |
| 210 * until the encoder signals completion by running |callback|. |
| 211 * |
| 212 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 213 * encoder. |
| 214 * @param[in] callback A <code>PP_CompletionCallback</code> to be called on |
| 215 * completion. |
| 216 * |
| 217 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 218 * Returns PP_ERROR_FAILED if the encoder isn't initialized. |
| 219 */ |
| 220 int32_t (*Reset)(PP_Resource video_encoder, |
| 221 struct PP_CompletionCallback callback); |
| 222 }; |
| 223 /** |
| 224 * @} |
| 225 */ |
| 226 |
| 227 #endif /* PPAPI_C_PPB_VIDEO_ENCODER_H_ */ |
| 228 |
OLD | NEW |