1/*!\page usage Usage 2 3 The vpx Multi-Format codec SDK provides a unified interface amongst its 4 supported codecs. This abstraction allows applications using this SDK to 5 easily support multiple video formats with minimal code duplication or 6 "special casing." This section describes the interface common to all codecs. 7 For codec-specific details, see the \ref codecs page. 8 9 The following sections are common to all codecs: 10 - \ref usage_types 11 - \ref usage_features 12 - \ref usage_init 13 - \ref usage_errors 14 15 Fore more information on decoder and encoder specific usage, see the 16 following pages: 17 \if decoder - \subpage usage_decode \endif 18 \if decoder - \subpage usage_encode \endif 19 20 \section usage_types Important Data Types 21 There are two important data structures to consider in this interface. 22 23 \subsection usage_ctxs Contexts 24 A context is a storage area allocated by the calling application that the 25 codec may write into to store details about a single instance of that codec. 26 Most of the context is implementation specific, and thus opaque to the 27 application. The context structure as seen by the application is of fixed 28 size, and thus can be allocated with automatic storage or dynamically 29 on the heap. 30 31 Most operations require an initialized codec context. Codec context 32 instances are codec specific. That is, the codec to be used for the encoded 33 video must be known at initialization time. See #vpx_codec_ctx_t for further 34 information. 35 36 \subsection usage_ifaces Interfaces 37 A codec interface is an opaque structure that controls how function calls 38 into the generic interface are dispatched to their codec-specific 39 implementations. Applications \ref MUSTNOT attempt to examine or override 40 this storage, as it contains internal implementation details likely to 41 change from release to release. 42 43 Each supported codec will expose an interface structure to the application 44 as an <code>extern</code> reference to a structure of the incomplete type 45 #vpx_codec_iface_t. 46 47 \section usage_features Features 48 Several "features" are defined that are optionally implemented by codec 49 algorithms. Indeed, the same algorithm may support different features on 50 different platforms. The purpose of defining these features is that when 51 they are implemented, they conform to a common interface. The features, or 52 capabilities, of an algorithm can be queried from it's interface by using 53 the vpx_codec_get_caps() method. Attempts to invoke features not supported 54 by an algorithm will generally result in #VPX_CODEC_INCAPABLE. 55 56 Currently defined features available in both encoders and decoders include: 57 - \subpage usage_xma 58 59 \if decoder 60 Currently defined decoder features include: 61 - \ref usage_cb 62 - \ref usage_postproc 63 \endif 64 65 \section usage_init Initialization 66 To initialize a codec instance, the address of the codec context 67 and interface structures are passed to an initialization function. Depending 68 on the \ref usage_features that the codec supports, the codec could be 69 initialized in different modes. Most notably, the application may choose to 70 use \ref usage_xma mode to gain fine grained control over how and where 71 memory is allocated for the codec. 72 73 To prevent cases of confusion where the ABI of the library changes, 74 the ABI is versioned. The ABI version number must be passed at 75 initialization time to ensure the application is using a header file that 76 matches the library. The current ABI version number is stored in the 77 preprocessor macros #VPX_CODEC_ABI_VERSION, #VPX_ENCODER_ABI_VERSION, and 78 #VPX_DECODER_ABI_VERSION. For convenience, each initialization function has 79 a wrapper macro that inserts the correct version number. These macros are 80 named like the initialization methods, but without the _ver suffix. 81 82 83 The available initialization methods are: 84 \if encoder - #vpx_codec_enc_init (calls vpx_codec_enc_init_ver()) \endif 85 \if decoder - #vpx_codec_dec_init (calls vpx_codec_dec_init_ver()) \endif 86 87 88 89 \section usage_errors Error Handling 90 Almost all codec functions return an error status of type #vpx_codec_err_t. 91 The semantics of how each error condition should be processed is clearly 92 defined in the definitions of each enumerated value. Error values can be 93 converted into ASCII strings with the vpx_codec_error() and 94 vpx_codec_err_to_string() methods. The difference between these two methods is 95 that vpx_codec_error() returns the error state from an initialized context, 96 whereas vpx_codec_err_to_string() can be used in cases where an error occurs 97 outside any context. The enumerated value returned from the last call can be 98 retrieved from the <code>err</code> member of the decoder context as well. 99 Finally, more detailed error information may be able to be obtained by using 100 the vpx_codec_error_detail() method. Not all errors produce detailed error 101 information. 102 103 In addition to error information, the codec library's build configuration 104 is available at runtime on some platforms. This information can be returned 105 by calling vpx_codec_build_config(), and is formatted as a base64 coded string 106 (comprised of characters in the set [a-z_a-Z0-9+/]). This information is not 107 useful to an application at runtime, but may be of use to vpx for support. 108 109 110 \section usage_deadline Deadline 111 Both the encoding and decoding functions have a <code>deadline</code> 112 parameter. This parameter indicates the amount of time, in microseconds 113 (us), that the application wants the codec to spend processing before 114 returning. This is a soft deadline -- that is, the semantics of the 115 requested operation take precedence over meeting the deadline. If, for 116 example, an application sets a <code>deadline</code> of 1000us, and the 117 frame takes 2000us to decode, the call to vpx_codec_decode() will return 118 after 2000us. In this case the deadline is not met, but the semantics of the 119 function are preserved. If, for the same frame, an application instead sets 120 a <code>deadline</code> of 5000us, the decoder will see that it has 3000us 121 remaining in its time slice when decoding completes. It could then choose to 122 run a set of \ref usage_postproc filters, and perhaps would return after 123 4000us (instead of the allocated 5000us). In this case the deadline is met, 124 and the semantics of the call are preserved, as before. 125 126 The special value <code>0</code> is reserved to represent an infinite 127 deadline. In this case, the codec will perform as much processing as 128 possible to yield the highest quality frame. 129 130 By convention, the value <code>1</code> is used to mean "return as fast as 131 possible." 132 133*/ 134 135 136/*! \page usage_xma External Memory Allocation 137 Applications that wish to have fine grained control over how and where 138 decoders allocate memory \ref MAY make use of the eXternal Memory Allocation 139 (XMA) interface. Not all codecs support the XMA \ref usage_features. 140 141 To use a decoder in XMA mode, the decoder \ref MUST be initialized with the 142 vpx_codec_xma_init_ver() function. The amount of memory a decoder needs to 143 allocate is heavily dependent on the size of the encoded video frames. The 144 size of the video must be known before requesting the decoder's memory map. 145 This stream information can be obtained with the vpx_codec_peek_stream_info() 146 function, which does not require a constructed decoder context. If the exact 147 stream is not known, a stream info structure can be created that reflects 148 the maximum size that the decoder instance is required to support. 149 150 Once the decoder instance has been initialized and the stream information 151 determined, the application calls the vpx_codec_get_mem_map() iterator 152 repeatedly to get a list of the memory segments requested by the decoder. 153 The iterator value should be initialized to NULL to request the first 154 element, and the function will return #VPX_CODEC_LIST_END to signal the end of 155 the list. 156 157 After each segment is identified, it must be passed to the codec through the 158 vpx_codec_set_mem_map() function. Segments \ref MUST be passed in the same 159 order as they are returned from vpx_codec_get_mem_map(), but there is no 160 requirement that vpx_codec_get_mem_map() must finish iterating before 161 vpx_codec_set_mem_map() is called. For instance, some applications may choose 162 to get a list of all requests, construct an optimal heap, and then set all 163 maps at once with one call. Other applications may set one map at a time, 164 allocating it immediately after it is returned from vpx_codec_get_mem_map(). 165 166 After all segments have been set using vpx_codec_set_mem_map(), the codec may 167 be used as it would be in normal internal allocation mode. 168 169 \section usage_xma_seg_id Segment Identifiers 170 Each requested segment is identified by an identifier unique to 171 that decoder type. Some of these identifiers are private, while others are 172 enumerated for application use. Identifiers not enumerated publicly are 173 subject to change. Identifiers are non-consecutive. 174 175 \section usage_xma_seg_szalign Segment Size and Alignment 176 The sz (size) and align (alignment) parameters describe the required size 177 and alignment of the requested segment. Alignment will always be a power of 178 two. Applications \ref MUST honor the alignment requested. Failure to do so 179 could result in program crashes or may incur a speed penalty. 180 181 \section usage_xma_seg_flags Segment Flags 182 The flags member of the segment structure indicates any requirements or 183 desires of the codec for the particular segment. The #VPX_CODEC_MEM_ZERO flag 184 indicates that the segment \ref MUST be zeroed by the application prior to 185 passing it to the application. The #VPX_CODEC_MEM_WRONLY flag indicates that 186 the segment will only be written into by the decoder, not read. If this flag 187 is not set, the application \ref MUST insure that the memory segment is 188 readable. On some platforms, framebuffer memory is writable but not 189 readable, for example. The #VPX_CODEC_MEM_FAST flag indicates that the segment 190 will be frequently accessed, and that it should be placed into fast memory, 191 if any is available. The application \ref MAY choose to place other segments 192 in fast memory as well, but the most critical segments will be identified by 193 this flag. 194 195 \section usage_xma_seg_basedtor Segment Base Address and Destructor 196 For each requested memory segment, the application must determine the 197 address of a memory segment that meets the requirements of the codec. This 198 address is set in the <code>base</code> member of the #vpx_codec_mmap 199 structure. If the application requires processing when the segment is no 200 longer used by the codec (for instance to deallocate it or close an 201 associated file descriptor) the <code>dtor</code> and <code>priv</code> 202 members can be set. 203*/ 204