10
10
# include <va/va.h>
11
11
# include <va/va_drm.h>
12
12
13
+ # include "opencv2/core.hpp" // cv::format()
14
+
13
15
namespace va {
14
16
15
17
bool openDisplay ();
@@ -70,10 +72,9 @@ static unsigned readId(const char* devName, const char* idName)
70
72
{
71
73
long int id = 0 ;
72
74
73
- char fileName[256 ];
74
- snprintf (fileName, sizeof (fileName), " %s/%s/%s" , VA_INTEL_PCI_DIR, devName, idName);
75
+ std ::string fileName = cv ::format (" %s/%s/%s" , VA_INTEL_PCI_DIR, devName, idName);
75
76
76
- FILE* file = fopen (fileName, " r" );
77
+ FILE* file = fopen (fileName. c_str () , " r" );
77
78
if (file)
78
79
{
79
80
char str[16 ] = " " ;
@@ -100,9 +101,8 @@ static int findAdapter(unsigned desiredVendorId)
100
101
unsigned vendorId = readId (name, " vendor" );
101
102
if (vendorId == desiredVendorId)
102
103
{
103
- char subdirName[256 ];
104
- snprintf (subdirName, sizeof (subdirName), " %s/%s/%s" , VA_INTEL_PCI_DIR, name, " drm" );
105
- Directory subdir (subdirName);
104
+ std ::string subdirName = cv ::format (" %s/%s/%s" , VA_INTEL_PCI_DIR, name, " drm" );
105
+ Directory subdir (subdirName.c_str ());
106
106
for (int j = 0 ; j < subdir.count (); ++ j)
107
107
{
108
108
if (! strncmp (subdir[j]- > d_name, " card" , 4 ))
@@ -130,29 +130,23 @@ public:
130
130
numbers[1 ] = adapterIndex;
131
131
for (int i = 0 ; i < NUM_NODES; ++ i)
132
132
{
133
- int sz = sizeof (VA_INTEL_DRI_DIR) + strlen (names[i]) + 3 ;
134
- paths[i] = new char [sz];
135
- snprintf (paths[i], sz, " %s%s%d" , VA_INTEL_DRI_DIR, names[i], numbers[i]);
133
+ paths[i] = cv ::format (" %s%s%d" , VA_INTEL_DRI_DIR, names[i], numbers[i]);
136
134
}
137
135
}
138
136
~ NodeInfo ()
139
137
{
140
- for (int i = 0 ; i < NUM_NODES; ++ i)
141
- {
142
- delete paths[i];
143
- paths[i] = 0 ;
144
- }
138
+ // nothing
145
139
}
146
140
int count () const
147
141
{
148
142
return NUM_NODES;
149
143
}
150
144
const char* path (int index) const
151
145
{
152
- return ((index >= 0 ) && (index < NUM_NODES)) ? paths[index] : 0 ;
146
+ return ((index >= 0 ) && (index < NUM_NODES)) ? paths[index]. c_str () : 0 ;
153
147
}
154
148
private :
155
- char * paths[NUM_NODES];
149
+ std ::string paths[NUM_NODES];
156
150
};
157
151
158
152
static bool openDeviceIntel ();
0 commit comments