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 Wed Jan 14 13:51:24 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" |
| 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 * |
| 38 * Typical usage: |
| 39 * - Call Create() to create a new video encoder resource. |
| 40 * - Call GetSupportedFormats() to determine which codecs and profiles are |
| 41 * available. |
| 42 * - Call Initialize() to initialize the encoder for a supported profile. |
| 43 * - Call GetVideoFrame() to get a blank frame and fill it in, or get a video |
| 44 * frame from another resource, e.g. <code>PPB_MediaStreamVideoTrack</code>. |
| 45 * - Call Encode() to push the video frame to the encoder. If an external frame |
| 46 * is pushed, wait for completion to recycle the frame. |
| 47 * - Call GetBitstreamBuffer() continuously (waiting for each previous call to |
| 48 * complete) to pull encoded pictures from the encoder. |
| 49 * - Call RecycleBitstreamBuffer() after consuming the data in the bitstream |
| 50 * buffer. |
| 51 * - To destroy the encoder, the plugin should release all of its references to |
| 52 * it. Any pending callbacks will abort before the encoder is destroyed. |
| 53 * |
| 54 * Available video codecs vary by platform. |
| 55 * All: theora, vorbis, vp8. |
| 56 * Chrome and ChromeOS: h264. |
| 57 * ChromeOS: mpeg4. |
| 58 */ |
| 59 struct PPB_VideoEncoder_0_1 { |
| 60 /** |
| 61 * Creates a new video encoder resource. |
| 62 * |
| 63 * @param[in] instance A <code>PP_Instance</code> identifying the instance |
| 64 * with the video encoder. |
| 65 * |
| 66 * @return A <code>PP_Resource</code> corresponding to a video encoder if |
| 67 * successful or 0 otherwise. |
| 68 */ |
| 69 PP_Resource (*Create)(PP_Instance instance); |
| 70 /** |
| 71 * Determines if the given resource is a video encoder. |
| 72 * |
| 73 * @param[in] resource A <code>PP_Resource</code> identifying a resource. |
| 74 * |
| 75 * @return <code>PP_TRUE</code> if the resource is a |
| 76 * <code>PPB_VideoEncoder</code>, <code>PP_FALSE</code> if the resource is |
| 77 * invalid or some other type. |
| 78 */ |
| 79 PP_Bool (*IsVideoEncoder)(PP_Resource resource); |
| 80 /** |
| 81 * Gets an array of supported video encoder profiles. |
| 82 * These can be used to choose a profile before calling Initialize(). |
| 83 * |
| 84 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 85 * encoder. |
| 86 * @param[in] output A <code>PP_ArrayOutput</code> to hold the supported |
| 87 * <code>PP_SupportedVideoProfile</code> structs. |
| 88 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 89 * completion. |
| 90 * |
| 91 * @return If >= 0, the number of supported profiles returned, otherwise an |
| 92 * error code from <code>pp_errors.h</code>. |
| 93 */ |
| 94 int32_t (*GetSupportedProfiles)(PP_Resource video_encoder, |
| 95 struct PP_ArrayOutput output, |
| 96 struct PP_CompletionCallback callback); |
| 97 /** |
| 98 * Initializes a video encoder resource. This should be called after Create() |
| 99 * and GetSupportedProfiles() and before any functions below. |
| 100 * |
| 101 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 102 * encoder. |
| 103 * @param[in] input_format The <code>PP_VideoFrame_Format</code> of the |
| 104 * frames which will be encoded. |
| 105 * @param[in] input_visible_size A <code>PP_Size</code> specifying the |
| 106 * dimensions of the visible part of the input frames. |
| 107 * @param[in] output_profile A <code>PP_VideoProfile</code> specifying the |
| 108 * codec profile of the encoded output stream. |
| 109 * @param[in] acceleration A <code>PP_HardwareAcceleration</code> specifying |
| 110 * whether to use a hardware accelerated or a software implementation. |
| 111 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 112 * completion. |
| 113 * |
| 114 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 115 * Returns PP_ERROR_NOTSUPPORTED if video encoding is not available, or the |
| 116 * requested codec profile is not supported. |
| 117 * Returns PP_ERROR_NOMEMORY if frame and bitstream buffers can't be created. |
| 118 */ |
| 119 int32_t (*Initialize)(PP_Resource video_encoder, |
| 120 PP_VideoFrame_Format input_format, |
| 121 const struct PP_Size* input_visible_size, |
| 122 PP_VideoProfile output_profile, |
| 123 uint32_t initial_bitrate, |
| 124 PP_HardwareAcceleration acceleration, |
| 125 struct PP_CompletionCallback callback); |
| 126 /** |
| 127 * Gets the number of input video frames that the encoder may hold while |
| 128 * encoding. If the plugin is providing the video frames, it should have at |
| 129 * least this many available. This must be called after Initialize(). |
| 130 * |
| 131 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 132 * encoder. |
| 133 * @return An int32_t containing the number of frames required, or an error |
| 134 * code from <code>pp_errors.h</code>. |
| 135 */ |
| 136 int32_t (*GetInputFramesRequired)(PP_Resource video_encoder); |
| 137 /** |
| 138 * Gets a blank video frame which can be filled with video data and passed |
| 139 * to the encoder. |
| 140 * |
| 141 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 142 * encoder. |
| 143 * @param[out] video_frame A blank <code>PPB_VideoFrame</code> resource. |
| 144 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 145 * completion. |
| 146 * |
| 147 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 148 */ |
| 149 int32_t (*GetVideoFrame)(PP_Resource video_encoder, |
| 150 PP_Resource* video_frame, |
| 151 struct PP_CompletionCallback callback); |
| 152 /** |
| 153 * Encodes a video frame. |
| 154 * |
| 155 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 156 * encoder. |
| 157 * @param[in] video_frame The <code>PPB_VideoFrame</code> to be encoded. |
| 158 * @param[in] force_keyframe A <code>PP_Bool> specifying whether the encoder |
| 159 * should emit a key frame for this video frame. |
| 160 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 161 * completion. Plugins that pass <code>PPB_VideoFrame</code> resources owned |
| 162 * by other resources should wait for completion before reusing them. |
| 163 * |
| 164 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 165 */ |
| 166 int32_t (*Encode)(PP_Resource video_encoder, |
| 167 PP_Resource video_frame, |
| 168 PP_Bool force_keyframe, |
| 169 struct PP_CompletionCallback callback); |
| 170 /** |
| 171 * Gets the next encoded bitstream buffer from the encoder. |
| 172 * |
| 173 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 174 * encoder. |
| 175 * @param[out] bitstream_buffer A <code>PP_BitstreamBuffer</code> containing |
| 176 * encoded video data. |
| 177 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 178 * completion. The plugin can call GetBitstreamBuffer from the callback in |
| 179 * order to continuously "pull" bitstream buffers from the encoder. |
| 180 * |
| 181 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 182 */ |
| 183 int32_t (*GetBitstreamBuffer)(PP_Resource video_encoder, |
| 184 struct PP_BitstreamBuffer* bitstream_buffer, |
| 185 struct PP_CompletionCallback callback); |
| 186 /** |
| 187 * Recycles a bitstream buffer back to the encoder. |
| 188 * |
| 189 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 190 * encoder. |
| 191 * @param[in] bitstream_buffer A <code>PP_BitstreamBuffer</code> that is no |
| 192 * longer needed by the plugin. |
| 193 */ |
| 194 void (*RecycleBitstreamBuffer)( |
| 195 PP_Resource video_encoder, |
| 196 const struct PP_BitstreamBuffer* bitstream_buffer); |
| 197 /** |
| 198 * Requests a change to encoding parameters. This is only a request, |
| 199 * fulfilled on a best-effort basis. |
| 200 * |
| 201 * @param[in] video_encoder A <code>PP_Resource</code> identifying the video |
| 202 * encoder. |
| 203 * @param[in] bitrate The requested new bitrate, in bits per second. |
| 204 * @param[in] framerate The requested new framerate, in frames per second. |
| 205 */ |
| 206 void (*RequestEncodingParametersChange)(PP_Resource video_encoder, |
| 207 uint32_t bitrate, |
| 208 uint32_t framerate); |
| 209 }; |
| 210 |
| 211 typedef struct PPB_VideoEncoder_0_1 PPB_VideoEncoder; |
| 212 /** |
| 213 * @} |
| 214 */ |
| 215 |
| 216 #endif /* PPAPI_C_PPB_VIDEO_ENCODER_H_ */ |
| 217 |
OLD | NEW |