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
|
/*
********************************************************************************
* USB UVC Driver
*
* (c) Copyright 2010-2015, All winners Co,Ld.
* All Right Reserved
*
* FileName : usbWebcam.h
*
* Author : Kingvan.Tong
*
* Date : 2013.03.26
*
* Description : USB Webcam
*
* Others : NULL
*
* History:
* <time> <version > <author> <desc>
* 2013.03.26 1.0 Kingvan.Tong build this file
*
********************************************************************************
*/
#include <stdio.h>
#include <string.h>
#include "usb_os_platform.h"
#include "error.h"
#include "video.h"
#include "uvcvideo.h"
#include "usbWebcam.h"
#include "hal_mem.h"
#include "hal_log.h"
#include "drv_webcam.h"
static usbWebcam_t *g_usbWebcam = NULL;
typedef __s32 (*active_buf) (struct uvc_streaming *stream) ;
static active_buf p_func;
static __s32 transport(__u32 addr0, __u32 addr1, __u32 addr2)
{
UVCDev_t *UVCDev = NULL;
UVCDev = g_usbWebcam->UVCDev;
hal_log_info("usb:(%x,%x,%x),(%x,%x,%x), %x,%x\n", addr0, addr1, addr2,
UVCDev->frame_buf0, UVCDev->frame_buf1, UVCDev->frame_buf2, (unsigned int)UVCDev->active_buf, (unsigned int)g_usbWebcam->uvc_irq);
if((void *)addr0 != NULL)
{
UVCDev->frame_len = 640*480;
UVCDev->exchange_buf = g_usbWebcam->uvc_irq;
UVCDev->frame_buf0 = addr0;
UVCDev->frame_buf1 = 0;
UVCDev->frame_buf2 = 0;
if(UVCDev->active_buf==NULL)
{
//printf("UVCDev->active_buf==NULL p_func=%x\n",p_func);
UVCDev->active_buf = p_func;
}
UVCDev->active_buf(UVCDev->streams);
}
else
{
if(UVCDev->active_buf) {
p_func = UVCDev->active_buf;
}
UVCDev->frame_len = 0;
UVCDev->active_buf = NULL;
UVCDev->exchange_buf = NULL;
UVCDev->frame_buf0 = 0;
UVCDev->frame_buf1 = 0;
UVCDev->frame_buf2 = 0;
//printf("transport UVCDev->active_buf==NULL\n");
}
return 0;
}
__s32 usbWebcam_probe(UVCDev_t *UVCDev)
{
usbWebcam_t *usbWebcam = NULL;
__u8 err = 0;
__s32 ret = 0;
extern __s32 DRV_WEBCAM_MInit(void);
extern __s32 DEV_WEBCAM_Ioctrl(__hdle hWebcam, __u32 cmd, __s32 aux, void *pbuffer);
if(UVCDev == NULL || g_usbWebcam == NULL){
hal_log_err("ERR: usbWebcamProbe: input error, 0x%x,0x%x\n", (unsigned int)UVCDev, (unsigned int)g_usbWebcam);
return -1;
}
usbWebcam = g_usbWebcam;
usbWebcam->UVCDev = UVCDev;
UVCDev->Extern = usbWebcam;
DRV_WEBCAM_MInit();
// usbWebcam->webcamHdl = fopen("b:\\UVC\\WEBCAM","r+");
if( usbWebcam->webcamHdl == NULL )
{
__s32 i;
hal_log_info("don't fined drv_webcam\n");
for( i = 0; i < UVC_URBS; ++i )
{
UVCDev->urb_mem[i] = usbWebcam->urb_mem[i];
}
} else {
printf("%s %d %s usbWebcam->webcamHdl == NULL!\n", __FILE__, __LINE__, __func__);
}
usbWebcam_v4l2_init(UVCDev);
ret = usbWebcam_v4l2_capture_on(UVCDev);
if( usbWebcam->webcamHdl )
{
DEV_WEBCAM_Ioctrl(usbWebcam->webcamHdl, DRV_WENCAM_CMD_GET_IRQ_CB, 0, (void*)(&usbWebcam->uvc_irq));
DEV_WEBCAM_Ioctrl(usbWebcam->webcamHdl, DRV_WENCAM_CMD_SET_TRANSPORT_CB, 0, (void*)transport);
DEV_WEBCAM_Ioctrl(usbWebcam->webcamHdl, DRV_WENCAM_CMD_WEBCAM_INSERT, 0, 0);
}
/* Notice: 由于新的设备上来以后,系统的设备管理告知应用程序,因此只能由驱动告知应用程序 */
// USB_OS_esKSRV_SendMsg(KMSG_USR_SYSTEM_WEBCAM_PLUGIN, KMSG_PRIO_HIGH);
hal_log_info("webcam plug in message...\n");
return ret;
}
void* usbWebcam_init(void)
{
usbWebcam_t *usbWebcam = NULL;
__u8 err = 0;
__s32 ret = 0;
/* 创建一个Webcam设备,并且初始化 */
usbWebcam = (usbWebcam_t *)hal_malloc(sizeof(usbWebcam_t));
if(usbWebcam == NULL){
hal_log_err("ERR: hal_malloc failed\n");
return NULL;
}
memset(usbWebcam, 0, sizeof(usbWebcam_t));
g_usbWebcam = usbWebcam;
{
__s32 i;
for( i = 0; i < UVC_URBS; ++i )
{
usbWebcam->urb_mem[i] = (__u32)hal_malloc(UVC_MAX_PACKETS*3);
if (!usbWebcam->urb_mem[i]) {
hal_log_info("esMEMS_Malloc fail\n");
}
}
}
return (void*)usbWebcam;
}
__s32 usbWebcam_remove(UVCDev_t * UVCDev)
{
usbWebcam_t *usbWebcam = NULL;
extern __s32 DEV_WEBCAM_Ioctrl(__hdle hWebcam, __u32 cmd, __s32 aux, void *pbuffer);
if(UVCDev == NULL){
hal_log_err("ERR: usbWebcamRemove: input error\n");
return -1;
}
usbWebcam = UVCDev->Extern;
if(usbWebcam == NULL){
hal_log_err("ERR: usbWebcamRemove: usbWebcam == NULL\n");
return -1;
}
if( usbWebcam->webcamHdl )
{
DEV_WEBCAM_Ioctrl(usbWebcam->webcamHdl, DRV_WENCAM_CMD_SET_TRANSPORT_CB, 0, 0);
DEV_WEBCAM_Ioctrl(usbWebcam->webcamHdl, DRV_WENCAM_CMD_WEBCAM_MOVED, (__s32)UVCDev->frame_buf0, (void*)UVCDev->frame_buf1);
}
// USB_OS_esKSRV_SendMsg(KMSG_USR_SYSTEM_WEBCAM_PLUGOUT, KMSG_PRIO_HIGH);
hal_log_info("webcam plug out message...\n");
usbWebcam->UVCDev = NULL;
UVCDev->Extern = NULL;
UVCDev->exchange_buf = NULL;
UVCDev->frame_buf0 = 0;
UVCDev->frame_buf1 = 0;
UVCDev->frame_buf2 = 0;
usbWebcam_v4l2_capture_off(UVCDev);//关中断发生器
usbWebcam_v4l2_exit(UVCDev);
if( usbWebcam->webcamHdl ) {
fclose(usbWebcam->webcamHdl);
}
return 0;
}
__s32 usbWebcam_exit(void* arg)
{
usbWebcam_t *usbWebcam = (usbWebcam_t *)arg;
__u8 err = 0;
if(usbWebcam == NULL){
hal_log_err("ERR: usbWebcamRemove: usbWebcam == NULL\n");
return -1;
}
{
__s32 i;
for (i = 0; i < UVC_URBS; ++i) {
if (usbWebcam->urb_mem[i]) {
hal_free((void*)usbWebcam->urb_mem[i]);
usbWebcam->urb_mem[i] = 0;
}
}
}
hal_free(usbWebcam);
return 0;
}
|