1 /**************************************************************************
3 * Copyright 2009 Younes Manton.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
31 #include "pipe/p_defines.h"
32 #include "pipe/p_video_enums.h"
34 /* u_reduce_video_profile() needs these */
35 #include "pipe/p_compiler.h"
36 #include "util/u_debug.h"
37 #include "util/u_math.h"
43 static inline enum pipe_video_format
44 u_reduce_video_profile(enum pipe_video_profile profile
)
48 case PIPE_VIDEO_PROFILE_MPEG1
:
49 case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE
:
50 case PIPE_VIDEO_PROFILE_MPEG2_MAIN
:
51 return PIPE_VIDEO_FORMAT_MPEG12
;
53 case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE
:
54 case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE
:
55 return PIPE_VIDEO_FORMAT_MPEG4
;
57 case PIPE_VIDEO_PROFILE_VC1_SIMPLE
:
58 case PIPE_VIDEO_PROFILE_VC1_MAIN
:
59 case PIPE_VIDEO_PROFILE_VC1_ADVANCED
:
60 return PIPE_VIDEO_FORMAT_VC1
;
62 case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE
:
63 case PIPE_VIDEO_PROFILE_MPEG4_AVC_CONSTRAINED_BASELINE
:
64 case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN
:
65 case PIPE_VIDEO_PROFILE_MPEG4_AVC_EXTENDED
:
66 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
:
67 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH10
:
68 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH422
:
69 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH444
:
70 return PIPE_VIDEO_FORMAT_MPEG4_AVC
;
72 case PIPE_VIDEO_PROFILE_HEVC_MAIN
:
73 case PIPE_VIDEO_PROFILE_HEVC_MAIN_10
:
74 case PIPE_VIDEO_PROFILE_HEVC_MAIN_STILL
:
75 case PIPE_VIDEO_PROFILE_HEVC_MAIN_12
:
76 case PIPE_VIDEO_PROFILE_HEVC_MAIN_444
:
77 return PIPE_VIDEO_FORMAT_HEVC
;
80 return PIPE_VIDEO_FORMAT_UNKNOWN
;
85 u_copy_nv12_to_yv12(void *const *destination_data
,
86 uint32_t const *destination_pitches
,
87 int src_plane
, int src_field
,
88 int src_stride
, int num_fields
,
90 int width
, int height
)
93 unsigned u_stride
= destination_pitches
[2] * num_fields
;
94 unsigned v_stride
= destination_pitches
[1] * num_fields
;
95 uint8_t *u_dst
= (uint8_t *)destination_data
[2] + destination_pitches
[2] * src_field
;
96 uint8_t *v_dst
= (uint8_t *)destination_data
[1] + destination_pitches
[1] * src_field
;
99 for (y
= 0; y
< height
; y
++) {
100 for (x
= 0; x
< width
; x
++) {
102 v_dst
[x
] = src
[2*x
+1];
111 * \brief Copy YV12 chroma data while converting it NV12
113 * Given a set of YV12 source pointers and -pitches, copy the data to a
114 * layout typical for NV12 video buffers.
116 * \param source data[in] The plane data pointers. Array of 3.
117 * \param source_pitches[in] The plane pitches. Array of 3.
118 * \param dst_plane[in] The destination plane to copy to. For NV12 always 1.
119 * \param dst_field[in] The destination field if interlaced.
120 * \param dst_stride[in] The destination stride for this plane.
121 * \param num_fields[in] The number of fields in the video buffer.
122 * \param dst[in] The destination plane pointer.
123 * \param width[in] The source plane width.
124 * \param height[in] The source plane height.
127 u_copy_nv12_from_yv12(const void *const *source_data
,
128 uint32_t const *source_pitches
,
129 int dst_plane
, int dst_field
,
130 int dst_stride
, int num_fields
,
132 int width
, int height
)
135 unsigned u_stride
= source_pitches
[2] * num_fields
;
136 unsigned v_stride
= source_pitches
[1] * num_fields
;
137 uint8_t *u_src
= (uint8_t *)source_data
[2] + source_pitches
[2] * dst_field
;
138 uint8_t *v_src
= (uint8_t *)source_data
[1] + source_pitches
[1] * dst_field
;
141 for (y
= 0; y
< height
; y
++) {
142 for (x
= 0; x
< width
; x
++) {
144 dst
[2*x
+1] = v_src
[x
];
153 u_copy_yv12_to_nv12(void *const *destination_data
,
154 uint32_t const *destination_pitches
,
155 int src_plane
, int src_field
,
156 int src_stride
, int num_fields
,
158 int width
, int height
)
161 unsigned offset
= 2 - src_plane
;
162 unsigned stride
= destination_pitches
[1] * num_fields
;
163 uint8_t *dst
= (uint8_t *)destination_data
[1] + destination_pitches
[1] * src_field
;
166 for (y
= 0; y
< height
; y
++) {
167 for (x
= 0; x
< 2 * width
; x
+= 2) {
168 dst
[x
+offset
] = src
[x
>>1];
176 u_copy_swap422_packed(void *const *destination_data
,
177 uint32_t const *destination_pitches
,
178 int src_plane
, int src_field
,
179 int src_stride
, int num_fields
,
181 int width
, int height
)
184 unsigned stride
= destination_pitches
[0] * num_fields
;
185 uint8_t *dst
= (uint8_t *)destination_data
[0] + destination_pitches
[0] * src_field
;
188 for (y
= 0; y
< height
; y
++) {
189 for (x
= 0; x
< 4 * width
; x
+= 4) {
200 static inline uint32_t
201 u_get_h264_level(uint32_t width
, uint32_t height
, uint32_t *max_reference
)
203 uint32_t max_dpb_mbs
;
205 width
= align(width
, 16);
206 height
= align(height
, 16);
208 /* Max references will be used for caculation of number of DPB buffers
209 in the UVD driver, limitation of max references is 16. Some client
210 like mpv application for VA-API, it requires references more than that,
211 so we have to set max of references to 16 here. */
212 *max_reference
= MIN2(*max_reference
, 16);
213 max_dpb_mbs
= (width
/ 16) * (height
/ 16) * *max_reference
;
215 /* The calculation is based on "Decoded picture buffering" section
216 from http://en.wikipedia.org/wiki/H.264/MPEG-4_AVC */
217 if (max_dpb_mbs
<= 8100)
219 else if (max_dpb_mbs
<= 18000)
221 else if (max_dpb_mbs
<= 20480)
223 else if (max_dpb_mbs
<= 32768)
225 else if (max_dpb_mbs
<= 34816)
227 else if (max_dpb_mbs
<= 110400)
229 else if (max_dpb_mbs
<= 184320)
239 #endif /* U_VIDEO_H */