summaryrefslogtreecommitdiff
path: root/vdpauinfo.cpp
blob: 60f36195dc87e30aa54cb182595c20ed434442e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/* 
Query and display NVIDIA VDPAU capabilities, a la glxinfo 
version 0.0.2

Copyright (c) 2008 Wladimir J. van der Laan

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
/// TODO
/// - possible bug, querying VDP_CHROMA_TYPE_444 returns an error
///  (VDP_STATUS_INVALID_CHROMA_TYPE) is this NVIDIA or us?
/// - parse display/screen from command line
/// - list color table formats for queryOutputSurface

#include <stdlib.h>
#include <stdio.h>
#include <vdpau/vdpau.h>
#include <vdpau/vdpau_x11.h>

#include "VDPDeviceImpl.h"

/******************* Base ****************/

void queryBaseInfo(VDPDeviceImpl *device)
{
    uint32_t api;
    const char *info;
    if(device->GetApiVersion(&api) != VDP_STATUS_OK ||
       device->GetInformationString(&info) != VDP_STATUS_OK)
    {
        fprintf(stderr, "Error querying API version or information\n");
        exit(-1);    
    }
    printf("API version: %i\n", api);
    printf("Information string: %s\n", info);
}

/* Generic description structure */
struct Desc
{
    const char *name;
    uint32_t id;
    uint32_t aux; /* optional extra parameter... */
};

/**************** Video surface ************/
Desc chroma_types[] = {
{"420", VDP_CHROMA_TYPE_420},
{"422", VDP_CHROMA_TYPE_422},
{"444", VDP_CHROMA_TYPE_444},
};
const size_t chroma_type_count = sizeof(chroma_types)/sizeof(Desc);

Desc ycbcr_types[] = {
{"NV12", VDP_YCBCR_FORMAT_NV12},
{"YV12", VDP_YCBCR_FORMAT_YV12},
{"UYVY", VDP_YCBCR_FORMAT_UYVY},
{"YUYV", VDP_YCBCR_FORMAT_YUYV},
{"Y8U8V8A8", VDP_YCBCR_FORMAT_Y8U8V8A8},
{"V8U8Y8A8", VDP_YCBCR_FORMAT_V8U8Y8A8},
};
const size_t ycbcr_type_count = sizeof(ycbcr_types)/sizeof(Desc);

Desc rgb_types[] = {
{"B8G8R8A8", VDP_RGBA_FORMAT_B8G8R8A8},
{"R8G8B8A8", VDP_RGBA_FORMAT_R8G8B8A8},
{"R10G10B10A2", VDP_RGBA_FORMAT_R10G10B10A2},
{"B10G10R10A2", VDP_RGBA_FORMAT_B10G10R10A2},
{"A8", VDP_RGBA_FORMAT_A8},
};
const size_t rgb_type_count = sizeof(rgb_types)/sizeof(Desc);

Desc indexed_types[] = {
{"A4I4", VDP_INDEXED_FORMAT_A4I4},
{"I4A4", VDP_INDEXED_FORMAT_I4A4},
{"A8I8", VDP_INDEXED_FORMAT_A8I8},
{"I8A8", VDP_INDEXED_FORMAT_I8A8},
};
const size_t indexed_type_count = sizeof(indexed_types)/sizeof(Desc);

Desc color_table_formats[] = {
{"B8G8R8X8", VDP_COLOR_TABLE_FORMAT_B8G8R8X8},
};
const size_t color_table_format_count = sizeof(color_table_formats)/sizeof(Desc);


void queryVideoSurface(VDPDeviceImpl *device)
{
    VdpStatus rv;
    printf("\nVideo surface:\n\n");
    printf("name   width height types\n");
    printf("-------------------------------------------\n");
    for(int x=0; x<chroma_type_count; ++x)
    {
        VdpBool is_supported = false;
        uint32_t max_width, max_height;

        rv = device->VideoSurfaceQueryCapabilities(device->device, chroma_types[x].id, 
            &is_supported, &max_width, &max_height);
        if(rv == VDP_STATUS_OK && is_supported)
        {
            printf("%-6s %5i %5i  ", chroma_types[x].name, 
                max_width, max_height);
            /* Find out supported formats */
            for(int y=0; y<ycbcr_type_count; ++y)
            {
                is_supported = false;
                rv = device->VideoSurfaceQueryGetPutBitsYCbCrCapabilities(
                    device->device, chroma_types[x].id, ycbcr_types[y].id,
                    &is_supported);
                if(rv == VDP_STATUS_OK && is_supported)
                {
                    printf("%s ", ycbcr_types[y].name);
                }
            }
            printf("\n");
        }
    }
}

/***************** Output surface ****************/
void queryOutputSurface(VDPDeviceImpl *device)
{
    VdpStatus rv;
    printf("\nOutput surface:\n\n");
    printf("name              width height nat types\n");
    printf("----------------------------------------------------\n");
    for(int x=0; x<rgb_type_count; ++x)
    {
        VdpBool is_supported, native=false;
        uint32_t max_width, max_height;

        rv = device->OutputSurfaceQueryCapabilities(device->device, rgb_types[x].id, 
            &is_supported, &max_width, &max_height);
        device->OutputSurfaceQueryGetPutBitsNativeCapabilities(device->device, rgb_types[x].id,
            &native);
        if(rv == VDP_STATUS_OK && is_supported)
        {
            printf("%-16s %5i %5i    %c  ", rgb_types[x].name, 
                max_width, max_height, native?'y':'-');
            /* Find out supported formats */
            for(int y=0; y<ycbcr_type_count; ++y)
            {
                is_supported = false;
                rv = device->OutputSurfaceQueryPutBitsYCbCrCapabilities(
                    device->device, chroma_types[x].id, ycbcr_types[y].id,
                    &is_supported);
                if(rv == VDP_STATUS_OK && is_supported)
                {
                    printf("%s ", ycbcr_types[y].name);
                }
            }
            printf("\n");
        }
    }
    // OutputSurfaceQueryPutBitsIndexedCapabilities
    //   rgba, idx, colortable -> supported
}

/***************** Bitmap surface ****************/
void queryBitmapSurface(VDPDeviceImpl *device)
{
    VdpStatus rv;
    printf("\nBitmap surface:\n\n");
    printf("name              width height\n");
    printf("------------------------------\n");
    for(int x=0; x<rgb_type_count; ++x)
    {
        VdpBool is_supported;
        uint32_t max_width, max_height;

        rv = device->BitmapSurfaceQueryCapabilities(device->device, rgb_types[x].id, 
            &is_supported, &max_width, &max_height);
        if(rv == VDP_STATUS_OK && is_supported)
        {
            printf("%-16s %5i %5i\n", rgb_types[x].name, 
                max_width, max_height);
        }
    }
}

/******************* Video mixer ****************/

/* Type for value ranges */
enum DataType
{
    DT_NONE,
    DT_INT,
    DT_UINT,
    DT_FLOAT
};

Desc mixer_features[] = {
{"DEINTERLACE_TEMPORAL",VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL},
{"DEINTERLACE_TEMPORAL_SPATIAL",VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL},
{"INVERSE_TELECINE",VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE},
{"NOISE_REDUCTION",VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION},
{"SHARPNESS",VDP_VIDEO_MIXER_FEATURE_SHARPNESS},
{"LUMA_KEY",VDP_VIDEO_MIXER_FEATURE_LUMA_KEY},
{"HIGH QUALITY SCALING - L1", VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1},
{"HIGH QUALITY SCALING - L2", VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2},
{"HIGH QUALITY SCALING - L3", VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3},
{"HIGH QUALITY SCALING - L4", VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4},
{"HIGH QUALITY SCALING - L5", VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5},
{"HIGH QUALITY SCALING - L6", VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6},
{"HIGH QUALITY SCALING - L7", VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7},
{"HIGH QUALITY SCALING - L8", VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8},
{"HIGH QUALITY SCALING - L9", VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9},
};
const size_t mixer_features_count = sizeof(mixer_features)/sizeof(Desc);

Desc mixer_parameters[] = {
{"VIDEO_SURFACE_WIDTH",VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH,DT_UINT},
{"VIDEO_SURFACE_HEIGHT",VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT,DT_UINT},
{"CHROMA_TYPE",VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE,DT_NONE},
{"LAYERS",VDP_VIDEO_MIXER_PARAMETER_LAYERS,DT_UINT},
};
const size_t mixer_parameters_count = sizeof(mixer_parameters)/sizeof(Desc);

Desc mixer_attributes[] = {
{"BACKGROUND_COLOR",VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR,DT_NONE},
{"CSC_MATRIX",VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX,DT_NONE},
{"NOISE_REDUCTION_LEVEL",VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL,DT_FLOAT},
{"SHARPNESS_LEVEL",VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL,DT_FLOAT},
{"LUMA_KEY_MIN_LUMA",VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA,DT_NONE},
{"LUMA_KEY_MAX_LUMA",VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA,DT_NONE},
};
const size_t mixer_attributes_count = sizeof(mixer_attributes)/sizeof(Desc);

void display_range(uint32_t aux, uint32_t minval, uint32_t maxval)
{
    switch(aux)
    {
        case DT_INT: printf("%8i %8i", minval, maxval); break;
        case DT_UINT: printf("%8u %8u", minval, maxval); break;
        case DT_FLOAT: printf("%8.2f %8.2f", *((float*)&minval), *((float*)&maxval)); break;
        default: /* Ignore value which we don't know how to display */;
    }
}

void queryVideoMixer(VDPDeviceImpl *device)
{
    VdpStatus rv;
    printf("\nVideo mixer:\n\n");
   // Features
    printf("feature name                    sup\n");
    printf("------------------------------------\n");
    for(int x=0; x<mixer_features_count; ++x)
    {
        VdpBool is_supported = true; /* There seems to be a bug in VideoMixerQueryFeatureSupport, is_supported is only set if the feature is not supported */
        rv = device->VideoMixerQueryFeatureSupport(device->device, mixer_features[x].id, 
            &is_supported);
        is_supported = (rv == VDP_STATUS_OK && is_supported);
        printf("%-32s %c\n", mixer_features[x].name, 
            is_supported?'y':'-');
       
    }
    printf("\n");
    // Parameters (+range)
    printf("parameter name                  sup      min      max\n");
    printf("-----------------------------------------------------\n");
    for(int x=0; x<mixer_parameters_count; ++x)
    {
        VdpBool is_supported = false;

        rv = device->VideoMixerQueryParameterSupport(device->device, mixer_parameters[x].id, 
            &is_supported);
        is_supported = (rv == VDP_STATUS_OK && is_supported);
        printf("%-32s %c  ", mixer_parameters[x].name, 
            is_supported?'y':'-');
        if(is_supported)
        {
            uint32_t minval, maxval;
            rv = device->VideoMixerQueryParameterValueRange(device->device, mixer_parameters[x].id, 
                (void*)&minval, (void*)&maxval);
            if(rv == VDP_STATUS_OK)
                display_range(mixer_parameters[x].aux, minval, maxval);
        }
        printf("\n");
    }
    printf("\n");
    
    // Attributes (+range)
    printf("attribute name                  sup      min      max\n");
    printf("-----------------------------------------------------\n");
    for(int x=0; x<mixer_attributes_count; ++x)
    {
        VdpBool is_supported = false;

        rv = device->VideoMixerQueryAttributeSupport(device->device, mixer_attributes[x].id, 
            &is_supported);
        is_supported = (rv == VDP_STATUS_OK && is_supported);
        printf("%-32s %c  ", mixer_attributes[x].name, 
            is_supported?'y':'-');
        if(is_supported)
        {
            uint32_t minval, maxval;
            rv = device->VideoMixerQueryAttributeValueRange(device->device, mixer_parameters[x].id, 
                (void*)&minval, (void*)&maxval);
            if(rv == VDP_STATUS_OK)
                display_range(mixer_attributes[x].aux, minval, maxval);
        }
        printf("\n");
    }
    printf("\n");    
}

/******************* Decoder ****************/

Desc decoder_profiles[] = {
{"MPEG1",              VDP_DECODER_PROFILE_MPEG1},
{"MPEG2_SIMPLE",       VDP_DECODER_PROFILE_MPEG2_SIMPLE},
{"MPEG2_MAIN",         VDP_DECODER_PROFILE_MPEG2_MAIN},
{"H264_BASELINE",      VDP_DECODER_PROFILE_H264_BASELINE},
{"H264_MAIN",          VDP_DECODER_PROFILE_H264_MAIN},
{"H264_HIGH",          VDP_DECODER_PROFILE_H264_HIGH},
{"VC1_SIMPLE",         VDP_DECODER_PROFILE_VC1_SIMPLE},
{"VC1_MAIN",           VDP_DECODER_PROFILE_VC1_MAIN},
{"VC1_ADVANCED",       VDP_DECODER_PROFILE_VC1_ADVANCED},
{"MPEG4_PART2_SP",     VDP_DECODER_PROFILE_MPEG4_PART2_SP},
{"MPEG4_PART2_ASP",    VDP_DECODER_PROFILE_MPEG4_PART2_ASP},
{"DIVX4_QMOBILE",      VDP_DECODER_PROFILE_DIVX4_QMOBILE},
{"DIVX4_MOBILE",       VDP_DECODER_PROFILE_DIVX4_MOBILE},
{"DIVX4_HOME_THEATER", VDP_DECODER_PROFILE_DIVX4_HOME_THEATER},
{"DIVX4_HD_1080P",     VDP_DECODER_PROFILE_DIVX4_HD_1080P},
{"DIVX5_QMOBILE",      VDP_DECODER_PROFILE_DIVX5_QMOBILE},
{"DIVX5_MOBILE",       VDP_DECODER_PROFILE_DIVX5_MOBILE},
{"DIVX5_HOME_THEATER", VDP_DECODER_PROFILE_DIVX5_HOME_THEATER},
{"DIVX5_HD_1080P",     VDP_DECODER_PROFILE_DIVX5_HD_1080P},
};
const size_t decoder_profile_count = sizeof(decoder_profiles)/sizeof(Desc);

void queryDecoderCaps(VDPDeviceImpl *device)
{
    VdpStatus rv;
    printf("\nDecoder capabilities:\n\n");
    printf("name               level macbs width height\n");
    printf("-------------------------------------------\n");
    for(int x=0; x<decoder_profile_count; ++x)
    {
        VdpBool is_supported = false;
        uint32_t max_level, max_macroblocks, max_width, max_height;

        rv = device->DecoderQueryCapabilities(device->device, decoder_profiles[x].id, 
            &is_supported, &max_level, &max_macroblocks, &max_width, &max_height);
        if(rv == VDP_STATUS_OK && is_supported)
        {
            printf("%-20s %2i %5i %5i %5i\n", decoder_profiles[x].name, 
                max_level, max_macroblocks, max_width, max_height);
        }
    }
}


int main(int argc, char **argv)
{
    /* Create an X Display */
    Display *display;
    int screen;
    char *display_name = XDisplayName(NULL);
    if ((display=XOpenDisplay(display_name)) == NULL)
    {
        fprintf(stderr,"vdpauinfo: cannot connect to X server %s\n",
              XDisplayName(display_name));
        exit(-1);
    }
    screen = DefaultScreen(display);
    printf("display: %s   screen: %i\n", display_name, screen);
    
    /* Create device */
    VdpDevice device;
    VdpGetProcAddress *get_proc_address;
    VdpStatus rv;
    rv = vdp_device_create_x11(display, screen, &device, &get_proc_address);
    if(rv != VDP_STATUS_OK)
    {
        fprintf(stderr, "Error creating VDPAU device: %i\n", rv); /* cannot use GetErrorString here */
        exit(-1);
    }    
    
    VDPDeviceImpl *impl = new VDPDeviceImpl(device, get_proc_address);
    
    queryBaseInfo(impl);
    queryVideoSurface(impl);
    queryDecoderCaps(impl);
    queryOutputSurface(impl);
    queryBitmapSurface(impl);
    queryVideoMixer(impl);

    printf("\n");
}