vpx_decoder_compat.h 23.3 KB
Newer Older
 John Koleszar committed May 18, 2010 1 /*  John Koleszar committed Sep 09, 2010 2  * Copyright (c) 2010 The WebM project authors. All Rights Reserved.  John Koleszar committed May 18, 2010 3  *  John Koleszar committed Jun 18, 2010 4  * Use of this source code is governed by a BSD-style license  John Koleszar committed Jun 04, 2010 5 6  * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found  John Koleszar committed Jun 18, 2010 7  * in the file PATENTS. All contributing project authors may  John Koleszar committed Jun 04, 2010 8  * be found in the AUTHORS file in the root of the source tree.  John Koleszar committed May 18, 2010 9 10 11 12 13 14 15 16 17 18  */ /*!\defgroup decoder Common Decoder Algorithm Interface * This abstraction allows applications using this decoder to easily support * multiple video formats with minimal code duplication. This section describes * the interface common to all codecs. * @{ */  James Zern committed Feb 16, 2011 19 /*!\file  John Koleszar committed May 18, 2010 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80  * \brief Provides a compatibility layer between version 1 and 2 of this API. * * This interface has been deprecated. Only existing code should make use * of this interface, and therefore, it is only thinly documented. Existing * code should be ported to the vpx_codec_* API. */ #ifdef __cplusplus extern "C" { #endif #ifndef VPX_DECODER_COMPAT_H #define VPX_DECODER_COMPAT_H /*!\brief Decoder algorithm return codes */ typedef enum { /*!\brief Operation completed without error */ VPX_DEC_OK = VPX_CODEC_OK, /*!\brief Unspecified error */ VPX_DEC_ERROR = VPX_CODEC_ERROR, /*!\brief Memory operation failed */ VPX_DEC_MEM_ERROR = VPX_CODEC_MEM_ERROR, /*!\brief ABI version mismatch */ VPX_DEC_ABI_MISMATCH = VPX_CODEC_ABI_MISMATCH, /*!\brief The given bitstream is not supported. * * The bitstream was unable to be parsed at the highest level. The decoder * is unable to proceed. This error \ref SHOULD be treated as fatal to the * stream. */ VPX_DEC_UNSUP_BITSTREAM = VPX_CODEC_UNSUP_BITSTREAM, /*!\brief Encoded bitstream uses an unsupported feature * * The decoder does not implement a feature required by the encoder. This * return code should only be used for features that prevent future * pictures from being properly decoded. This error \ref MAY be treated as * fatal to the stream or \ref MAY be treated as fatal to the current GOP. */ VPX_DEC_UNSUP_FEATURE = VPX_CODEC_UNSUP_FEATURE, /*!\brief The coded data for this stream is corrupt or incomplete * * There was a problem decoding the current frame. This return code * should only be used for failures that prevent future pictures from * being properly decoded. This error \ref MAY be treated as fatal to the * stream or \ref MAY be treated as fatal to the current GOP. If decoding * is continued for the current GOP, artifacts may be present. */ VPX_DEC_CORRUPT_FRAME = VPX_CODEC_CORRUPT_FRAME, /*!\brief An application-supplied parameter is not valid. * */ VPX_DEC_INVALID_PARAM = VPX_CODEC_INVALID_PARAM, /*!\brief An iterator reached the end of list. * */  Timothy B. Terriberry committed Oct 27, 2010 81  VPX_DEC_LIST_END = VPX_CODEC_LIST_END  John Koleszar committed May 18, 2010 82 83 84 85 86 87 88 89 90 91  } vpx_dec_err_t; /*! \brief Decoder capabilities bitfield * * Each decoder advertises the capabilities it supports as part of its * ::vpx_dec_iface_t interface structure. Capabilities are extra interfaces * or functionality, and are not required to be supported by a decoder. *  James Zern committed Feb 16, 2011 92  * The available flags are specified by VPX_DEC_CAP_* defines.  John Koleszar committed May 18, 2010 93 94 95 96  */ typedef int vpx_dec_caps_t; #define VPX_DEC_CAP_PUT_SLICE 0x0001 /**< Will issue put_slice callbacks */ #define VPX_DEC_CAP_PUT_FRAME 0x0002 /**< Will issue put_frame callbacks */  James Zern committed Feb 16, 2011 97 #define VPX_DEC_CAP_XMA 0x0004 /**< Supports eXternal Memory Allocation */  John Koleszar committed May 18, 2010 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224  /*!\brief Stream properties * * This structure is used to query or set properties of the decoded * stream. Algorithms may extend this structure with data specific * to their bitstream by setting the sz member appropriately. */ #if 1 typedef vpx_codec_stream_info_t vpx_dec_stream_info_t; #else typedef struct { unsigned int sz; /**< Size of this structure */ unsigned int w; /**< Width (or 0 for unknown/default) */ unsigned int h; /**< Height (or 0 for unknown/default) */ unsigned int is_kf; /**< Current frame is a keyframe */ } vpx_dec_stream_info_t; #endif /*!\brief Decoder interface structure. * * Contains function pointers and other data private to the decoder * implementation. This structure is opaque to the application. */ typedef const struct vpx_codec_iface vpx_dec_iface_t; typedef struct vpx_codec_priv vpx_dec_priv_t; /*!\brief Iterator * * Opaque storage used for iterating over lists. */ typedef vpx_codec_iter_t vpx_dec_iter_t; /*!\brief Decoder context structure * * All decoders \ref MUST support this context structure fully. In general, * this data should be considered private to the decoder algorithm, and * not be manipulated or examined by the calling application. Applications * may reference the 'name' member to get a printable description of the * algorithm. */ #if 1 typedef vpx_codec_ctx_t vpx_dec_ctx_t; #else typedef struct { const char *name; /**< Printable interface name */ vpx_dec_iface_t *iface; /**< Interface pointers */ vpx_dec_err_t err; /**< Last returned error */ vpx_dec_priv_t *priv; /**< Algorithm private storage */ } vpx_dec_ctx_t; #endif /*!\brief Return the build configuration * * Returns a printable string containing an encoded version of the build * configuration. This may be useful to vpx support. * */ const char *vpx_dec_build_config(void) DEPRECATED; /*!\brief Return the name for a given interface * * Returns a human readable string for name of the given decoder interface. * * \param[in] iface Interface pointer * */ const char *vpx_dec_iface_name(vpx_dec_iface_t *iface) DEPRECATED; /*!\brief Convert error number to printable string * * Returns a human readable string for the last error returned by the * algorithm. The returned error will be one line and will not contain * any newline characters. * * * \param[in] err Error number. * */ const char *vpx_dec_err_to_string(vpx_dec_err_t err) DEPRECATED; /*!\brief Retrieve error synopsis for decoder context * * Returns a human readable string for the last error returned by the * algorithm. The returned error will be one line and will not contain * any newline characters. * * * \param[in] ctx Pointer to this instance's context. * */ const char *vpx_dec_error(vpx_dec_ctx_t *ctx) DEPRECATED; /*!\brief Retrieve detailed error information for decoder context * * Returns a human readable string providing detailed information about * the last error. * * \param[in] ctx Pointer to this instance's context. * * \retval NULL * No detailed information is available. */ const char *vpx_dec_error_detail(vpx_dec_ctx_t *ctx) DEPRECATED; /* REQUIRED FUNCTIONS * * The following functions are required to be implemented for all decoders. * They represent the base case functionality expected of all decoders. */ /*!\brief Initialize a decoder instance * * Initializes a decoder context using the given interface. Applications * should call the vpx_dec_init convenience macro instead of this * function directly, to ensure that the ABI version number parameter * is properly initialized. * * \param[in] ctx Pointer to this instance's context.  James Zern committed Feb 16, 2011 225  * \param[in] iface Pointer to the algorithm interface to use.  John Koleszar committed May 18, 2010 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255  * \param[in] ver ABI version number. Must be set to * VPX_DECODER_ABI_VERSION * \retval #VPX_DEC_OK * The decoder algorithm initialized. * \retval #VPX_DEC_MEM_ERROR * Memory allocation failed. */ vpx_dec_err_t vpx_dec_init_ver(vpx_dec_ctx_t *ctx, vpx_dec_iface_t *iface, int ver) DEPRECATED; #define vpx_dec_init(ctx, iface) \ vpx_dec_init_ver(ctx, iface, VPX_DECODER_ABI_VERSION) /*!\brief Destroy a decoder instance * * Destroys a decoder context, freeing any associated memory buffers. * * \param[in] ctx Pointer to this instance's context * * \retval #VPX_DEC_OK * The decoder algorithm initialized. * \retval #VPX_DEC_MEM_ERROR * Memory allocation failed. */ vpx_dec_err_t vpx_dec_destroy(vpx_dec_ctx_t *ctx) DEPRECATED; /*!\brief Get the capabilities of an algorithm. *  James Zern committed Feb 16, 2011 256  * Retrieves the capabilities bitfield from the algorithm's interface.  John Koleszar committed May 18, 2010 257  *  James Zern committed Feb 16, 2011 258  * \param[in] iface Pointer to the algorithm interface  John Koleszar committed May 18, 2010 259 260 261 262 263 264 265 266 267 268 269  * */ vpx_dec_caps_t vpx_dec_get_caps(vpx_dec_iface_t *iface) DEPRECATED; /*!\brief Parse stream info from a buffer * * Performs high level parsing of the bitstream. Construction of a decoder * context is not necessary. Can be used to determine if the bitstream is * of the proper format, and to extract information from the stream. *  James Zern committed Feb 16, 2011 270  * \param[in] iface Pointer to the algorithm interface  John Koleszar committed May 18, 2010 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311  * \param[in] data Pointer to a block of data to parse * \param[in] data_sz Size of the data buffer * \param[in,out] si Pointer to stream info to update. The size member * \ref MUST be properly initialized, but \ref MAY be * clobbered by the algorithm. This parameter \ref MAY * be NULL. * * \retval #VPX_DEC_OK * Bitstream is parsable and stream information updated */ vpx_dec_err_t vpx_dec_peek_stream_info(vpx_dec_iface_t *iface, const uint8_t *data, unsigned int data_sz, vpx_dec_stream_info_t *si) DEPRECATED; /*!\brief Return information about the current stream. * * Returns information about the stream that has been parsed during decoding. * * \param[in] ctx Pointer to this instance's context * \param[in,out] si Pointer to stream info to update. The size member * \ref MUST be properly initialized, but \ref MAY be * clobbered by the algorithm. This parameter \ref MAY * be NULL. * * \retval #VPX_DEC_OK * Bitstream is parsable and stream information updated */ vpx_dec_err_t vpx_dec_get_stream_info(vpx_dec_ctx_t *ctx, vpx_dec_stream_info_t *si) DEPRECATED; /*!\brief Control algorithm * * This function is used to exchange algorithm specific data with the decoder * instance. This can be used to implement features specific to a particular * algorithm. * * This wrapper function dispatches the request to the helper function * associated with the given ctrl_id. It tries to call this function  James Zern committed Feb 16, 2011 312  * transparently, but will return #VPX_DEC_ERROR if the request could not  John Koleszar committed May 18, 2010 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509  * be dispatched. * * \param[in] ctx Pointer to this instance's context * \param[in] ctrl_id Algorithm specific control identifier * \param[in,out] data Data to exchange with algorithm instance. * * \retval #VPX_DEC_OK * The control request was processed. * \retval #VPX_DEC_ERROR * The control request was not processed. * \retval #VPX_DEC_INVALID_PARAM * The data was not valid. */ vpx_dec_err_t vpx_dec_control(vpx_dec_ctx_t *ctx, int ctrl_id, void *data) DEPRECATED; /*!\brief Decode data * * Processes a buffer of coded data. If the processing results in a new * decoded frame becoming available, #VPX_DEC_CB_PUT_SLICE and * #VPX_DEC_CB_PUT_FRAME events may be generated, as appropriate. Encoded data * \ref MUST be passed in DTS (decode time stamp) order. Frames produced will * always be in PTS (presentation time stamp) order. * * \param[in] ctx Pointer to this instance's context * \param[in] data Pointer to this block of new coded data. If * NULL, a VPX_DEC_CB_PUT_FRAME event is posted * for the previously decoded frame. * \param[in] data_sz Size of the coded data, in bytes. * \param[in] user_priv Application specific data to associate with * this frame. * \param[in] rel_pts PTS relative to the previous frame, in us. If * unknown or unavailable, set to zero. * * \return Returns #VPX_DEC_OK if the coded data was processed completely * and future pictures can be decoded without error. Otherwise, * see the descriptions of the other error codes in ::vpx_dec_err_t * for recoverability capabilities. */ vpx_dec_err_t vpx_dec_decode(vpx_dec_ctx_t *ctx, uint8_t *data, unsigned int data_sz, void *user_priv, int rel_pts) DEPRECATED; /*!\brief Decoded frames iterator * * Iterates over a list of the frames available for display. The iterator * storage should be initialized to NULL to start the iteration. Iteration is * complete when this function returns NULL. * * The list of available frames becomes valid upon completion of the * vpx_dec_decode call, and remains valid until the next call to vpx_dec_decode. * * \param[in] ctx Pointer to this instance's context * \param[in out] iter Iterator storage, initialized to NULL * * \return Returns a pointer to an image, if one is ready for display. Frames * produced will always be in PTS (presentation time stamp) order. */ vpx_image_t *vpx_dec_get_frame(vpx_dec_ctx_t *ctx, vpx_dec_iter_t *iter) DEPRECATED; /*!\defgroup cap_put_frame Frame-Based Decoding Functions * * The following functions are required to be implemented for all decoders * that advertise the VPX_DEC_CAP_PUT_FRAME capability. Calling these functions * for codecs that don't advertise this capability will result in an error * code being returned, usually VPX_DEC_ERROR * @{ */ /*!\brief put frame callback prototype * * This callback is invoked by the decoder to notify the application of * the availability of decoded image data. */ typedef void (*vpx_dec_put_frame_cb_fn_t)(void *user_priv, const vpx_image_t *img); /*!\brief Register for notification of frame completion. * * Registers a given function to be called when a decoded frame is * available. * * \param[in] ctx Pointer to this instance's context * \param[in] cb Pointer to the callback function * \param[in] user_priv User's private data * * \retval #VPX_DEC_OK * Callback successfully registered. * \retval #VPX_DEC_ERROR * Decoder context not initialized, or algorithm not capable of * posting slice completion. */ vpx_dec_err_t vpx_dec_register_put_frame_cb(vpx_dec_ctx_t *ctx, vpx_dec_put_frame_cb_fn_t cb, void *user_priv) DEPRECATED; /*!@} - end defgroup cap_put_frame */ /*!\defgroup cap_put_slice Slice-Based Decoding Functions * * The following functions are required to be implemented for all decoders * that advertise the VPX_DEC_CAP_PUT_SLICE capability. Calling these functions * for codecs that don't advertise this capability will result in an error * code being returned, usually VPX_DEC_ERROR * @{ */ /*!\brief put slice callback prototype * * This callback is invoked by the decoder to notify the application of * the availability of partially decoded image data. The */ typedef void (*vpx_dec_put_slice_cb_fn_t)(void *user_priv, const vpx_image_t *img, const vpx_image_rect_t *valid, const vpx_image_rect_t *update); /*!\brief Register for notification of slice completion. * * Registers a given function to be called when a decoded slice is * available. * * \param[in] ctx Pointer to this instance's context * \param[in] cb Pointer to the callback function * \param[in] user_priv User's private data * * \retval #VPX_DEC_OK * Callback successfully registered. * \retval #VPX_DEC_ERROR * Decoder context not initialized, or algorithm not capable of * posting slice completion. */ vpx_dec_err_t vpx_dec_register_put_slice_cb(vpx_dec_ctx_t *ctx, vpx_dec_put_slice_cb_fn_t cb, void *user_priv) DEPRECATED; /*!@} - end defgroup cap_put_slice*/ /*!\defgroup cap_xma External Memory Allocation Functions * * The following functions are required to be implemented for all decoders * that advertise the VPX_DEC_CAP_XMA capability. Calling these functions * for codecs that don't advertise this capability will result in an error * code being returned, usually VPX_DEC_ERROR * @{ */ /*!\brief Memory Map Entry * * This structure is used to contain the properties of a memory segment. It * is populated by the decoder in the request phase, and by the calling * application once the requested allocation has been performed. */ #if 1 #define VPX_DEC_MEM_ZERO 0x1 /**< Segment must be zeroed by allocation */ #define VPX_DEC_MEM_WRONLY 0x2 /**< Segment need not be readable */ #define VPX_DEC_MEM_FAST 0x4 /**< Place in fast memory, if available */ typedef struct vpx_codec_mmap vpx_dec_mmap_t; #else typedef struct vpx_dec_mmap { /* * The following members are set by the codec when requesting a segment */ unsigned int id; /**< identifier for the segment's contents */ unsigned long sz; /**< size of the segment, in bytes */ unsigned int align; /**< required alignment of the segment, in bytes */ unsigned int flags; /**< bitfield containing segment properties */ #define VPX_DEC_MEM_ZERO 0x1 /**< Segment must be zeroed by allocation */ #define VPX_DEC_MEM_WRONLY 0x2 /**< Segment need not be readable */ #define VPX_DEC_MEM_FAST 0x4 /**< Place in fast memory, if available */ /* The following members are to be filled in by the allocation function */ void *base; /**< pointer to the allocated segment */ void (*dtor)(struct vpx_dec_mmap *map); /**< destructor to call */ void *priv; /**< allocator private storage */ } vpx_dec_mmap_t; #endif /*!\brief Initialize a decoder instance in external allocation mode * * Initializes a decoder context using the given interface. Applications * should call the vpx_dec_xma_init convenience macro instead of this * function directly, to ensure that the ABI version number parameter * is properly initialized. * * \param[in] ctx Pointer to this instance's context.  James Zern committed Feb 16, 2011 510  * \param[in] iface Pointer to the algorithm interface to use.  John Koleszar committed May 18, 2010 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560  * \param[in] ver ABI version number. Must be set to * VPX_DECODER_ABI_VERSION * \retval #VPX_DEC_OK * The decoder algorithm initialized. * \retval #VPX_DEC_ERROR * Decoder does not support XMA mode. */ vpx_dec_err_t vpx_dec_xma_init_ver(vpx_dec_ctx_t *ctx, vpx_dec_iface_t *iface, int ver) DEPRECATED; #define vpx_dec_xma_init(ctx, iface) \ vpx_dec_xma_init_ver(ctx, iface, VPX_DECODER_ABI_VERSION) /*!\brief Iterate over the list of segments to allocate. * * Iterates over a list of the segments to allocate. The iterator storage * should be initialized to NULL to start the iteration. Iteration is complete * when this function returns VPX_DEC_LIST_END. The amount of memory needed to * allocate is dependant upon the size of the encoded stream. This means that * the stream info structure must be known at allocation time. It can be * populated with the vpx_dec_peek_stream_info() function. In cases where the * stream to be decoded is not available at allocation time, a fixed size must * be requested. The decoder will not be able to decode streams larger than * the size used at allocation time. * * \param[in] ctx Pointer to this instance's context. * \param[out] mmap Pointer to the memory map entry to populate. * \param[in] si Pointer to the stream info. * \param[in out] iter Iterator storage, initialized to NULL * * \retval #VPX_DEC_OK * The memory map entry was populated. * \retval #VPX_DEC_ERROR * Decoder does not support XMA mode. * \retval #VPX_DEC_MEM_ERROR * Unable to determine segment size from stream info. */ vpx_dec_err_t vpx_dec_get_mem_map(vpx_dec_ctx_t *ctx, vpx_dec_mmap_t *mmap, const vpx_dec_stream_info_t *si, vpx_dec_iter_t *iter) DEPRECATED; /*!\brief Identify allocated segments to decoder instance * * Stores a list of allocated segments in the decoder. Segments \ref MUST be * passed in the order they are read from vpx_dec_get_mem_map(), but may be * passed in groups of any size. Segments \ref MUST be set only once. The * allocation function \ref MUST ensure that the vpx_dec_mmap_t::base member  James Zern committed Feb 16, 2011 561  * is non-NULL. If the segment requires cleanup handling (e.g., calling free()  John Koleszar committed May 18, 2010 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587  * or close()) then the vpx_dec_mmap_t::dtor member \ref MUST be populated. * * \param[in] ctx Pointer to this instance's context. * \param[in] mmaps Pointer to the first memory map entry in the list. * \param[in] num_maps Number of entries being set at this time * * \retval #VPX_DEC_OK * The segment was stored in the decoder context. * \retval #VPX_DEC_ERROR * Decoder does not support XMA mode. * \retval #VPX_DEC_MEM_ERROR * Segment base address was not set, or segment was already stored. */ vpx_dec_err_t vpx_dec_set_mem_map(vpx_dec_ctx_t *ctx, vpx_dec_mmap_t *mmaps, unsigned int num_maps) DEPRECATED; /*!@} - end defgroup cap_xma*/ /*!@} - end defgroup decoder*/ #endif #ifdef __cplusplus } #endif