1 /*
2  *  vdpau_dump.c - Dump utilities
3  *
4  *  libva-vdpau-driver (C) 2009-2011 Splitted-Desktop Systems
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
19  */
20 
21 #include "sysdeps.h"
22 #include "vdpau_dump.h"
23 
24 #define DEBUG 1
25 #include "debug.h"
26 
27 
28 // Returns string representation of FOURCC
string_of_FOURCC(uint32_t fourcc)29 const char *string_of_FOURCC(uint32_t fourcc)
30 {
31     static char str[5];
32     str[0] = fourcc;
33     str[1] = fourcc >> 8;
34     str[2] = fourcc >> 16;
35     str[3] = fourcc >> 24;
36     str[4] = '\0';
37     return str;
38 }
39 
40 // Returns string representation of VABufferType
string_of_VABufferType(VABufferType type)41 const char *string_of_VABufferType(VABufferType type)
42 {
43     const char *str = NULL;
44     switch (type) {
45 #define _(X) case X: str = #X; break
46         _(VAPictureParameterBufferType);
47         _(VAIQMatrixBufferType);
48         _(VABitPlaneBufferType);
49         _(VASliceGroupMapBufferType);
50         _(VASliceParameterBufferType);
51         _(VASliceDataBufferType);
52         _(VAMacroblockParameterBufferType);
53         _(VAResidualDataBufferType);
54         _(VADeblockingParameterBufferType);
55         _(VAImageBufferType);
56 #if VA_CHECK_VERSION(0,30,0)
57         _(VAProtectedSliceDataBufferType);
58         _(VAEncCodedBufferType);
59         _(VAEncSequenceParameterBufferType);
60         _(VAEncPictureParameterBufferType);
61         _(VAEncSliceParameterBufferType);
62         // _(VAEncH264VUIBufferType);
63         // _(VAEncH264SEIBufferType);
64 #endif
65 #if VA_CHECK_VERSION(0,31,1)
66         _(VAQMatrixBufferType);
67 #endif
68 #if VA_CHECK_VERSION(0,32,0)
69         _(VAEncMiscParameterBufferType);
70 #endif
71     default:
72         break;
73 #undef _
74     }
75     return str;
76 }
77 
78 // Returns string representation of VdpCodec
string_of_VdpCodec(VdpCodec codec)79 const char *string_of_VdpCodec(VdpCodec codec)
80 {
81     const char *str = NULL;
82     switch (codec) {
83 #define _(X) case VDP_CODEC_##X: str = #X; break
84         _(MPEG1);
85         _(MPEG2);
86         _(MPEG4);
87         _(H264);
88         _(VC1);
89 #undef _
90     }
91     return str;
92 }
93 
94 #if USE_TRACER
95 #define TRACE               trace_print
96 #define INDENT(INC)         trace_indent(INC)
97 #define DUMPi(S, M)         TRACE("." #M " = %d,\n", S->M)
98 #define DUMPx(S, M)         TRACE("." #M " = 0x%08x,\n", S->M)
99 #define DUMPp(S, M)         TRACE("." #M " = %p,\n", S->M)
100 #define DUMPm(S, M, I, J)   dump_matrix_NxM(#M, (uint8_t *)S->M, I, J, I * J)
101 #else
102 #define trace_enabled()     (0)
103 #define do_nothing()        do { } while (0)
104 #define TRACE(FORMAT,...)   do_nothing()
105 #define INDENT(INC)         do_nothing()
106 #define DUMPi(S, M)         do_nothing()
107 #define DUMPx(S, M)         do_nothing()
108 #define DUMPp(S, M)         do_nothing()
109 #define DUMPm(S, M, I, J)   do_nothing()
110 #endif
111 
112 // Dumps matrix[N][M] = N rows x M columns (uint8_t)
113 static void
dump_matrix_NxM(const char * label,const uint8_t * matrix,int N,int M,int L)114 dump_matrix_NxM(const char *label, const uint8_t *matrix, int N, int M, int L)
115 {
116     int i, j, n = 0;
117 
118     TRACE(".%s = {\n", label);
119     INDENT(1);
120     for (j = 0; j < N; j++) {
121         for (i = 0; i < M; i++, n++) {
122             if (n >= L)
123                 break;
124             if (i > 0)
125                 TRACE(", ");
126             TRACE("0x%02x", matrix[n]);
127         }
128         if (j < (N - 1))
129             TRACE(",");
130         TRACE("\n");
131         if (n >= L)
132             break;
133     }
134     INDENT(-1);
135     TRACE("}\n");
136 }
137 
138 // Dumps VdpPictureInfoMPEG1Or2
dump_VdpPictureInfoMPEG1Or2(VdpPictureInfoMPEG1Or2 * pic_info)139 void dump_VdpPictureInfoMPEG1Or2(VdpPictureInfoMPEG1Or2 *pic_info)
140 {
141     INDENT(1);
142     TRACE("VdpPictureInfoMPEG1Or2 = {\n");
143     INDENT(1);
144     DUMPx(pic_info, forward_reference);
145     DUMPx(pic_info, backward_reference);
146     DUMPi(pic_info, slice_count);
147     DUMPi(pic_info, picture_structure);
148     DUMPi(pic_info, picture_coding_type);
149     DUMPi(pic_info, intra_dc_precision);
150     DUMPi(pic_info, frame_pred_frame_dct);
151     DUMPi(pic_info, concealment_motion_vectors);
152     DUMPi(pic_info, intra_vlc_format);
153     DUMPi(pic_info, alternate_scan);
154     DUMPi(pic_info, q_scale_type);
155     DUMPi(pic_info, top_field_first);
156     DUMPi(pic_info, full_pel_forward_vector);
157     DUMPi(pic_info, full_pel_backward_vector);
158     TRACE(".f_code = { { %d, %d }, { %d, %d } };\n",
159           pic_info->f_code[0][0], pic_info->f_code[0][1],
160           pic_info->f_code[1][0], pic_info->f_code[1][1]);
161     DUMPm(pic_info, intra_quantizer_matrix, 8, 8);
162     DUMPm(pic_info, non_intra_quantizer_matrix, 8, 8);
163     INDENT(-1);
164     TRACE("};\n");
165     INDENT(-1);
166 }
167 
168 // Dumps VdpPictureInfoMPEG4Part2
169 #if HAVE_VDPAU_MPEG4
dump_VdpPictureInfoMPEG4Part2(VdpPictureInfoMPEG4Part2 * pic_info)170 void dump_VdpPictureInfoMPEG4Part2(VdpPictureInfoMPEG4Part2 *pic_info)
171 {
172     INDENT(1);
173     TRACE("VdpPictureInfoMPEG4Part2 = {\n");
174     INDENT(1);
175     DUMPx(pic_info, forward_reference);
176     DUMPx(pic_info, backward_reference);
177     DUMPi(pic_info, vop_time_increment_resolution);
178     DUMPi(pic_info, vop_coding_type);
179     DUMPi(pic_info, vop_fcode_forward);
180     DUMPi(pic_info, vop_fcode_backward);
181     DUMPi(pic_info, resync_marker_disable);
182     DUMPi(pic_info, interlaced);
183     DUMPi(pic_info, quant_type);
184     DUMPi(pic_info, quarter_sample);
185     DUMPi(pic_info, short_video_header);
186     DUMPi(pic_info, rounding_control);
187     DUMPi(pic_info, alternate_vertical_scan_flag);
188     DUMPi(pic_info, top_field_first);
189     DUMPm(pic_info, intra_quantizer_matrix, 8, 8);
190     DUMPm(pic_info, non_intra_quantizer_matrix, 8, 8);
191     INDENT(-1);
192     TRACE("};\n");
193     INDENT(-1);
194 }
195 #endif
196 
197 // Dumps VdpReferenceFrameH264
198 static void
dump_VdpReferenceFrameH264(VdpReferenceFrameH264 * rf,const char * label)199 dump_VdpReferenceFrameH264(VdpReferenceFrameH264 *rf, const char *label)
200 {
201     TRACE(".%s = {\n", label);
202     INDENT(1);
203     DUMPx(rf, surface);
204     DUMPi(rf, is_long_term);
205     DUMPi(rf, top_is_reference);
206     DUMPi(rf, bottom_is_reference);
207     DUMPi(rf, field_order_cnt[0]);
208     DUMPi(rf, field_order_cnt[1]);
209     DUMPi(rf, frame_idx);
210     INDENT(-1);
211     TRACE("}\n");
212 }
213 
214 // Dumps VdpPictureInfoH264
dump_VdpPictureInfoH264(VdpPictureInfoH264 * pic_info)215 void dump_VdpPictureInfoH264(VdpPictureInfoH264 *pic_info)
216 {
217     int i;
218 
219     INDENT(1);
220     TRACE("VdpPictureInfoH264 = {\n");
221     INDENT(1);
222     DUMPi(pic_info, slice_count);
223     DUMPi(pic_info, field_order_cnt[0]);
224     DUMPi(pic_info, field_order_cnt[1]);
225     DUMPi(pic_info, is_reference);
226     DUMPi(pic_info, frame_num);
227     DUMPi(pic_info, field_pic_flag);
228     DUMPi(pic_info, bottom_field_flag);
229     DUMPi(pic_info, num_ref_frames);
230     DUMPi(pic_info, mb_adaptive_frame_field_flag);
231     DUMPi(pic_info, constrained_intra_pred_flag);
232     DUMPi(pic_info, weighted_pred_flag);
233     DUMPi(pic_info, weighted_bipred_idc);
234     DUMPi(pic_info, frame_mbs_only_flag);
235     DUMPi(pic_info, transform_8x8_mode_flag);
236     DUMPi(pic_info, chroma_qp_index_offset);
237     DUMPi(pic_info, second_chroma_qp_index_offset);
238     DUMPi(pic_info, pic_init_qp_minus26);
239     DUMPi(pic_info, num_ref_idx_l0_active_minus1);
240     DUMPi(pic_info, num_ref_idx_l1_active_minus1);
241     DUMPi(pic_info, log2_max_frame_num_minus4);
242     DUMPi(pic_info, pic_order_cnt_type);
243     DUMPi(pic_info, log2_max_pic_order_cnt_lsb_minus4);
244     DUMPi(pic_info, delta_pic_order_always_zero_flag);
245     DUMPi(pic_info, direct_8x8_inference_flag);
246     DUMPi(pic_info, entropy_coding_mode_flag);
247     DUMPi(pic_info, pic_order_present_flag);
248     DUMPi(pic_info, deblocking_filter_control_present_flag);
249     DUMPi(pic_info, redundant_pic_cnt_present_flag);
250     DUMPm(pic_info, scaling_lists_4x4, 6, 16);
251     DUMPm(pic_info, scaling_lists_8x8[0], 8, 8);
252     DUMPm(pic_info, scaling_lists_8x8[1], 8, 8);
253     for (i = 0; i < 16; i++) {
254         char label[100];
255         sprintf(label, "referenceFrames[%d]", i);
256         dump_VdpReferenceFrameH264(&pic_info->referenceFrames[i], label);
257     }
258     INDENT(-1);
259     TRACE("};\n");
260     INDENT(-1);
261 }
262 
263 // Dumps VdpPictureInfoVC1
dump_VdpPictureInfoVC1(VdpPictureInfoVC1 * pic_info)264 void dump_VdpPictureInfoVC1(VdpPictureInfoVC1 *pic_info)
265 {
266     INDENT(1);
267     TRACE("VdpPictureInfoVC1 = {\n");
268     INDENT(1);
269     DUMPx(pic_info, forward_reference);
270     DUMPx(pic_info, backward_reference);
271     DUMPi(pic_info, slice_count);
272     DUMPi(pic_info, picture_type);
273     DUMPi(pic_info, frame_coding_mode);
274     DUMPi(pic_info, postprocflag);
275     DUMPi(pic_info, pulldown);
276     DUMPi(pic_info, interlace);
277     DUMPi(pic_info, tfcntrflag);
278     DUMPi(pic_info, finterpflag);
279     DUMPi(pic_info, psf);
280     DUMPi(pic_info, dquant);
281     DUMPi(pic_info, panscan_flag);
282     DUMPi(pic_info, refdist_flag);
283     DUMPi(pic_info, quantizer);
284     DUMPi(pic_info, extended_mv);
285     DUMPi(pic_info, extended_dmv);
286     DUMPi(pic_info, overlap);
287     DUMPi(pic_info, vstransform);
288     DUMPi(pic_info, loopfilter);
289     DUMPi(pic_info, fastuvmc);
290     DUMPi(pic_info, range_mapy_flag);
291     DUMPi(pic_info, range_mapy);
292     DUMPi(pic_info, range_mapuv_flag);
293     DUMPi(pic_info, range_mapuv);
294     DUMPi(pic_info, multires);
295     DUMPi(pic_info, syncmarker);
296     DUMPi(pic_info, rangered);
297     DUMPi(pic_info, maxbframes);
298     DUMPi(pic_info, deblockEnable);
299     DUMPi(pic_info, pquant);
300     INDENT(-1);
301     TRACE("};\n");
302     INDENT(-1);
303 }
304 
305 // Dumps VdpBitstreamBuffer
dump_VdpBitstreamBuffer(VdpBitstreamBuffer * bitstream_buffer)306 void dump_VdpBitstreamBuffer(VdpBitstreamBuffer *bitstream_buffer)
307 {
308     const uint8_t *buffer = bitstream_buffer->bitstream;
309     const uint32_t size   = bitstream_buffer->bitstream_bytes;
310 
311     INDENT(1);
312     TRACE("VdpBitstreamBuffer (%d bytes) = {\n", size);
313     INDENT(1);
314     dump_matrix_NxM("buffer", buffer, 10, 15, size);
315     INDENT(-1);
316     TRACE("};\n");
317     INDENT(-1);
318 }
319