-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcam_common.cpp
210 lines (170 loc) · 6.15 KB
/
dcam_common.cpp
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
#include "dcam_common.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#ifndef ASSERT
#define ASSERT(c)
#endif
// ----------------------------------------------------------------
inline const int my_dcamdev_string( DCAMERR& err, HDCAM hdcam, int32 idStr, char* text, int32 textbytes )
{
DCAMDEV_STRING param;
memset( ¶m, 0, sizeof(param) );
param.size = sizeof(param);
param.text = text;
param.textbytes = textbytes;
param.iString = idStr;
err = dcamdev_getstring( hdcam, ¶m );
return ! failed( err );
}
// ----------------------------------------------------------------
void dcamcon_show_dcamerr( HDCAM hdcam, DCAMERR errid, const char* apiname, const char* fmt, ... )
{
char errtext[ 256 ];
DCAMERR err;
my_dcamdev_string( err, hdcam, errid, errtext, sizeof(errtext) );
printf( "FAILED: (DCAMERR)0x%08X %s @ %s", errid, errtext, apiname );
if( fmt != NULL )
{
printf( " : " );
va_list arg;
va_start(arg,fmt);
vprintf( fmt, arg );
va_end(arg);
}
printf( "\n" );
}
// ----------------------------------------------------------------
void dcamcon_show_dcamdev_info( HDCAM hdcam )
{
char model[ 256 ];
char cameraid[ 64 ];
char bus[ 64 ];
DCAMERR err;
if( ! my_dcamdev_string( err, hdcam, DCAM_IDSTR_MODEL, model, sizeof(model) ) )
{
dcamcon_show_dcamerr( hdcam, err, "dcamdev_getstring(DCAM_IDSTR_MODEL)\n" );
}
else
if( ! my_dcamdev_string( err, hdcam, DCAM_IDSTR_CAMERAID, cameraid, sizeof(cameraid)) )
{
dcamcon_show_dcamerr( hdcam, err, "dcamdev_getstring(DCAM_IDSTR_CAMERAID)\n" );
}
else
if( ! my_dcamdev_string( err, hdcam, DCAM_IDSTR_BUS, bus, sizeof(bus) ) )
{
dcamcon_show_dcamerr( hdcam, err, "dcamdev_getstring(DCAM_IDSTR_BUS)\n" );
}
else
{
printf( "%s (%s) on %s\n", model, cameraid, bus );
}
}
// show HDCAM camera information by text.
void dcamcon_show_dcamdev_info_detail( HDCAM hdcam )
{
char buf[ 256 ];
DCAMERR err;
if( ! my_dcamdev_string( err, hdcam, DCAM_IDSTR_VENDOR, buf, sizeof(buf) ) )
dcamcon_show_dcamerr( hdcam, err, "dcamdev_getstring(DCAM_IDSTR_VENDOR)\n" );
else
printf( "DCAM_IDSTR_VENDOR = %s\n", buf );
if( ! my_dcamdev_string( err, hdcam, DCAM_IDSTR_MODEL, buf, sizeof(buf) ) )
dcamcon_show_dcamerr( hdcam, err, "dcamdev_getstring(DCAM_IDSTR_MODEL)\n" );
else
printf( "DCAM_IDSTR_MODEL = %s\n", buf );
if( ! my_dcamdev_string( err, hdcam, DCAM_IDSTR_CAMERAID, buf, sizeof(buf) ) )
dcamcon_show_dcamerr( hdcam, err, "dcamdev_getstring(DCAM_IDSTR_CAMERAID)\n" );
else
printf( "DCAM_IDSTR_CAMERAID = %s\n", buf );
if( ! my_dcamdev_string( err, hdcam, DCAM_IDSTR_BUS, buf, sizeof(buf) ) )
dcamcon_show_dcamerr( hdcam, err, "dcamdev_getstring(DCAM_IDSTR_BUS)\n" );
else
printf( "DCAM_IDSTR_BUS = %s\n", buf );
if( ! my_dcamdev_string( err, hdcam, DCAM_IDSTR_CAMERAVERSION, buf, sizeof(buf) ) )
dcamcon_show_dcamerr( hdcam, err, "dcamdev_getstring(DCAM_IDSTR_CAMERAVERSION)\n" );
else
printf( "DCAM_IDSTR_CAMERAVERSION = %s\n", buf );
if( ! my_dcamdev_string( err, hdcam, DCAM_IDSTR_DRIVERVERSION, buf, sizeof(buf) ) )
dcamcon_show_dcamerr( hdcam, err, "dcamdev_getstring(DCAM_IDSTR_DRIVERVERSION)\n" );
else
printf( "DCAM_IDSTR_DRIVERVERSION = %s\n", buf );
if( ! my_dcamdev_string( err, hdcam, DCAM_IDSTR_MODULEVERSION, buf, sizeof(buf) ) )
dcamcon_show_dcamerr( hdcam, err, "dcamdev_getstring(DCAM_IDSTR_MODULEVERSION)\n" );
else
printf( "DCAM_IDSTR_MODULEVERSION = %s\n", buf );
if( ! my_dcamdev_string( err, hdcam, DCAM_IDSTR_DCAMAPIVERSION, buf, sizeof(buf) ) )
dcamcon_show_dcamerr( hdcam, err, "dcamdev_getstring(DCAM_IDSTR_DCAMAPIVERSION)\n" );
else
printf( "DCAM_IDSTR_DCAMAPIVERSION = %s\n", buf );
}
// ----------------------------------------------------------------
// initialize DCAM-API and get HDCAM camera handle.
HDCAM dcamcon_init_open()
{
// Initialize DCAM-API ver 4.0
DCAMAPI_INIT paraminit;
memset( ¶minit, 0, sizeof(paraminit) );
paraminit.size = sizeof(paraminit);
DCAMERR err;
err = dcamapi_init( ¶minit );
if( failed( err ) )
{
// failure
dcamcon_show_dcamerr( NULL, err, "dcamapi_init()" );
return NULL;
}
int32 nDevice = paraminit.iDeviceCount;
if(nDevice<=0){goto Error;}//ASSERT( nDevice > 0 ); // nDevice must be larger than 0
int32 iDevice;
// show all camera information by text
for( iDevice = 0; iDevice < nDevice; iDevice++ )
{
dcamcon_show_dcamdev_info( (HDCAM)iDevice );
}
if( nDevice > 1 )
{
// choose one camera from the list if there are two or more cameras.
printf( "choose one of camera from above list by index (0-%d) >", nDevice-1 );
iDevice = -1;
char buf[256];
while( fgets( buf, sizeof(buf), stdin ) != NULL )
{
if( _strcmpi( buf, "exit" ) == 0 || _stricmp( buf, "exit\n" ) == 0 )
{
iDevice = -1;
break;
}
iDevice = atoi( buf );
if( 0 <= iDevice && iDevice < nDevice )
break;
}
}
else
{
iDevice = 0;
}
if( 0 <= iDevice && iDevice < nDevice )
{
// open specified camera
DCAMDEV_OPEN paramopen;
memset( ¶mopen, 0, sizeof(paramopen) );
paramopen.size = sizeof(paramopen);
paramopen.index = iDevice;
err = dcamdev_open( ¶mopen );
if( ! failed(err) )
{
HDCAM hdcam = paramopen.hdcam;
dcamcon_show_dcamdev_info_detail( hdcam );
// success
return hdcam;
}
dcamcon_show_dcamerr( (HDCAM)iDevice, err, "dcamdev_open()", "index is %d\n", iDevice );
}
Error:
// uninitialize DCAM-API
dcamapi_uninit();
// failure
return NULL;
}