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.
9 The following sections are common to all codecs:
15 Fore more information on decoder and encoder specific usage, see the
17 \if decoder - \subpage usage_decode \endif
18 \if decoder - \subpage usage_encode \endif
20 \section usage_types Important Data Types
21 There are two important data structures to consider in this interface.
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
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
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.
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
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.
56 Currently defined features available in both encoders and decoders include:
60 Currently defined decoder features include:
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.
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.
83 The available initialization methods are:
84 \if encoder - #vpx_codec_enc_init (calls vpx_codec_enc_init_ver()) \endif
85 \if multi-encoder - #vpx_codec_enc_init_multi (calls vpx_codec_enc_init_multi_ver()) \endif
86 \if decoder - #vpx_codec_dec_init (calls vpx_codec_dec_init_ver()) \endif
90 \section usage_errors Error Handling
91 Almost all codec functions return an error status of type #vpx_codec_err_t.
92 The semantics of how each error condition should be processed is clearly
93 defined in the definitions of each enumerated value. Error values can be
94 converted into ASCII strings with the vpx_codec_error() and
95 vpx_codec_err_to_string() methods. The difference between these two methods is
96 that vpx_codec_error() returns the error state from an initialized context,
97 whereas vpx_codec_err_to_string() can be used in cases where an error occurs
98 outside any context. The enumerated value returned from the last call can be
99 retrieved from the <code>err</code> member of the decoder context as well.
100 Finally, more detailed error information may be able to be obtained by using
101 the vpx_codec_error_detail() method. Not all errors produce detailed error
104 In addition to error information, the codec library's build configuration
105 is available at runtime on some platforms. This information can be returned
106 by calling vpx_codec_build_config(), and is formatted as a base64 coded string
107 (comprised of characters in the set [a-z_a-Z0-9+/]). This information is not
108 useful to an application at runtime, but may be of use to vpx for support.
111 \section usage_deadline Deadline
112 Both the encoding and decoding functions have a <code>deadline</code>
113 parameter. This parameter indicates the amount of time, in microseconds
114 (us), that the application wants the codec to spend processing before
115 returning. This is a soft deadline -- that is, the semantics of the
116 requested operation take precedence over meeting the deadline. If, for
117 example, an application sets a <code>deadline</code> of 1000us, and the
118 frame takes 2000us to decode, the call to vpx_codec_decode() will return
119 after 2000us. In this case the deadline is not met, but the semantics of the
120 function are preserved. If, for the same frame, an application instead sets
121 a <code>deadline</code> of 5000us, the decoder will see that it has 3000us
122 remaining in its time slice when decoding completes. It could then choose to
123 run a set of \ref usage_postproc filters, and perhaps would return after
124 4000us (instead of the allocated 5000us). In this case the deadline is met,
125 and the semantics of the call are preserved, as before.
127 The special value <code>0</code> is reserved to represent an infinite
128 deadline. In this case, the codec will perform as much processing as
129 possible to yield the highest quality frame.
131 By convention, the value <code>1</code> is used to mean "return as fast as
137 /*! \page usage_xma External Memory Allocation
138 Applications that wish to have fine grained control over how and where
139 decoders allocate memory \ref MAY make use of the eXternal Memory Allocation
140 (XMA) interface. Not all codecs support the XMA \ref usage_features.
142 To use a decoder in XMA mode, the decoder \ref MUST be initialized with the
143 vpx_codec_xma_init_ver() function. The amount of memory a decoder needs to
144 allocate is heavily dependent on the size of the encoded video frames. The
145 size of the video must be known before requesting the decoder's memory map.
146 This stream information can be obtained with the vpx_codec_peek_stream_info()
147 function, which does not require a constructed decoder context. If the exact
148 stream is not known, a stream info structure can be created that reflects
149 the maximum size that the decoder instance is required to support.
151 Once the decoder instance has been initialized and the stream information
152 determined, the application calls the vpx_codec_get_mem_map() iterator
153 repeatedly to get a list of the memory segments requested by the decoder.
154 The iterator value should be initialized to NULL to request the first
155 element, and the function will return #VPX_CODEC_LIST_END to signal the end of
158 After each segment is identified, it must be passed to the codec through the
159 vpx_codec_set_mem_map() function. Segments \ref MUST be passed in the same
160 order as they are returned from vpx_codec_get_mem_map(), but there is no
161 requirement that vpx_codec_get_mem_map() must finish iterating before
162 vpx_codec_set_mem_map() is called. For instance, some applications may choose
163 to get a list of all requests, construct an optimal heap, and then set all
164 maps at once with one call. Other applications may set one map at a time,
165 allocating it immediately after it is returned from vpx_codec_get_mem_map().
167 After all segments have been set using vpx_codec_set_mem_map(), the codec may
168 be used as it would be in normal internal allocation mode.
170 \section usage_xma_seg_id Segment Identifiers
171 Each requested segment is identified by an identifier unique to
172 that decoder type. Some of these identifiers are private, while others are
173 enumerated for application use. Identifiers not enumerated publicly are
174 subject to change. Identifiers are non-consecutive.
176 \section usage_xma_seg_szalign Segment Size and Alignment
177 The sz (size) and align (alignment) parameters describe the required size
178 and alignment of the requested segment. Alignment will always be a power of
179 two. Applications \ref MUST honor the alignment requested. Failure to do so
180 could result in program crashes or may incur a speed penalty.
182 \section usage_xma_seg_flags Segment Flags
183 The flags member of the segment structure indicates any requirements or
184 desires of the codec for the particular segment. The #VPX_CODEC_MEM_ZERO flag
185 indicates that the segment \ref MUST be zeroed by the application prior to
186 passing it to the application. The #VPX_CODEC_MEM_WRONLY flag indicates that
187 the segment will only be written into by the decoder, not read. If this flag
188 is not set, the application \ref MUST insure that the memory segment is
189 readable. On some platforms, framebuffer memory is writable but not
190 readable, for example. The #VPX_CODEC_MEM_FAST flag indicates that the segment
191 will be frequently accessed, and that it should be placed into fast memory,
192 if any is available. The application \ref MAY choose to place other segments
193 in fast memory as well, but the most critical segments will be identified by
196 \section usage_xma_seg_basedtor Segment Base Address and Destructor
197 For each requested memory segment, the application must determine the
198 address of a memory segment that meets the requirements of the codec. This
199 address is set in the <code>base</code> member of the #vpx_codec_mmap
200 structure. If the application requires processing when the segment is no
201 longer used by the codec (for instance to deallocate it or close an
202 associated file descriptor) the <code>dtor</code> and <code>priv</code>