util: Move u_debug to utils
[mesa.git] / src / gallium / auxiliary / util / u_video.h
index 7e743de253ec695d5baddb44e4df2cb3f6f0cac6..f6e93dd03872a471230b53e821d6b48b8170493b 100644 (file)
@@ -60,6 +60,7 @@ u_reduce_video_profile(enum pipe_video_profile 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:
@@ -75,6 +76,13 @@ u_reduce_video_profile(enum pipe_video_profile profile)
       case PIPE_VIDEO_PROFILE_HEVC_MAIN_444:
          return PIPE_VIDEO_FORMAT_HEVC;
 
+      case PIPE_VIDEO_PROFILE_JPEG_BASELINE:
+         return PIPE_VIDEO_FORMAT_JPEG;
+
+      case PIPE_VIDEO_PROFILE_VP9_PROFILE0:
+      case PIPE_VIDEO_PROFILE_VP9_PROFILE2:
+         return PIPE_VIDEO_FORMAT_VP9;
+
       default:
          return PIPE_VIDEO_FORMAT_UNKNOWN;
    }
@@ -106,6 +114,48 @@ u_copy_nv12_to_yv12(void *const *destination_data,
    }
 }
 
+/**
+ * \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,
@@ -129,43 +179,6 @@ u_copy_yv12_to_nv12(void *const *destination_data,
    }
 }
 
-static inline void
-u_copy_yv12_img_to_nv12_surf(ubyte *const *src,
-                             ubyte *dst,
-                             unsigned width,
-                             unsigned height,
-                             unsigned src_stride,
-                             unsigned dst_stride,
-                             int field)
-{
-   if (field == 0) {
-      ubyte *src_0 = src[field];
-      for (int i = 0; i < height ; i++) {
-         memcpy(dst, src_0, width);
-         dst += dst_stride;
-         src_0 += src_stride;
-      }
-   } else if (field == 1) {
-      const ubyte *src_1 = src[field];
-      const ubyte *src_2 = src[field+1];
-      bool odd = false;
-      for (unsigned i = 0; i < height ; i++) {
-         for (unsigned j = 0; j < width*2 ; j++) {
-            if (odd == false) {
-               dst[j] = src_1[j/2];
-               odd = true;
-            } else {
-               dst[j] = src_2[j/2];
-               odd = false;
-            }
-         }
-         dst += dst_stride;
-         src_1 += src_stride;
-         src_2 += src_stride;
-      }
-   }
-}
-
 static inline void
 u_copy_swap422_packed(void *const *destination_data,
                        uint32_t const *destination_pitches,
@@ -226,6 +239,30 @@ u_get_h264_level(uint32_t width, uint32_t height, uint32_t *max_reference)
       return 52;
 }
 
+static inline uint32_t
+u_get_h264_profile_idc(enum pipe_video_profile profile)
+{
+   switch (profile) {
+      case PIPE_VIDEO_PROFILE_MPEG4_AVC_CONSTRAINED_BASELINE:
+      case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
+         return 66;
+      case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN:
+         return 77;
+      case PIPE_VIDEO_PROFILE_MPEG4_AVC_EXTENDED:
+         return 88;
+      case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH:
+         return 100;
+      case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH10:
+         return 110;
+      case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH422:
+         return 122;
+      case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH444:
+         return 244;
+      default:
+         return 66; //use baseline profile instead
+   }
+}
+
 #ifdef __cplusplus
 }
 #endif