+static inline void
+u_copy_yv12_to_nv12(void *const *destination_data,
+ uint32_t const *destination_pitches,
+ int src_plane, int src_field,
+ int src_stride, int num_fields,
+ uint8_t const *src,
+ int width, int height)
+{
+ int x, y;
+ unsigned offset = 2 - src_plane;
+ unsigned stride = destination_pitches[1] * num_fields;
+ uint8_t *dst = (uint8_t *)destination_data[1] + destination_pitches[1] * src_field;
+
+ /* TODO: SIMD */
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < 2 * width; x += 2) {
+ dst[x+offset] = src[x>>1];
+ }
+ dst += stride;
+ src += src_stride;
+ }
+}
+
+static inline void
+u_copy_swap422_packed(void *const *destination_data,
+ uint32_t const *destination_pitches,
+ int src_plane, int src_field,
+ int src_stride, int num_fields,
+ uint8_t const *src,
+ int width, int height)
+{
+ int x, y;
+ unsigned stride = destination_pitches[0] * num_fields;
+ uint8_t *dst = (uint8_t *)destination_data[0] + destination_pitches[0] * src_field;
+
+ /* TODO: SIMD */
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < 4 * width; x += 4) {
+ dst[x+0] = src[x+1];
+ dst[x+1] = src[x+0];
+ dst[x+2] = src[x+3];
+ dst[x+3] = src[x+2];
+ }
+ dst += stride;
+ src += src_stride;
+ }
+}
+
+static inline uint32_t
+u_get_h264_level(uint32_t width, uint32_t height, uint32_t *max_reference)
+{
+ uint32_t max_dpb_mbs;
+
+ width = align(width, 16);
+ height = align(height, 16);
+
+ /* Max references will be used for caculation of number of DPB buffers
+ in the UVD driver, limitation of max references is 16. Some client
+ like mpv application for VA-API, it requires references more than that,
+ so we have to set max of references to 16 here. */
+ *max_reference = MIN2(*max_reference, 16);
+ max_dpb_mbs = (width / 16) * (height / 16) * *max_reference;
+
+ /* The calculation is based on "Decoded picture buffering" section
+ from http://en.wikipedia.org/wiki/H.264/MPEG-4_AVC */
+ if (max_dpb_mbs <= 8100)
+ return 30;
+ else if (max_dpb_mbs <= 18000)
+ return 31;
+ else if (max_dpb_mbs <= 20480)
+ return 32;
+ else if (max_dpb_mbs <= 32768)
+ return 41;
+ else if (max_dpb_mbs <= 34816)
+ return 42;
+ else if (max_dpb_mbs <= 110400)
+ return 50;
+ else if (max_dpb_mbs <= 184320)
+ return 51;
+ else
+ return 52;
+}
+
+#ifdef __cplusplus
+}
+#endif
+