#ifndef U_VIDEO_H
#define U_VIDEO_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#include "pipe/p_defines.h"
#include "pipe/p_video_enums.h"
/* u_reduce_video_profile() needs these */
#include "pipe/p_compiler.h"
#include "util/u_debug.h"
+#include "util/u_math.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
-static INLINE enum pipe_video_format
+static inline enum pipe_video_format
u_reduce_video_profile(enum pipe_video_profile profile)
{
switch (profile)
return PIPE_VIDEO_FORMAT_VC1;
case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
+ case PIPE_VIDEO_PROFILE_MPEG4_AVC_CONSTRAINED_BASELINE:
case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN:
case PIPE_VIDEO_PROFILE_MPEG4_AVC_EXTENDED:
case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH:
case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH444:
return PIPE_VIDEO_FORMAT_MPEG4_AVC;
+ case PIPE_VIDEO_PROFILE_HEVC_MAIN:
+ case PIPE_VIDEO_PROFILE_HEVC_MAIN_10:
+ case PIPE_VIDEO_PROFILE_HEVC_MAIN_STILL:
+ case PIPE_VIDEO_PROFILE_HEVC_MAIN_12:
+ case PIPE_VIDEO_PROFILE_HEVC_MAIN_444:
+ return PIPE_VIDEO_FORMAT_HEVC;
+
default:
return PIPE_VIDEO_FORMAT_UNKNOWN;
}
}
-static INLINE void
+static inline void
u_copy_nv12_to_yv12(void *const *destination_data,
uint32_t const *destination_pitches,
int src_plane, int src_field,
}
}
-static INLINE void
+/**
+ * \brief Copy YV12 chroma data while converting it NV12
+ *
+ * Given a set of YV12 source pointers and -pitches, copy the data to a
+ * layout typical for NV12 video buffers.
+ *
+ * \param source data[in] The plane data pointers. Array of 3.
+ * \param source_pitches[in] The plane pitches. Array of 3.
+ * \param dst_plane[in] The destination plane to copy to. For NV12 always 1.
+ * \param dst_field[in] The destination field if interlaced.
+ * \param dst_stride[in] The destination stride for this plane.
+ * \param num_fields[in] The number of fields in the video buffer.
+ * \param dst[in] The destination plane pointer.
+ * \param width[in] The source plane width.
+ * \param height[in] The source plane height.
+ */
+static inline void
+u_copy_nv12_from_yv12(const void *const *source_data,
+ uint32_t const *source_pitches,
+ int dst_plane, int dst_field,
+ int dst_stride, int num_fields,
+ uint8_t *dst,
+ int width, int height)
+{
+ int x, y;
+ unsigned u_stride = source_pitches[2] * num_fields;
+ unsigned v_stride = source_pitches[1] * num_fields;
+ uint8_t *u_src = (uint8_t *)source_data[2] + source_pitches[2] * dst_field;
+ uint8_t *v_src = (uint8_t *)source_data[1] + source_pitches[1] * dst_field;
+
+ /* TODO: SIMD */
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
+ dst[2*x] = u_src[x];
+ dst[2*x+1] = v_src[x];
+ }
+ u_src += u_stride;
+ v_src += v_stride;
+ dst += dst_stride;
+ }
+}
+
+static inline void
u_copy_yv12_to_nv12(void *const *destination_data,
uint32_t const *destination_pitches,
int src_plane, int src_field,
}
}
-static INLINE void
+static inline void
u_copy_swap422_packed(void *const *destination_data,
uint32_t const *destination_pitches,
int src_plane, int src_field,
}
}
+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