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