Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/avicap32/v4l.c
4393 views
1
/*
2
* Copyright 2002 Dmitry Timoshkov for CodeWeavers
3
* Copyright 2005 Maarten Lankhorst
4
*
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
9
*
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
14
*
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18
*/
19
20
#if 0
21
#pragma makedep unix
22
#endif
23
24
#include "config.h"
25
26
#include <errno.h>
27
#include <fcntl.h>
28
#include <stdarg.h>
29
#include <stdio.h>
30
#include <unistd.h>
31
#include <sys/stat.h>
32
#include <sys/ioctl.h>
33
#ifdef HAVE_LINUX_VIDEODEV2_H
34
# include <linux/videodev2.h>
35
#endif
36
37
#include "ntstatus.h"
38
#define WIN32_NO_STATUS
39
#include "windef.h"
40
#include "winternl.h"
41
#include "wine/debug.h"
42
43
#include "unixlib.h"
44
45
#ifdef HAVE_LINUX_VIDEODEV2_H
46
47
WINE_DEFAULT_DEBUG_CHANNEL(avicap);
48
49
static int xioctl(int fd, int request, void *arg)
50
{
51
int ret;
52
53
do
54
ret = ioctl(fd, request, arg);
55
while (ret < 0 && errno == EINTR);
56
57
return ret;
58
}
59
60
static void v4l_umbstowcs(const char *src, DWORD srclen, WCHAR *dst, DWORD dstlen)
61
{
62
DWORD ret = ntdll_umbstowcs(src, srclen, dst, dstlen - 1);
63
64
dst[ret] = 0;
65
}
66
67
static NTSTATUS get_device_desc(void *args)
68
{
69
struct get_device_desc_params *params = args;
70
struct v4l2_capability caps = {{0}};
71
char device[16];
72
struct stat st;
73
int fd;
74
75
snprintf(device, sizeof(device), "/dev/video%u", params->index);
76
77
if (stat(device, &st) < 0)
78
{
79
/* This is probably because the device does not exist */
80
WARN("Failed to stat %s: %s\n", device, strerror(errno));
81
return STATUS_OBJECT_NAME_NOT_FOUND;
82
}
83
84
if (!S_ISCHR(st.st_mode))
85
{
86
ERR("%s is not a character device.\n", device);
87
return STATUS_OBJECT_TYPE_MISMATCH;
88
}
89
90
if ((fd = open(device, O_RDWR | O_NONBLOCK)) < 0)
91
{
92
ERR("%s: Failed to open: %s\n", device, strerror(errno));
93
return STATUS_UNSUCCESSFUL;
94
}
95
96
if (!xioctl(fd, VIDIOC_QUERYCAP, &caps))
97
{
98
BOOL is_capture_device;
99
#ifdef V4L2_CAP_DEVICE_CAPS
100
if (caps.capabilities & V4L2_CAP_DEVICE_CAPS)
101
is_capture_device = caps.device_caps & V4L2_CAP_VIDEO_CAPTURE;
102
else
103
#endif
104
is_capture_device = caps.capabilities & V4L2_CAP_VIDEO_CAPTURE;
105
if (is_capture_device)
106
{
107
char version[CAP_DESC_MAX];
108
int ret;
109
110
v4l_umbstowcs((char *)caps.card, strlen((char *)caps.card),
111
params->name, ARRAY_SIZE(params->name));
112
113
ret = snprintf(version, ARRAY_SIZE(version), "%s v%u.%u.%u", (char *)caps.driver,
114
(caps.version >> 16) & 0xff, (caps.version >> 8) & 0xff, caps.version & 0xff);
115
v4l_umbstowcs(version, ret, params->version, ARRAY_SIZE(params->version));
116
}
117
close(fd);
118
return is_capture_device ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
119
}
120
121
/* errno 515 is used by some webcam drivers for unknown IOCTL commands. */
122
ERR("Failed to get capabilities for %s: %s\n", device, strerror(errno));
123
124
close(fd);
125
return STATUS_UNSUCCESSFUL;
126
}
127
128
const unixlib_entry_t __wine_unix_call_funcs[] =
129
{
130
get_device_desc,
131
};
132
133
#ifdef _WIN64
134
135
const unixlib_entry_t __wine_unix_call_wow64_funcs[] =
136
{
137
get_device_desc,
138
};
139
140
#endif /* _WIN64 */
141
142
#endif /* HAVE_LINUX_VIDEODEV2_H */
143
144