Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5564 | serge | 1 | /************************************************************************** |
2 | * |
||
3 | * Copyright 2009 Younes Manton. |
||
4 | * All Rights Reserved. |
||
5 | * |
||
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: |
||
13 | * |
||
14 | * The above copyright notice and this permission notice (including the |
||
15 | * next paragraph) shall be included in all copies or substantial portions |
||
16 | * of the Software. |
||
17 | * |
||
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. |
||
25 | * |
||
26 | **************************************************************************/ |
||
27 | |||
28 | #ifndef U_VIDEO_H |
||
29 | #define U_VIDEO_H |
||
30 | |||
31 | #ifdef __cplusplus |
||
32 | extern "C" { |
||
33 | #endif |
||
34 | |||
35 | #include "pipe/p_defines.h" |
||
36 | #include "pipe/p_video_enums.h" |
||
37 | |||
38 | /* u_reduce_video_profile() needs these */ |
||
39 | #include "pipe/p_compiler.h" |
||
40 | #include "util/u_debug.h" |
||
41 | #include "util/u_math.h" |
||
42 | |||
43 | static INLINE enum pipe_video_format |
||
44 | u_reduce_video_profile(enum pipe_video_profile profile) |
||
45 | { |
||
46 | switch (profile) |
||
47 | { |
||
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; |
||
52 | |||
53 | case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE: |
||
54 | case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE: |
||
55 | return PIPE_VIDEO_FORMAT_MPEG4; |
||
56 | |||
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; |
||
61 | |||
62 | case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE: |
||
63 | case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN: |
||
64 | case PIPE_VIDEO_PROFILE_MPEG4_AVC_EXTENDED: |
||
65 | case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH: |
||
66 | case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH10: |
||
67 | case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH422: |
||
68 | case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH444: |
||
69 | return PIPE_VIDEO_FORMAT_MPEG4_AVC; |
||
70 | |||
71 | default: |
||
72 | return PIPE_VIDEO_FORMAT_UNKNOWN; |
||
73 | } |
||
74 | } |
||
75 | |||
76 | static INLINE void |
||
77 | u_copy_nv12_to_yv12(void *const *destination_data, |
||
78 | uint32_t const *destination_pitches, |
||
79 | int src_plane, int src_field, |
||
80 | int src_stride, int num_fields, |
||
81 | uint8_t const *src, |
||
82 | int width, int height) |
||
83 | { |
||
84 | int x, y; |
||
85 | unsigned u_stride = destination_pitches[2] * num_fields; |
||
86 | unsigned v_stride = destination_pitches[1] * num_fields; |
||
87 | uint8_t *u_dst = (uint8_t *)destination_data[2] + destination_pitches[2] * src_field; |
||
88 | uint8_t *v_dst = (uint8_t *)destination_data[1] + destination_pitches[1] * src_field; |
||
89 | |||
90 | /* TODO: SIMD */ |
||
91 | for (y = 0; y < height; y++) { |
||
92 | for (x = 0; x < width; x++) { |
||
93 | u_dst[x] = src[2*x]; |
||
94 | v_dst[x] = src[2*x+1]; |
||
95 | } |
||
96 | u_dst += u_stride; |
||
97 | v_dst += v_stride; |
||
98 | src += src_stride; |
||
99 | } |
||
100 | } |
||
101 | |||
102 | static INLINE void |
||
103 | u_copy_yv12_to_nv12(void *const *destination_data, |
||
104 | uint32_t const *destination_pitches, |
||
105 | int src_plane, int src_field, |
||
106 | int src_stride, int num_fields, |
||
107 | uint8_t const *src, |
||
108 | int width, int height) |
||
109 | { |
||
110 | int x, y; |
||
111 | unsigned offset = 2 - src_plane; |
||
112 | unsigned stride = destination_pitches[1] * num_fields; |
||
113 | uint8_t *dst = (uint8_t *)destination_data[1] + destination_pitches[1] * src_field; |
||
114 | |||
115 | /* TODO: SIMD */ |
||
116 | for (y = 0; y < height; y++) { |
||
117 | for (x = 0; x < 2 * width; x += 2) { |
||
118 | dst[x+offset] = src[x>>1]; |
||
119 | } |
||
120 | dst += stride; |
||
121 | src += src_stride; |
||
122 | } |
||
123 | } |
||
124 | |||
125 | static INLINE void |
||
126 | u_copy_swap422_packed(void *const *destination_data, |
||
127 | uint32_t const *destination_pitches, |
||
128 | int src_plane, int src_field, |
||
129 | int src_stride, int num_fields, |
||
130 | uint8_t const *src, |
||
131 | int width, int height) |
||
132 | { |
||
133 | int x, y; |
||
134 | unsigned stride = destination_pitches[0] * num_fields; |
||
135 | uint8_t *dst = (uint8_t *)destination_data[0] + destination_pitches[0] * src_field; |
||
136 | |||
137 | /* TODO: SIMD */ |
||
138 | for (y = 0; y < height; y++) { |
||
139 | for (x = 0; x < 4 * width; x += 4) { |
||
140 | dst[x+0] = src[x+1]; |
||
141 | dst[x+1] = src[x+0]; |
||
142 | dst[x+2] = src[x+3]; |
||
143 | dst[x+3] = src[x+2]; |
||
144 | } |
||
145 | dst += stride; |
||
146 | src += src_stride; |
||
147 | } |
||
148 | } |
||
149 | |||
150 | static INLINE uint32_t |
||
151 | u_get_h264_level(uint32_t width, uint32_t height, uint32_t *max_reference) |
||
152 | { |
||
153 | uint32_t max_dpb_mbs; |
||
154 | |||
155 | width = align(width, 16); |
||
156 | height = align(height, 16); |
||
157 | |||
158 | /* Max references will be used for caculation of number of DPB buffers |
||
159 | in the UVD driver, limitation of max references is 16. Some client |
||
160 | like mpv application for VA-API, it requires references more than that, |
||
161 | so we have to set max of references to 16 here. */ |
||
162 | *max_reference = MIN2(*max_reference, 16); |
||
163 | max_dpb_mbs = (width / 16) * (height / 16) * *max_reference; |
||
164 | |||
165 | /* The calculation is based on "Decoded picture buffering" section |
||
166 | from http://en.wikipedia.org/wiki/H.264/MPEG-4_AVC */ |
||
167 | if (max_dpb_mbs <= 8100) |
||
168 | return 30; |
||
169 | else if (max_dpb_mbs <= 18000) |
||
170 | return 31; |
||
171 | else if (max_dpb_mbs <= 20480) |
||
172 | return 32; |
||
173 | else if (max_dpb_mbs <= 32768) |
||
174 | return 41; |
||
175 | else if (max_dpb_mbs <= 34816) |
||
176 | return 42; |
||
177 | else if (max_dpb_mbs <= 110400) |
||
178 | return 50; |
||
179 | else if (max_dpb_mbs <= 184320) |
||
180 | return 51; |
||
181 | else |
||
182 | return 52; |
||
183 | } |
||
184 | |||
185 | #ifdef __cplusplus |
||
186 | } |
||
187 | #endif |
||
188 | |||
189 | #endif /* U_VIDEO_H */=>=>=>=>=>=>=>>>>>>> |