File: NvSDIutils.cpp

package info (click to toggle)
bino 1.6.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,636 kB
  • sloc: cpp: 21,288; sh: 4,849; makefile: 314; sed: 16
file content (461 lines) | stat: -rw-r--r-- 15,522 bytes parent folder | download | duplicates (2)
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
/*
 * Copyright (C) 2012, 2015
 * Binocle <http://binocle.com/>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Written by Olivier Letz <oletz@binocle.com>.
 */

#include "config.h"

#include "NvSDIutils.h"

#include <GL/glx.h>

#include <stdio.h>
#include <string.h>
#include <sys/time.h>

#include <NVCtrl/NVCtrlLib.h>
#include <NVCtrl/NVCtrl.h>

#include "base/msg.h"
#include "base/dbg.h"

int
ScanHW (Display * dpy, HGPUNV * gpuList)
{
    HGPUNV gpuDevice;
    int num_gpus ;
    int gpu ;
    int *pData;
    int len ;
    char *str;
    bool ret;

    /* Get the number of gpus in the system */
    ret = XNVCTRLQueryTargetCount (dpy, NV_CTRL_TARGET_TYPE_GPU, &num_gpus);
    if (!ret) {
        msg::err("Failed to query number of gpus");
        return 1;
    }
    msg::inf("Number of GPUs: %d", num_gpus);
    int num_gpusWithXScreen = 0;

    for (gpu = 0; gpu < num_gpus; gpu++) {
        msg::inf("GPU %d information:", gpu);
        /* GPU name */
        ret = XNVCTRLQueryTargetStringAttribute (dpy, NV_CTRL_TARGET_TYPE_GPU, gpu,	// target_id
                0,	// display_mask
                NV_CTRL_STRING_PRODUCT_NAME,
                &str);
        if (!ret) {
            msg::err("Failed to query gpu product name");
            return 1;
        }
        msg::inf("Product Name                    : %s", str);
        /* X Screens driven by this GPU */
        ret = XNVCTRLQueryTargetBinaryData (dpy, NV_CTRL_TARGET_TYPE_GPU, gpu,	// target_id
                0,	// display_mask
                NV_CTRL_BINARY_DATA_XSCREENS_USING_GPU,
                (unsigned char **) &pData, &len);
        if (!ret) {
            msg::err("Failed to query list of X Screens");
            return 1;
        }
        msg::inf("Number of X Screens on GPU %d    : %d", gpu, pData[0]);
        //only return GPUs that have XScreens
        if (pData[0]) {
            gpuDevice.deviceXScreen = pData[1];	//chose the first screen
            strcpy (gpuDevice.deviceName, str);
            gpuList[gpu] = gpuDevice;
            num_gpusWithXScreen++;
        }
        XFree (pData);
    }
    return num_gpusWithXScreen;
}

//
// Calculate fps
//
GLfloat
CalcFPS ()
{
    static int t0 = -1;

    static int count = 0;

    struct timeval tv;

    struct timezone tz;

    static GLfloat __fps = 0.0;

    int t;

    gettimeofday (&tv, &tz);
    t = (int) tv.tv_sec;
    if (t0 < 0)
        t0 = t;
    count++;
    if (t - t0 >= 5.0) {
        GLfloat seconds = t - t0;

        __fps = count / seconds;
        t0 = t;
        count = 0;
    }
    return (__fps);
}

//
// Decode SDI input value returned.
//
const char *
decodeSDISyncInputDetected (int _value)
{
    switch (_value) {
    case NV_CTRL_GVO_SDI_SYNC_INPUT_DETECTED_HD:
        return ("NV_CTRL_GVO_SDI_SYNC_INPUT_DETECTED_HD");
        break;
    case NV_CTRL_GVO_SDI_SYNC_INPUT_DETECTED_SD:
        return ("NV_CTRL_GVO_SDI_SYNC_INPUT_DETECTED_SD");
        break;
    case NV_CTRL_GVO_SDI_SYNC_INPUT_DETECTED_NONE:
    default:
        return ("NV_CTRL_GVO_SDI_SYNC_INPUT_DETECTED_NONE");
        break;
    }				// switch
}

//
// Decode provided signal format.
//
const char *
decodeSignalFormat (int _value)
{
    switch (_value) {
    case NV_CTRL_GVIO_VIDEO_FORMAT_487I_59_94_SMPTE259_NTSC:
        return ("480i 59.94Hz (SMPTE259 - NTSC)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_576I_50_00_SMPTE259_PAL:
        return ("576i 50.00Hz (SMPTE259 - PAL)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_720P_59_94_SMPTE296:
        return ("720p 59.94Hz (SMPTE296)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_720P_60_00_SMPTE296:
        return ("720p 60.00Hz (SMPTE296)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1035I_59_94_SMPTE260:
        return ("1035i 59.94Hz (SMPTE260)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1035I_60_00_SMPTE260:
        return ("1035i 60.00Hz (SMPTE260)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080I_50_00_SMPTE295:
        return ("1080i 50.00Hz (SMPTE295)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080I_50_00_SMPTE274:
        return ("1080i 50.00Hz (SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080I_59_94_SMPTE274:
        return ("1080i 59.94Hz (SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080I_60_00_SMPTE274:
        return ("1080i 60.00Hz (SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080P_23_976_SMPTE274:
        return ("1080p 23.976Hz (SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080P_24_00_SMPTE274:
        return ("1080p 24.00Hz (SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080P_25_00_SMPTE274:
        return ("1080p 25.00Hz (SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080P_29_97_SMPTE274:
        return ("1080p 29.97Hz (SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080P_30_00_SMPTE274:
        return ("1080p 30.00Hz (SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_720P_50_00_SMPTE296:
        return ("720p 50.00Hz (SMPTE296)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080I_48_00_SMPTE274:
        return ("1080i 48.00Hz (SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080I_47_96_SMPTE274:
        return ("1080i 47.96Hz (SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_720P_30_00_SMPTE296:
        return ("720p 30.00Hz (SMPTE296)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_720P_29_97_SMPTE296:
        return ("720p 29.97Hz (SMPTE296)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_720P_25_00_SMPTE296:
        return ("720p 25.00Hz (SMPTE296)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_720P_24_00_SMPTE296:
        return ("720p 24.00Hz (SMPTE296)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_720P_23_98_SMPTE296:
        return ("720p 23.98Hz (SMPTE296)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080PSF_25_00_SMPTE274:
        return ("1080PsF 25.00Hz (SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080PSF_29_97_SMPTE274:
        return ("1080PsF 29.97Hz (SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080PSF_30_00_SMPTE274:
        return ("1080PsF 30.00Hz (SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080PSF_24_00_SMPTE274:
        return ("1080PsF 24.00Hz (SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080PSF_23_98_SMPTE274:
        return ("1080PsF 23.98Hz (SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048P_30_00_SMPTE372:
        return ("2048p 30.00Hz (SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048P_29_97_SMPTE372:
        return ("2048p 29.97Hz (SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048I_60_00_SMPTE372:
        return ("2048i 60.00Hz (SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048I_59_94_SMPTE372:
        return ("2048i 59.94Hz (SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048P_25_00_SMPTE372:
        return ("2048p 25.00Hz (SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048I_50_00_SMPTE372:
        return ("2048i 50.00Hz (SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048P_24_00_SMPTE372:
        return ("2048p 24.00Hz (SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048P_23_98_SMPTE372:
        return ("2048p 23.98Hz (SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048I_48_00_SMPTE372:
        return ("2048i 48.00Hz (SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048I_47_96_SMPTE372:
        return ("2048i 47.96Hz (SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080P_50_00_3G_LEVEL_A_SMPTE274:
        return ("1080p 50.00Hz (3G Level A - SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080P_59_94_3G_LEVEL_A_SMPTE274:
        return ("1080p 59.94Hz (3G Level A - SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080P_60_00_3G_LEVEL_A_SMPTE274:
        return ("1080p 60.00Hz (3G Level A - SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080P_60_00_3G_LEVEL_B_SMPTE274:
        return ("1080p 60.00Hz (3G Level B - SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080I_60_00_3G_LEVEL_B_SMPTE274:
        return ("1080i 60.00Hz (3G Level B - SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048I_60_00_3G_LEVEL_B_SMPTE372:
        return ("2048i 60.00Hz (3G Level B - SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080P_50_00_3G_LEVEL_B_SMPTE274:
        return ("1080p 50.00Hz (3G Level B - SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080I_50_00_3G_LEVEL_B_SMPTE274:
        return ("1080i 50.00Hz (3G Level B - SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048I_50_00_3G_LEVEL_B_SMPTE372:
        return ("2048i 50.00Hz (3G Level B - SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080P_30_00_3G_LEVEL_B_SMPTE274:
        return ("1080p 30.00Hz (3G Level B - SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048P_30_00_3G_LEVEL_B_SMPTE372:
        return ("2048p 30.00Hz (3G Level B - SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080P_25_00_3G_LEVEL_B_SMPTE274:
        return ("1080p 25.00Hz (3G Level B - SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048P_25_00_3G_LEVEL_B_SMPTE372:
        return ("2048p 25.00Hz (3G Level B - SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080P_24_00_3G_LEVEL_B_SMPTE274:
        return ("1080p 24.00Hz (3G Level B - SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048P_24_00_3G_LEVEL_B_SMPTE372:
        return ("2048p 24.00Hz (3G Level B - SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080I_48_00_3G_LEVEL_B_SMPTE274:
        return ("1080i 48.00Hz (3G Level B - SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048I_48_00_3G_LEVEL_B_SMPTE372:
        return ("2048i 48.00Hz (3G Level B - SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080P_59_94_3G_LEVEL_B_SMPTE274:
        return ("1080p 59.94Hz (3G Level B - SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080I_59_94_3G_LEVEL_B_SMPTE274:
        return ("1080i 59.94Hz (3G Level B - SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048I_59_94_3G_LEVEL_B_SMPTE372:
        return ("2048i 59.94Hz (3G Level B - SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080P_29_97_3G_LEVEL_B_SMPTE274:
        return ("1080p 29.97Hz (3G Level B - SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048P_29_97_3G_LEVEL_B_SMPTE372:
        return ("2048p 29.97Hz (3G Level B - SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080P_23_98_3G_LEVEL_B_SMPTE274:
        return ("1080p 23.98Hz (3G Level B - SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048P_23_98_3G_LEVEL_B_SMPTE372:
        return ("2048p 23.98Hz (3G Level B - SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_1080I_47_96_3G_LEVEL_B_SMPTE274:
        return ("1080i 47.96Hz (3G Level B - SMPTE274)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_2048I_47_96_3G_LEVEL_B_SMPTE372:
        return ("2048i 47.96Hz (3G Level B - SMPTE372)");
        break;
    case NV_CTRL_GVIO_VIDEO_FORMAT_NONE:
    default:
        return ("None");
        break;
    }				// switch
}

//
// Decode provided component sampling.
//
const char *
decodeComponentSampling (int _value)
{
    switch (_value) {
    case NV_CTRL_GVI_COMPONENT_SAMPLING_UNKNOWN:
        return ("NV_CTRL_GVI_COMPONENT_SAMPLING_UNKNOWN");
        break;
    case NV_CTRL_GVI_COMPONENT_SAMPLING_4444:
        return ("NV_CTRL_GVI_COMPONENT_SAMPLING_4444");
        break;
    case NV_CTRL_GVI_COMPONENT_SAMPLING_4224:
        return ("NV_CTRL_GVI_COMPONENT_SAMPLING_4224");
        break;
    case NV_CTRL_GVI_COMPONENT_SAMPLING_444:
        return ("NV_CTRL_GVI_COMPONENT_SAMPLING_444");
        break;
    case NV_CTRL_GVI_COMPONENT_SAMPLING_422:
        return ("NV_CTRL_GVI_COMPONENT_SAMPLING_422");
        break;
    default:
        return ("NV_CTRL_GVI_COMPONENT_SAMPLING_UNKNOWN");
        break;
    }				// switch
}

//
// Decode provided color space
//
const char *
decodeColorSpace (int _value)
{
    switch (_value) {
    case NV_CTRL_GVI_COLOR_SPACE_GBR:
        return ("NV_CTRL_GVI_COLOR_SPACE_GBR");
        break;
    case NV_CTRL_GVI_COLOR_SPACE_GBRA:
        return ("NV_CTRL_GVI_COLOR_SPACE_GBRA");
        break;
    case NV_CTRL_GVI_COLOR_SPACE_GBRD:
        return ("NV_CTRL_GVI_COLOR_SPACE_GBRD");
        break;
    case NV_CTRL_GVI_COLOR_SPACE_YCBCR:
        return ("NV_CTRL_GVI_COLOR_SPACE_YCBCR");
        break;
    case NV_CTRL_GVI_COLOR_SPACE_YCBCRA:
        return ("NV_CTRL_GVI_COLOR_SPACE_YCBCRA");
        break;
    case NV_CTRL_GVI_COLOR_SPACE_YCBCRD:
        return ("NV_CTRL_GVI_COLOR_SPACE_YCBCRD");
        break;
    case NV_CTRL_GVI_COLOR_SPACE_UNKNOWN:
    default:
        return ("NV_CTRL_GVI_COLOR_SPACE_UNKNOWN");
        break;
    }				// switch
}

//
// Decode bits per component
//
const char *
decodeBitsPerComponent (int _value)
{
    switch (_value) {
    case NV_CTRL_GVI_BITS_PER_COMPONENT_UNKNOWN:
        return ("NV_CTRL_GVI_BITS_PER_COMPONENT_UNKNOWN");
        break;
    case NV_CTRL_GVI_BITS_PER_COMPONENT_8:
        return ("NV_CTRL_GVI_BITS_PER_COMPONENT_8");
        break;
    case NV_CTRL_GVI_BITS_PER_COMPONENT_10:
        return ("NV_CTRL_GVI_BITS_PER_COMPONENT_10");
        break;
    case NV_CTRL_GVI_BITS_PER_COMPONENT_12:
        return ("NV_CTRL_GVI_BITS_PER_COMPONENT_12");
        break;
    default:
        return ("NV_CTRL_GVI_BITS_PER_COMPONENT_UNKNOWN");
        break;
    }				// switch
}

//
// Decode chroma expand
//
const char *
decodeChromaExpand (int _value)
{
    switch (_value) {
    case NV_CTRL_GVI_CHROMA_EXPAND_FALSE:
        return ("NV_CTRL_GVI_CHROMA_EXPAND_FALSE");
        break;
    case NV_CTRL_GVI_CHROMA_EXPAND_TRUE:
        return ("NV_CTRL_GVI_CHROMA_EXPAND_TRUE");
        break;
    default:
        return ("NV_CTRL_GVI_CHROMA_EXPAND_UNKNOWN");
        break;
    }				// switch
}