1*fb1b10abSAndroid Build Coastguard Worker/*!\page usage Usage 2*fb1b10abSAndroid Build Coastguard Worker 3*fb1b10abSAndroid Build Coastguard Worker The vpx multi-format codec SDK provides a unified interface amongst its 4*fb1b10abSAndroid Build Coastguard Worker supported codecs. This abstraction allows applications using this SDK to 5*fb1b10abSAndroid Build Coastguard Worker easily support multiple video formats with minimal code duplication or 6*fb1b10abSAndroid Build Coastguard Worker "special casing." This section describes the interface common to all codecs. 7*fb1b10abSAndroid Build Coastguard Worker For codec-specific details, see the \ref codecs page. 8*fb1b10abSAndroid Build Coastguard Worker 9*fb1b10abSAndroid Build Coastguard Worker The following sections are common to all codecs: 10*fb1b10abSAndroid Build Coastguard Worker - \ref usage_types 11*fb1b10abSAndroid Build Coastguard Worker - \ref usage_features 12*fb1b10abSAndroid Build Coastguard Worker - \ref usage_init 13*fb1b10abSAndroid Build Coastguard Worker - \ref usage_errors 14*fb1b10abSAndroid Build Coastguard Worker 15*fb1b10abSAndroid Build Coastguard Worker For more information on decoder and encoder specific usage, see the 16*fb1b10abSAndroid Build Coastguard Worker following pages: 17*fb1b10abSAndroid Build Coastguard Worker \if decoder 18*fb1b10abSAndroid Build Coastguard Worker \li \subpage usage_decode 19*fb1b10abSAndroid Build Coastguard Worker \endif 20*fb1b10abSAndroid Build Coastguard Worker \if encoder 21*fb1b10abSAndroid Build Coastguard Worker \li \subpage usage_encode 22*fb1b10abSAndroid Build Coastguard Worker \endif 23*fb1b10abSAndroid Build Coastguard Worker 24*fb1b10abSAndroid Build Coastguard Worker \section usage_types Important Data Types 25*fb1b10abSAndroid Build Coastguard Worker There are two important data structures to consider in this interface. 26*fb1b10abSAndroid Build Coastguard Worker 27*fb1b10abSAndroid Build Coastguard Worker \subsection usage_ctxs Contexts 28*fb1b10abSAndroid Build Coastguard Worker A context is a storage area allocated by the calling application that the 29*fb1b10abSAndroid Build Coastguard Worker codec may write into to store details about a single instance of that codec. 30*fb1b10abSAndroid Build Coastguard Worker Most of the context is implementation specific, and thus opaque to the 31*fb1b10abSAndroid Build Coastguard Worker application. The context structure as seen by the application is of fixed 32*fb1b10abSAndroid Build Coastguard Worker size, and thus can be allocated with automatic storage or dynamically 33*fb1b10abSAndroid Build Coastguard Worker on the heap. 34*fb1b10abSAndroid Build Coastguard Worker 35*fb1b10abSAndroid Build Coastguard Worker Most operations require an initialized codec context. Codec context 36*fb1b10abSAndroid Build Coastguard Worker instances are codec specific. That is, the codec to be used for the encoded 37*fb1b10abSAndroid Build Coastguard Worker video must be known at initialization time. See #vpx_codec_ctx_t for further 38*fb1b10abSAndroid Build Coastguard Worker information. 39*fb1b10abSAndroid Build Coastguard Worker 40*fb1b10abSAndroid Build Coastguard Worker \subsection usage_ifaces Interfaces 41*fb1b10abSAndroid Build Coastguard Worker A codec interface is an opaque structure that controls how function calls 42*fb1b10abSAndroid Build Coastguard Worker into the generic interface are dispatched to their codec-specific 43*fb1b10abSAndroid Build Coastguard Worker implementations. Applications \ref MUSTNOT attempt to examine or override 44*fb1b10abSAndroid Build Coastguard Worker this storage, as it contains internal implementation details likely to 45*fb1b10abSAndroid Build Coastguard Worker change from release to release. 46*fb1b10abSAndroid Build Coastguard Worker 47*fb1b10abSAndroid Build Coastguard Worker Each supported codec will expose an interface structure to the application 48*fb1b10abSAndroid Build Coastguard Worker as an <code>extern</code> reference to a structure of the incomplete type 49*fb1b10abSAndroid Build Coastguard Worker #vpx_codec_iface_t. 50*fb1b10abSAndroid Build Coastguard Worker 51*fb1b10abSAndroid Build Coastguard Worker \section usage_features Features 52*fb1b10abSAndroid Build Coastguard Worker Several "features" are defined that are optionally implemented by codec 53*fb1b10abSAndroid Build Coastguard Worker algorithms. Indeed, the same algorithm may support different features on 54*fb1b10abSAndroid Build Coastguard Worker different platforms. The purpose of defining these features is that when 55*fb1b10abSAndroid Build Coastguard Worker they are implemented, they conform to a common interface. The features, or 56*fb1b10abSAndroid Build Coastguard Worker capabilities, of an algorithm can be queried from it's interface by using 57*fb1b10abSAndroid Build Coastguard Worker the vpx_codec_get_caps() method. Attempts to invoke features not supported 58*fb1b10abSAndroid Build Coastguard Worker by an algorithm will generally result in #VPX_CODEC_INCAPABLE. 59*fb1b10abSAndroid Build Coastguard Worker 60*fb1b10abSAndroid Build Coastguard Worker \if decoder 61*fb1b10abSAndroid Build Coastguard Worker Currently defined decoder features include: 62*fb1b10abSAndroid Build Coastguard Worker - \ref usage_cb 63*fb1b10abSAndroid Build Coastguard Worker - \ref usage_postproc 64*fb1b10abSAndroid Build Coastguard Worker \endif 65*fb1b10abSAndroid Build Coastguard Worker 66*fb1b10abSAndroid Build Coastguard Worker \section usage_init Initialization 67*fb1b10abSAndroid Build Coastguard Worker To initialize a codec instance, the address of the codec context 68*fb1b10abSAndroid Build Coastguard Worker and interface structures are passed to an initialization function. Depending 69*fb1b10abSAndroid Build Coastguard Worker on the \ref usage_features that the codec supports, the codec could be 70*fb1b10abSAndroid Build Coastguard Worker initialized in different modes. 71*fb1b10abSAndroid Build Coastguard Worker 72*fb1b10abSAndroid Build Coastguard Worker To prevent cases of confusion where the ABI of the library changes, 73*fb1b10abSAndroid Build Coastguard Worker the ABI is versioned. The ABI version number must be passed at 74*fb1b10abSAndroid Build Coastguard Worker initialization time to ensure the application is using a header file that 75*fb1b10abSAndroid Build Coastguard Worker matches the library. The current ABI version number is stored in the 76*fb1b10abSAndroid Build Coastguard Worker preprocessor macros #VPX_CODEC_ABI_VERSION, #VPX_ENCODER_ABI_VERSION, and 77*fb1b10abSAndroid Build Coastguard Worker #VPX_DECODER_ABI_VERSION. For convenience, each initialization function has 78*fb1b10abSAndroid Build Coastguard Worker a wrapper macro that inserts the correct version number. These macros are 79*fb1b10abSAndroid Build Coastguard Worker named like the initialization methods, but without the _ver suffix. 80*fb1b10abSAndroid Build Coastguard Worker 81*fb1b10abSAndroid Build Coastguard Worker 82*fb1b10abSAndroid Build Coastguard Worker The available initialization methods are: 83*fb1b10abSAndroid Build Coastguard Worker \if encoder 84*fb1b10abSAndroid Build Coastguard Worker \li #vpx_codec_enc_init (calls vpx_codec_enc_init_ver()) 85*fb1b10abSAndroid Build Coastguard Worker \li #vpx_codec_enc_init_multi (calls vpx_codec_enc_init_multi_ver()) 86*fb1b10abSAndroid Build Coastguard Worker \endif 87*fb1b10abSAndroid Build Coastguard Worker \if decoder 88*fb1b10abSAndroid Build Coastguard Worker \li #vpx_codec_dec_init (calls vpx_codec_dec_init_ver()) 89*fb1b10abSAndroid Build Coastguard Worker \endif 90*fb1b10abSAndroid Build Coastguard Worker 91*fb1b10abSAndroid Build Coastguard Worker 92*fb1b10abSAndroid Build Coastguard Worker \section usage_errors Error Handling 93*fb1b10abSAndroid Build Coastguard Worker Almost all codec functions return an error status of type #vpx_codec_err_t. 94*fb1b10abSAndroid Build Coastguard Worker The semantics of how each error condition should be processed is clearly 95*fb1b10abSAndroid Build Coastguard Worker defined in the definitions of each enumerated value. Error values can be 96*fb1b10abSAndroid Build Coastguard Worker converted into ASCII strings with the vpx_codec_error() and 97*fb1b10abSAndroid Build Coastguard Worker vpx_codec_err_to_string() methods. The difference between these two methods is 98*fb1b10abSAndroid Build Coastguard Worker that vpx_codec_error() returns the error state from an initialized context, 99*fb1b10abSAndroid Build Coastguard Worker whereas vpx_codec_err_to_string() can be used in cases where an error occurs 100*fb1b10abSAndroid Build Coastguard Worker outside any context. The enumerated value returned from the last call can be 101*fb1b10abSAndroid Build Coastguard Worker retrieved from the <code>err</code> member of the decoder context as well. 102*fb1b10abSAndroid Build Coastguard Worker Finally, more detailed error information may be able to be obtained by using 103*fb1b10abSAndroid Build Coastguard Worker the vpx_codec_error_detail() method. Not all errors produce detailed error 104*fb1b10abSAndroid Build Coastguard Worker information. 105*fb1b10abSAndroid Build Coastguard Worker 106*fb1b10abSAndroid Build Coastguard Worker In addition to error information, the codec library's build configuration 107*fb1b10abSAndroid Build Coastguard Worker is available at runtime on some platforms. This information can be returned 108*fb1b10abSAndroid Build Coastguard Worker by calling vpx_codec_build_config(), and is formatted as a base64 coded string 109*fb1b10abSAndroid Build Coastguard Worker (comprised of characters in the set [a-z_a-Z0-9+/]). This information is not 110*fb1b10abSAndroid Build Coastguard Worker useful to an application at runtime, but may be of use to vpx for support. 111*fb1b10abSAndroid Build Coastguard Worker 112*fb1b10abSAndroid Build Coastguard Worker 113*fb1b10abSAndroid Build Coastguard Worker \section usage_deadline Deadline 114*fb1b10abSAndroid Build Coastguard Worker Both the encoding and decoding functions have a <code>deadline</code> 115*fb1b10abSAndroid Build Coastguard Worker parameter. This parameter indicates the amount of time, in microseconds 116*fb1b10abSAndroid Build Coastguard Worker (us), that the application wants the codec to spend processing before 117*fb1b10abSAndroid Build Coastguard Worker returning. This is a soft deadline -- that is, the semantics of the 118*fb1b10abSAndroid Build Coastguard Worker requested operation take precedence over meeting the deadline. If, for 119*fb1b10abSAndroid Build Coastguard Worker example, an application sets a <code>deadline</code> of 1000us, and the 120*fb1b10abSAndroid Build Coastguard Worker frame takes 2000us to decode, the call to vpx_codec_decode() will return 121*fb1b10abSAndroid Build Coastguard Worker after 2000us. In this case the deadline is not met, but the semantics of the 122*fb1b10abSAndroid Build Coastguard Worker function are preserved. If, for the same frame, an application instead sets 123*fb1b10abSAndroid Build Coastguard Worker a <code>deadline</code> of 5000us, the decoder will see that it has 3000us 124*fb1b10abSAndroid Build Coastguard Worker remaining in its time slice when decoding completes. It could then choose to 125*fb1b10abSAndroid Build Coastguard Worker run a set of \ref usage_postproc filters, and perhaps would return after 126*fb1b10abSAndroid Build Coastguard Worker 4000us (instead of the allocated 5000us). In this case the deadline is met, 127*fb1b10abSAndroid Build Coastguard Worker and the semantics of the call are preserved, as before. 128*fb1b10abSAndroid Build Coastguard Worker 129*fb1b10abSAndroid Build Coastguard Worker The special value <code>0</code> is reserved to represent an infinite 130*fb1b10abSAndroid Build Coastguard Worker deadline. In this case, the codec will perform as much processing as 131*fb1b10abSAndroid Build Coastguard Worker possible to yield the highest quality frame. 132*fb1b10abSAndroid Build Coastguard Worker 133*fb1b10abSAndroid Build Coastguard Worker By convention, the value <code>1</code> is used to mean "return as fast as 134*fb1b10abSAndroid Build Coastguard Worker possible." 135*fb1b10abSAndroid Build Coastguard Worker 136*fb1b10abSAndroid Build Coastguard Worker*/ 137