OLD | NEW |
(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 |
| 6 /* From ppb_video_encoder.idl modified Fri Jan 16 13:26:50 2015. */ |
| 7 |
| 8 #ifndef PPAPI_C_PPB_VIDEO_ENCODER_H_ |
| 9 #define PPAPI_C_PPB_VIDEO_ENCODER_H_ |
| 10 |
| 11 #include "ppapi/c/pp_array_output.h" |
| 12 #include "ppapi/c/pp_bool.h" |
| 13 #include "ppapi/c/pp_codecs.h" |
| 14 #include "ppapi/c/pp_completion_callback.h" |
| 15 #include "ppapi/c/pp_instance.h" |
| 16 #include "ppapi/c/pp_macros.h" |
| 17 #include "ppapi/c/pp_resource.h" |
| 18 #include "ppapi/c/pp_size.h" |
| 19 #include "ppapi/c/pp_stdint.h" |
| 20 #include "ppapi/c/ppb_video_frame.h" |
| 21 |
| 22 #define PPB_VIDEOENCODER_INTERFACE_0_1 "PPB_VideoEncoder;0.1" /* dev */ |
| 23 #define PPB_VIDEOENCODER_INTERFACE PPB_VIDEOENCODER_INTERFACE_0_1 |
| 24 |
| 25 /** |
| 26 * @file |
| 27 * This file defines the <code>PPB_VideoEncoder</code> interface. |
| 28 */ |
| 29 |
| 30 |
| 31 /** |
| 32 * @addtogroup Interfaces |
| 33 * @{ |
| 34 */ |
| 35 /** |
| 36 * Video encoder interface. |
| 37 * This interface is still in development (Dev API status) and may change, |
| 38 * so is only supported on Dev channel and Canary currently. |
| 39 * |
| 40 * Typical usage: |
| 41 * - Call Create() to create a new video encoder resource. |
| 42 * - Call GetSupportedFormats() to determine which codecs and profiles are |
| 43 * available. |
| 44 * - Call Initialize() to initialize the encoder for a supported profile. |
| 45 * - Call GetVideoFrame() to get a blank frame and fill it in, or get a video |
| 46 * frame from another resource, e.g. <code>PPB_MediaStreamVideoTrack</code>. |
| 47 * - Call Encode() to push the video frame to the encoder. If an external frame |
| 48 * is pushed, wait for completion to recycle the frame. |
| 49 * - Call GetBitstreamBuffer() continuously (waiting for each previous call to |
| 50 * complete) to pull encoded pictures from the encoder. |
| 51 * - Call RecycleBitstreamBuffer() after consuming the data in the bitstream |
| 52 * buffer. |
| 53 * - To destroy the encoder, the plugin should release all of its references to |
| 54 * it. Any pending callbacks will abort before the encoder is destroyed. |
| 55 * |
| 56 * Available video codecs vary by platform. |
| 57 * All: theora, vorbis, vp8. |
| 58 * Chrome and ChromeOS: h264. |
| 59 * ChromeOS: mpeg4. |
| 60 */ |
| 61 struct PPB_VideoEncoder_0_1 { /* dev */ |
| 62 /** |
| 63 * Creates a new video encoder resource. |
| 64 * |
| 65 * @param[in] instance A <code>PP_Instance</code> identifying the instance |
| 66 * with the video encoder. |
| 67 * |
| 68 * @return A <code>PP_Resource</code> corresponding to a video encoder if |
| 69 * successful or 0 otherwise. |
| 70 */ |
| 71 PP_Resource (*Create)(PP_Instance instance); |
| 72 /** |
| 73 * Determines if the given resource is a video encoder. |
| 74 * |
| 75 * @param[in] resource A <code>PP_Resource</code> identifying a resource. |
| 76 * |
| 77 * @return <code>PP_TRUE</code> if the resource is a |
| 78 * <code>PPB_VideoEncoder</code>, <code>PP_FALSE</code> if the resource is |
| 79 * invalid or some other type. |
| 80 */ |
| 81 PP_Bool (*IsVideoEncoder)(PP_Resource resource); |
| 82 /** |
| 83 * Gets an array of supported video encoder profiles. |
| 84 * These can be used to choose a profile before calling Initialize(). |
| 85 * |
| 86 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 87 * encoder. |
| 88 * @param[in] output A <code>PP_ArrayOutput</code> to hold the supported |
| 89 * <code>PP_SupportedVideoProfile</code> structs. |
| 90 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 91 * completion. |
| 92 * |
| 93 * @return If >= 0, the number of supported profiles returned, otherwise an |
| 94 * error code from <code>pp_errors.h</code>. |
| 95 */ |
| 96 int32_t (*GetSupportedProfiles)(PP_Resource video_encoder, |
| 97 struct PP_ArrayOutput output, |
| 98 struct PP_CompletionCallback callback); |
| 99 /** |
| 100 * Initializes a video encoder resource. The plugin should call Initialize() |
| 101 * successfully before calling any of the functions below. |
| 102 * |
| 103 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 104 * encoder. |
| 105 * @param[in] input_format The <code>PP_VideoFrame_Format</code> of the |
| 106 * frames which will be encoded. |
| 107 * @param[in] input_visible_size A <code>PP_Size</code> specifying the |
| 108 * dimensions of the visible part of the input frames. |
| 109 * @param[in] output_profile A <code>PP_VideoProfile</code> specifying the |
| 110 * codec profile of the encoded output stream. |
| 111 * @param[in] acceleration A <code>PP_HardwareAcceleration</code> specifying |
| 112 * whether to use a hardware accelerated or a software implementation. |
| 113 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 114 * completion. |
| 115 * |
| 116 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 117 * Returns PP_ERROR_NOTSUPPORTED if video encoding is not available, or the |
| 118 * requested codec profile is not supported. |
| 119 */ |
| 120 int32_t (*Initialize)(PP_Resource video_encoder, |
| 121 PP_VideoFrame_Format input_format, |
| 122 const struct PP_Size* input_visible_size, |
| 123 PP_VideoProfile output_profile, |
| 124 uint32_t initial_bitrate, |
| 125 PP_HardwareAcceleration acceleration, |
| 126 struct PP_CompletionCallback callback); |
| 127 /** |
| 128 * Gets the number of input video frames that the encoder may hold while |
| 129 * encoding. If the plugin is providing the video frames, it should have at |
| 130 * least this many available. |
| 131 * |
| 132 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 133 * encoder. |
| 134 * @return An int32_t containing the number of frames required, or an error |
| 135 * code from <code>pp_errors.h</code>. |
| 136 * Returns PP_ERROR_FAILED if Initialize() has not successfully completed. |
| 137 */ |
| 138 int32_t (*GetFramesRequired)(PP_Resource video_encoder); |
| 139 /** |
| 140 * Gets the coded size of the video frames required by the encoder. Coded |
| 141 * size is the logical size of the input frames, in pixels. The encoder may |
| 142 * have hardware alignment requirements that make this different from |
| 143 * |input_visible_size|, as requested in the call to Initialize(). |
| 144 * |
| 145 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 146 * encoder. |
| 147 * @param[in] coded_size A <code>PP_Size</code> to hold the coded size. |
| 148 * @return An int32_t containing a result code from <code>pp_errors.h</code>. |
| 149 * Returns PP_ERROR_FAILED if Initialize() has not successfully completed. |
| 150 */ |
| 151 int32_t (*GetFrameCodedSize)(PP_Resource video_encoder, |
| 152 struct PP_Size* coded_size); |
| 153 /** |
| 154 * Gets a blank video frame which can be filled with video data and passed |
| 155 * to the encoder. |
| 156 * |
| 157 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 158 * encoder. |
| 159 * @param[out] video_frame A blank <code>PPB_VideoFrame</code> resource. |
| 160 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 161 * completion. |
| 162 * |
| 163 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 164 * Returns PP_ERROR_FAILED if Initialize() has not successfully completed. |
| 165 */ |
| 166 int32_t (*GetVideoFrame)(PP_Resource video_encoder, |
| 167 PP_Resource* video_frame, |
| 168 struct PP_CompletionCallback callback); |
| 169 /** |
| 170 * Encodes a video frame. |
| 171 * |
| 172 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 173 * encoder. |
| 174 * @param[in] video_frame The <code>PPB_VideoFrame</code> to be encoded. |
| 175 * @param[in] force_keyframe A <code>PP_Bool> specifying whether the encoder |
| 176 * should emit a key frame for this video frame. |
| 177 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 178 * completion. Plugins that pass <code>PPB_VideoFrame</code> resources owned |
| 179 * by other resources should wait for completion before reusing them. |
| 180 * |
| 181 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 182 * Returns PP_ERROR_FAILED if Initialize() has not successfully completed. |
| 183 */ |
| 184 int32_t (*Encode)(PP_Resource video_encoder, |
| 185 PP_Resource video_frame, |
| 186 PP_Bool force_keyframe, |
| 187 struct PP_CompletionCallback callback); |
| 188 /** |
| 189 * Gets the next encoded bitstream buffer from the encoder. |
| 190 * |
| 191 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 192 * encoder. |
| 193 * @param[out] bitstream_buffer A <code>PP_BitstreamBuffer</code> containing |
| 194 * encoded video data. |
| 195 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 196 * completion. The plugin can call GetBitstreamBuffer from the callback in |
| 197 * order to continuously "pull" bitstream buffers from the encoder. |
| 198 * |
| 199 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 200 * Returns PP_ERROR_FAILED if Initialize() has not successfully completed. |
| 201 * Returns PP_ERROR_INPROGRESS if a prior call to GetBitstreamBuffer() has |
| 202 * not completed. |
| 203 */ |
| 204 int32_t (*GetBitstreamBuffer)(PP_Resource video_encoder, |
| 205 struct PP_BitstreamBuffer* bitstream_buffer, |
| 206 struct PP_CompletionCallback callback); |
| 207 /** |
| 208 * Recycles a bitstream buffer back to the encoder. |
| 209 * |
| 210 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 211 * encoder. |
| 212 * @param[in] bitstream_buffer A <code>PP_BitstreamBuffer</code> that is no |
| 213 * longer needed by the plugin. |
| 214 */ |
| 215 void (*RecycleBitstreamBuffer)( |
| 216 PP_Resource video_encoder, |
| 217 const struct PP_BitstreamBuffer* bitstream_buffer); |
| 218 /** |
| 219 * Requests a change to encoding parameters. This is only a request, |
| 220 * fulfilled on a best-effort basis. |
| 221 * |
| 222 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 223 * encoder. |
| 224 * @param[in] bitrate The requested new bitrate, in bits per second. |
| 225 * @param[in] framerate The requested new framerate, in frames per second. |
| 226 */ |
| 227 void (*RequestEncodingParametersChange)(PP_Resource video_encoder, |
| 228 uint32_t bitrate, |
| 229 uint32_t framerate); |
| 230 }; |
| 231 |
| 232 typedef struct PPB_VideoEncoder_0_1 PPB_VideoEncoder; |
| 233 /** |
| 234 * @} |
| 235 */ |
| 236 |
| 237 #endif /* PPAPI_C_PPB_VIDEO_ENCODER_H_ */ |
OLD | NEW |