[44281] | 1 | /* $Id: UsbWebcamInterface.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * UsbWebcamInterface - Driver Interface for USB Webcam emulation.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[82968] | 7 | * Copyright (C) 2011-2020 Oracle Corporation
|
---|
[44281] | 8 | *
|
---|
[44337] | 9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
| 12 | * General Public License (GPL) as published by the Free Software
|
---|
| 13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
[44281] | 16 | */
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | #define LOG_GROUP LOG_GROUP_USB_WEBCAM
|
---|
[67914] | 20 | #include "LoggingNew.h"
|
---|
| 21 |
|
---|
[44281] | 22 | #include "UsbWebcamInterface.h"
|
---|
| 23 | #include "ConsoleImpl.h"
|
---|
| 24 | #include "ConsoleVRDPServer.h"
|
---|
[49120] | 25 | #include "EmulatedUSBImpl.h"
|
---|
[44281] | 26 |
|
---|
| 27 | #include <VBox/vmm/pdmwebcaminfs.h>
|
---|
[76760] | 28 | #include <VBox/err.h>
|
---|
[44281] | 29 |
|
---|
| 30 |
|
---|
[44758] | 31 | typedef struct EMWEBCAMREMOTE
|
---|
[44281] | 32 | {
|
---|
| 33 | EmWebcam *pEmWebcam;
|
---|
| 34 |
|
---|
[44758] | 35 | VRDEVIDEOINDEVICEHANDLE deviceHandle; /* The remote identifier. */
|
---|
[49120] | 36 |
|
---|
| 37 | /* Received from the remote client. */
|
---|
[44758] | 38 | uint32_t u32Version; /* VRDE_VIDEOIN_NEGOTIATE_VERSION */
|
---|
| 39 | uint32_t fu32Capabilities; /* VRDE_VIDEOIN_NEGOTIATE_CAP_* */
|
---|
[49120] | 40 | VRDEVIDEOINDEVICEDESC *pDeviceDesc;
|
---|
| 41 | uint32_t cbDeviceDesc;
|
---|
[44281] | 42 |
|
---|
| 43 | /* The device identifier for the PDM device.*/
|
---|
| 44 | uint64_t u64DeviceId;
|
---|
[44758] | 45 | } EMWEBCAMREMOTE;
|
---|
[44281] | 46 |
|
---|
[49120] | 47 | typedef struct EMWEBCAMDRV
|
---|
| 48 | {
|
---|
| 49 | EMWEBCAMREMOTE *pRemote;
|
---|
[62823] | 50 | PPDMIWEBCAMDEV pIWebcamUp;
|
---|
[62824] | 51 | PDMIWEBCAMDRV IWebcamDrv;
|
---|
[49120] | 52 | } EMWEBCAMDRV, *PEMWEBCAMDRV;
|
---|
| 53 |
|
---|
[44281] | 54 | typedef struct EMWEBCAMREQCTX
|
---|
| 55 | {
|
---|
| 56 | EMWEBCAMREMOTE *pRemote;
|
---|
| 57 | void *pvUser;
|
---|
| 58 | } EMWEBCAMREQCTX;
|
---|
| 59 |
|
---|
| 60 |
|
---|
[62824] | 61 | static DECLCALLBACK(void) drvEmWebcamReady(PPDMIWEBCAMDRV pInterface,
|
---|
[47416] | 62 | bool fReady)
|
---|
| 63 | {
|
---|
[49120] | 64 | NOREF(fReady);
|
---|
| 65 |
|
---|
[62824] | 66 | PEMWEBCAMDRV pThis = RT_FROM_MEMBER(pInterface, EMWEBCAMDRV, IWebcamDrv);
|
---|
[49120] | 67 | EMWEBCAMREMOTE *pRemote = pThis->pRemote;
|
---|
| 68 |
|
---|
| 69 | LogFlowFunc(("pRemote:%p\n", pThis->pRemote));
|
---|
| 70 |
|
---|
| 71 | if (pThis->pIWebcamUp)
|
---|
| 72 | {
|
---|
[62822] | 73 | pThis->pIWebcamUp->pfnAttached(pThis->pIWebcamUp,
|
---|
| 74 | pRemote->u64DeviceId,
|
---|
| 75 | pRemote->pDeviceDesc,
|
---|
| 76 | pRemote->cbDeviceDesc,
|
---|
| 77 | pRemote->u32Version,
|
---|
| 78 | pRemote->fu32Capabilities);
|
---|
[49120] | 79 | }
|
---|
[47416] | 80 | }
|
---|
| 81 |
|
---|
[62824] | 82 | static DECLCALLBACK(int) drvEmWebcamControl(PPDMIWEBCAMDRV pInterface,
|
---|
[44281] | 83 | void *pvUser,
|
---|
| 84 | uint64_t u64DeviceId,
|
---|
[62821] | 85 | const struct VRDEVIDEOINCTRLHDR *pCtrl,
|
---|
[44281] | 86 | uint32_t cbCtrl)
|
---|
| 87 | {
|
---|
[62824] | 88 | PEMWEBCAMDRV pThis = RT_FROM_MEMBER(pInterface, EMWEBCAMDRV, IWebcamDrv);
|
---|
[49120] | 89 | EMWEBCAMREMOTE *pRemote = pThis->pRemote;
|
---|
[44281] | 90 |
|
---|
[49120] | 91 | LogFlowFunc(("pRemote:%p, u64DeviceId %lld\n", pRemote, u64DeviceId));
|
---|
[44758] | 92 |
|
---|
[62821] | 93 | return pRemote->pEmWebcam->SendControl(pThis, pvUser, u64DeviceId, pCtrl, cbCtrl);
|
---|
[44281] | 94 | }
|
---|
| 95 |
|
---|
| 96 |
|
---|
[49120] | 97 | EmWebcam::EmWebcam(ConsoleVRDPServer *pServer)
|
---|
[44759] | 98 | :
|
---|
[49120] | 99 | mParent(pServer),
|
---|
[44759] | 100 | mpDrv(NULL),
|
---|
| 101 | mpRemote(NULL),
|
---|
| 102 | mu64DeviceIdSrc(0)
|
---|
[44281] | 103 | {
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | EmWebcam::~EmWebcam()
|
---|
| 107 | {
|
---|
| 108 | if (mpDrv)
|
---|
| 109 | {
|
---|
[49120] | 110 | mpDrv->pRemote = NULL;
|
---|
[44281] | 111 | mpDrv = NULL;
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[44758] | 115 | void EmWebcam::EmWebcamConstruct(EMWEBCAMDRV *pDrv)
|
---|
| 116 | {
|
---|
| 117 | AssertReturnVoid(mpDrv == NULL);
|
---|
| 118 |
|
---|
| 119 | mpDrv = pDrv;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
[44281] | 122 | void EmWebcam::EmWebcamDestruct(EMWEBCAMDRV *pDrv)
|
---|
| 123 | {
|
---|
| 124 | AssertReturnVoid(pDrv == mpDrv);
|
---|
| 125 |
|
---|
| 126 | if (mpRemote)
|
---|
| 127 | {
|
---|
[49120] | 128 | mParent->VideoInDeviceDetach(&mpRemote->deviceHandle);
|
---|
| 129 |
|
---|
| 130 | RTMemFree(mpRemote->pDeviceDesc);
|
---|
| 131 | mpRemote->pDeviceDesc = NULL;
|
---|
| 132 | mpRemote->cbDeviceDesc = 0;
|
---|
| 133 |
|
---|
[44281] | 134 | RTMemFree(mpRemote);
|
---|
| 135 | mpRemote = NULL;
|
---|
| 136 | }
|
---|
[44758] | 137 |
|
---|
[49120] | 138 | mpDrv->pRemote = NULL;
|
---|
[44758] | 139 | mpDrv = NULL;
|
---|
[44281] | 140 | }
|
---|
| 141 |
|
---|
| 142 | void EmWebcam::EmWebcamCbNotify(uint32_t u32Id, const void *pvData, uint32_t cbData)
|
---|
| 143 | {
|
---|
| 144 | int rc = VINF_SUCCESS;
|
---|
| 145 |
|
---|
| 146 | switch (u32Id)
|
---|
| 147 | {
|
---|
[44758] | 148 | case VRDE_VIDEOIN_NOTIFY_ID_ATTACH:
|
---|
[44281] | 149 | {
|
---|
| 150 | VRDEVIDEOINNOTIFYATTACH *p = (VRDEVIDEOINNOTIFYATTACH *)pvData;
|
---|
| 151 |
|
---|
[44758] | 152 | /* Older versions did not report u32Version and fu32Capabilities. */
|
---|
| 153 | uint32_t u32Version = 1;
|
---|
| 154 | uint32_t fu32Capabilities = VRDE_VIDEOIN_NEGOTIATE_CAP_VOID;
|
---|
[44281] | 155 |
|
---|
[73097] | 156 | if (cbData >= RT_UOFFSETOF(VRDEVIDEOINNOTIFYATTACH, u32Version) + sizeof(p->u32Version))
|
---|
[44758] | 157 | u32Version = p->u32Version;
|
---|
| 158 |
|
---|
[73097] | 159 | if (cbData >= RT_UOFFSETOF(VRDEVIDEOINNOTIFYATTACH, fu32Capabilities) + sizeof(p->fu32Capabilities))
|
---|
[44758] | 160 | fu32Capabilities = p->fu32Capabilities;
|
---|
| 161 |
|
---|
| 162 | LogFlowFunc(("ATTACH[%d,%d] version %d, caps 0x%08X\n",
|
---|
| 163 | p->deviceHandle.u32ClientId, p->deviceHandle.u32DeviceId,
|
---|
| 164 | u32Version, fu32Capabilities));
|
---|
| 165 |
|
---|
[44281] | 166 | /* Currently only one device is allowed. */
|
---|
| 167 | if (mpRemote)
|
---|
| 168 | {
|
---|
| 169 | AssertFailed();
|
---|
| 170 | rc = VERR_NOT_SUPPORTED;
|
---|
| 171 | break;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | EMWEBCAMREMOTE *pRemote = (EMWEBCAMREMOTE *)RTMemAllocZ(sizeof(EMWEBCAMREMOTE));
|
---|
| 175 | if (pRemote == NULL)
|
---|
| 176 | {
|
---|
| 177 | rc = VERR_NO_MEMORY;
|
---|
| 178 | break;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
[44758] | 181 | pRemote->pEmWebcam = this;
|
---|
| 182 | pRemote->deviceHandle = p->deviceHandle;
|
---|
| 183 | pRemote->u32Version = u32Version;
|
---|
| 184 | pRemote->fu32Capabilities = fu32Capabilities;
|
---|
[49120] | 185 | pRemote->pDeviceDesc = NULL;
|
---|
| 186 | pRemote->cbDeviceDesc = 0;
|
---|
[44758] | 187 | pRemote->u64DeviceId = ASMAtomicIncU64(&mu64DeviceIdSrc);
|
---|
[44281] | 188 |
|
---|
| 189 | mpRemote = pRemote;
|
---|
| 190 |
|
---|
| 191 | /* Tell the server that this webcam will be used. */
|
---|
[49120] | 192 | rc = mParent->VideoInDeviceAttach(&mpRemote->deviceHandle, mpRemote);
|
---|
[44281] | 193 | if (RT_FAILURE(rc))
|
---|
| 194 | {
|
---|
| 195 | RTMemFree(mpRemote);
|
---|
| 196 | mpRemote = NULL;
|
---|
| 197 | break;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | /* Get the device description. */
|
---|
[49120] | 201 | rc = mParent->VideoInGetDeviceDesc(NULL, &mpRemote->deviceHandle);
|
---|
[44281] | 202 |
|
---|
| 203 | if (RT_FAILURE(rc))
|
---|
| 204 | {
|
---|
[49120] | 205 | mParent->VideoInDeviceDetach(&mpRemote->deviceHandle);
|
---|
[44281] | 206 | RTMemFree(mpRemote);
|
---|
| 207 | mpRemote = NULL;
|
---|
| 208 | break;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | LogFlowFunc(("sent DeviceDesc\n"));
|
---|
| 212 | } break;
|
---|
| 213 |
|
---|
[44758] | 214 | case VRDE_VIDEOIN_NOTIFY_ID_DETACH:
|
---|
[44281] | 215 | {
|
---|
[62379] | 216 | VRDEVIDEOINNOTIFYDETACH *p = (VRDEVIDEOINNOTIFYDETACH *)pvData; NOREF(p);
|
---|
[44281] | 217 | Assert(cbData == sizeof(VRDEVIDEOINNOTIFYDETACH));
|
---|
| 218 |
|
---|
| 219 | LogFlowFunc(("DETACH[%d,%d]\n", p->deviceHandle.u32ClientId, p->deviceHandle.u32DeviceId));
|
---|
| 220 |
|
---|
[63563] | 221 | /** @todo */
|
---|
[44281] | 222 | if (mpRemote)
|
---|
| 223 | {
|
---|
[44758] | 224 | if (mpDrv && mpDrv->pIWebcamUp)
|
---|
[62822] | 225 | mpDrv->pIWebcamUp->pfnDetached(mpDrv->pIWebcamUp, mpRemote->u64DeviceId);
|
---|
[49120] | 226 | /* mpRemote is deallocated in EmWebcamDestruct */
|
---|
[44281] | 227 | }
|
---|
| 228 | } break;
|
---|
| 229 |
|
---|
| 230 | default:
|
---|
| 231 | rc = VERR_INVALID_PARAMETER;
|
---|
| 232 | AssertFailed();
|
---|
| 233 | break;
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | return;
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | void EmWebcam::EmWebcamCbDeviceDesc(int rcRequest, void *pDeviceCtx, void *pvUser,
|
---|
| 240 | const VRDEVIDEOINDEVICEDESC *pDeviceDesc, uint32_t cbDeviceDesc)
|
---|
| 241 | {
|
---|
[63259] | 242 | RT_NOREF(pvUser);
|
---|
[44281] | 243 | EMWEBCAMREMOTE *pRemote = (EMWEBCAMREMOTE *)pDeviceCtx;
|
---|
| 244 | Assert(pRemote == mpRemote);
|
---|
| 245 |
|
---|
[44758] | 246 | LogFlowFunc(("mpDrv %p, rcRequest %Rrc %p %p %p %d\n",
|
---|
| 247 | mpDrv, rcRequest, pDeviceCtx, pvUser, pDeviceDesc, cbDeviceDesc));
|
---|
[44281] | 248 |
|
---|
| 249 | if (RT_SUCCESS(rcRequest))
|
---|
| 250 | {
|
---|
[49120] | 251 | /* Save device description. */
|
---|
| 252 | Assert(pRemote->pDeviceDesc == NULL);
|
---|
| 253 | pRemote->pDeviceDesc = (VRDEVIDEOINDEVICEDESC *)RTMemDup(pDeviceDesc, cbDeviceDesc);
|
---|
| 254 | pRemote->cbDeviceDesc = cbDeviceDesc;
|
---|
| 255 |
|
---|
| 256 | /* Try to attach the device. */
|
---|
[51612] | 257 | EmulatedUSB *pEUSB = mParent->getConsole()->i_getEmulatedUSB();
|
---|
[50580] | 258 | pEUSB->i_webcamAttachInternal("", "", "EmWebcam", pRemote);
|
---|
[44281] | 259 | }
|
---|
| 260 | else
|
---|
| 261 | {
|
---|
[49120] | 262 | mParent->VideoInDeviceDetach(&mpRemote->deviceHandle);
|
---|
[44281] | 263 | RTMemFree(mpRemote);
|
---|
| 264 | mpRemote = NULL;
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | void EmWebcam::EmWebcamCbControl(int rcRequest, void *pDeviceCtx, void *pvUser,
|
---|
| 269 | const VRDEVIDEOINCTRLHDR *pControl, uint32_t cbControl)
|
---|
| 270 | {
|
---|
[63259] | 271 | RT_NOREF(rcRequest);
|
---|
[62379] | 272 | EMWEBCAMREMOTE *pRemote = (EMWEBCAMREMOTE *)pDeviceCtx; NOREF(pRemote);
|
---|
[44281] | 273 | Assert(pRemote == mpRemote);
|
---|
| 274 |
|
---|
| 275 | LogFlowFunc(("rcRequest %Rrc %p %p %p %d\n",
|
---|
| 276 | rcRequest, pDeviceCtx, pvUser, pControl, cbControl));
|
---|
| 277 |
|
---|
| 278 | bool fResponse = (pvUser != NULL);
|
---|
| 279 |
|
---|
[44758] | 280 | if (mpDrv && mpDrv->pIWebcamUp)
|
---|
[44440] | 281 | {
|
---|
[62822] | 282 | mpDrv->pIWebcamUp->pfnControl(mpDrv->pIWebcamUp,
|
---|
| 283 | fResponse,
|
---|
| 284 | pvUser,
|
---|
| 285 | mpRemote->u64DeviceId,
|
---|
| 286 | pControl,
|
---|
| 287 | cbControl);
|
---|
[44440] | 288 | }
|
---|
[44281] | 289 |
|
---|
| 290 | RTMemFree(pvUser);
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | void EmWebcam::EmWebcamCbFrame(int rcRequest, void *pDeviceCtx,
|
---|
| 294 | const VRDEVIDEOINPAYLOADHDR *pFrame, uint32_t cbFrame)
|
---|
| 295 | {
|
---|
[63259] | 296 | RT_NOREF(rcRequest, pDeviceCtx);
|
---|
[44281] | 297 | LogFlowFunc(("rcRequest %Rrc %p %p %d\n",
|
---|
| 298 | rcRequest, pDeviceCtx, pFrame, cbFrame));
|
---|
| 299 |
|
---|
[44758] | 300 | if (mpDrv && mpDrv->pIWebcamUp)
|
---|
[44440] | 301 | {
|
---|
[47416] | 302 | if ( cbFrame >= sizeof(VRDEVIDEOINPAYLOADHDR)
|
---|
| 303 | && cbFrame >= pFrame->u8HeaderLength)
|
---|
| 304 | {
|
---|
| 305 | uint32_t cbImage = cbFrame - pFrame->u8HeaderLength;
|
---|
| 306 | const uint8_t *pu8Image = cbImage > 0? (const uint8_t *)pFrame + pFrame->u8HeaderLength: NULL;
|
---|
| 307 |
|
---|
[62822] | 308 | mpDrv->pIWebcamUp->pfnFrame(mpDrv->pIWebcamUp,
|
---|
| 309 | mpRemote->u64DeviceId,
|
---|
| 310 | pFrame,
|
---|
| 311 | pFrame->u8HeaderLength,
|
---|
| 312 | pu8Image,
|
---|
| 313 | cbImage);
|
---|
[47416] | 314 | }
|
---|
[44440] | 315 | }
|
---|
[44281] | 316 | }
|
---|
| 317 |
|
---|
| 318 | int EmWebcam::SendControl(EMWEBCAMDRV *pDrv, void *pvUser, uint64_t u64DeviceId,
|
---|
| 319 | const VRDEVIDEOINCTRLHDR *pControl, uint32_t cbControl)
|
---|
| 320 | {
|
---|
| 321 | AssertReturn(pDrv == mpDrv, VERR_NOT_SUPPORTED);
|
---|
| 322 |
|
---|
| 323 | int rc = VINF_SUCCESS;
|
---|
| 324 |
|
---|
| 325 | EMWEBCAMREQCTX *pCtx = NULL;
|
---|
| 326 |
|
---|
| 327 | /* Verify that there is a remote device. */
|
---|
| 328 | if ( !mpRemote
|
---|
| 329 | || mpRemote->u64DeviceId != u64DeviceId)
|
---|
| 330 | {
|
---|
| 331 | rc = VERR_NOT_SUPPORTED;
|
---|
| 332 | }
|
---|
| 333 |
|
---|
| 334 | if (RT_SUCCESS(rc))
|
---|
| 335 | {
|
---|
| 336 | pCtx = (EMWEBCAMREQCTX *)RTMemAlloc(sizeof(EMWEBCAMREQCTX));
|
---|
| 337 | if (!pCtx)
|
---|
| 338 | {
|
---|
| 339 | rc = VERR_NO_MEMORY;
|
---|
| 340 | }
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | if (RT_SUCCESS(rc))
|
---|
| 344 | {
|
---|
| 345 | pCtx->pRemote = mpRemote;
|
---|
| 346 | pCtx->pvUser = pvUser;
|
---|
| 347 |
|
---|
[49120] | 348 | rc = mParent->VideoInControl(pCtx, &mpRemote->deviceHandle, pControl, cbControl);
|
---|
[44281] | 349 |
|
---|
| 350 | if (RT_FAILURE(rc))
|
---|
| 351 | {
|
---|
| 352 | RTMemFree(pCtx);
|
---|
| 353 | }
|
---|
| 354 | }
|
---|
| 355 |
|
---|
| 356 | return rc;
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 | /* static */ DECLCALLBACK(void *) EmWebcam::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
|
---|
| 360 | {
|
---|
| 361 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
| 362 | PEMWEBCAMDRV pThis = PDMINS_2_DATA(pDrvIns, PEMWEBCAMDRV);
|
---|
| 363 |
|
---|
[44758] | 364 | LogFlowFunc(("pszIID:%s\n", pszIID));
|
---|
| 365 |
|
---|
[44281] | 366 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
|
---|
[62824] | 367 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIWEBCAMDRV, &pThis->IWebcamDrv);
|
---|
[44281] | 368 | return NULL;
|
---|
| 369 | }
|
---|
| 370 |
|
---|
[45029] | 371 | /* static */ DECLCALLBACK(void) EmWebcam::drvDestruct(PPDMDRVINS pDrvIns)
|
---|
| 372 | {
|
---|
| 373 | PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
|
---|
| 374 | PEMWEBCAMDRV pThis = PDMINS_2_DATA(pDrvIns, PEMWEBCAMDRV);
|
---|
[49120] | 375 | EMWEBCAMREMOTE *pRemote = pThis->pRemote;
|
---|
[45029] | 376 |
|
---|
[49120] | 377 | LogFlowFunc(("iInstance %d, pRemote %p, pIWebcamUp %p\n",
|
---|
| 378 | pDrvIns->iInstance, pRemote, pThis->pIWebcamUp));
|
---|
[45029] | 379 |
|
---|
[49120] | 380 | if (pRemote && pRemote->pEmWebcam)
|
---|
[45029] | 381 | {
|
---|
[49120] | 382 | pRemote->pEmWebcam->EmWebcamDestruct(pThis);
|
---|
[45029] | 383 | }
|
---|
| 384 | }
|
---|
| 385 |
|
---|
[44281] | 386 | /* static */ DECLCALLBACK(int) EmWebcam::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
|
---|
| 387 | {
|
---|
[63259] | 388 | RT_NOREF(fFlags);
|
---|
[45029] | 389 | PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
|
---|
[44758] | 390 | LogFlowFunc(("iInstance:%d, pCfg:%p, fFlags:%x\n", pDrvIns->iInstance, pCfg, fFlags));
|
---|
[44281] | 391 |
|
---|
| 392 | PEMWEBCAMDRV pThis = PDMINS_2_DATA(pDrvIns, PEMWEBCAMDRV);
|
---|
| 393 |
|
---|
| 394 | AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
|
---|
| 395 | ("Configuration error: Not possible to attach anything to this driver!\n"),
|
---|
| 396 | VERR_PDM_DRVINS_NO_ATTACH);
|
---|
| 397 |
|
---|
[44758] | 398 | /* Check early that there is a device. No need to init anything if there is no device. */
|
---|
[62823] | 399 | pThis->pIWebcamUp = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIWEBCAMDEV);
|
---|
[44758] | 400 | if (pThis->pIWebcamUp == NULL)
|
---|
| 401 | {
|
---|
| 402 | LogRel(("USBWEBCAM: Emulated webcam device does not exist.\n"));
|
---|
| 403 | return VERR_PDM_MISSING_INTERFACE;
|
---|
| 404 | }
|
---|
| 405 |
|
---|
[44281] | 406 | void *pv = NULL;
|
---|
| 407 | int rc = CFGMR3QueryPtr(pCfg, "Object", &pv);
|
---|
[44758] | 408 | if (!RT_VALID_PTR(pv))
|
---|
| 409 | rc = VERR_INVALID_PARAMETER;
|
---|
| 410 | AssertMsgReturn(RT_SUCCESS(rc),
|
---|
| 411 | ("Configuration error: No/bad \"Object\" %p value! rc=%Rrc\n", pv, rc), rc);
|
---|
[44281] | 412 |
|
---|
[44758] | 413 | /* Everything ok. Initialize. */
|
---|
[49120] | 414 | pThis->pRemote = (EMWEBCAMREMOTE *)pv;
|
---|
| 415 | pThis->pRemote->pEmWebcam->EmWebcamConstruct(pThis);
|
---|
[44281] | 416 |
|
---|
| 417 | pDrvIns->IBase.pfnQueryInterface = drvQueryInterface;
|
---|
| 418 |
|
---|
[62824] | 419 | pThis->IWebcamDrv.pfnReady = drvEmWebcamReady;
|
---|
| 420 | pThis->IWebcamDrv.pfnControl = drvEmWebcamControl;
|
---|
[44281] | 421 |
|
---|
| 422 | return VINF_SUCCESS;
|
---|
| 423 | }
|
---|
| 424 |
|
---|
| 425 | /* static */ const PDMDRVREG EmWebcam::DrvReg =
|
---|
| 426 | {
|
---|
| 427 | /* u32Version */
|
---|
| 428 | PDM_DRVREG_VERSION,
|
---|
| 429 | /* szName[32] */
|
---|
| 430 | "EmWebcam",
|
---|
| 431 | /* szRCMod[32] */
|
---|
| 432 | "",
|
---|
| 433 | /* szR0Mod[32] */
|
---|
| 434 | "",
|
---|
| 435 | /* pszDescription */
|
---|
| 436 | "Main Driver communicating with VRDE",
|
---|
| 437 | /* fFlags */
|
---|
| 438 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
| 439 | /* fClass */
|
---|
| 440 | PDM_DRVREG_CLASS_USB,
|
---|
| 441 | /* cMaxInstances */
|
---|
| 442 | 1,
|
---|
| 443 | /* cbInstance */
|
---|
| 444 | sizeof(EMWEBCAMDRV),
|
---|
| 445 | /* pfnConstruct */
|
---|
| 446 | EmWebcam::drvConstruct,
|
---|
| 447 | /* pfnDestruct */
|
---|
| 448 | EmWebcam::drvDestruct,
|
---|
| 449 | /* pfnRelocate */
|
---|
| 450 | NULL,
|
---|
| 451 | /* pfnIOCtl */
|
---|
| 452 | NULL,
|
---|
| 453 | /* pfnPowerOn */
|
---|
| 454 | NULL,
|
---|
| 455 | /* pfnReset */
|
---|
| 456 | NULL,
|
---|
| 457 | /* pfnSuspend */
|
---|
| 458 | NULL,
|
---|
| 459 | /* pfnResume */
|
---|
| 460 | NULL,
|
---|
| 461 | /* pfnAttach */
|
---|
| 462 | NULL,
|
---|
| 463 | /* pfnDetach */
|
---|
| 464 | NULL,
|
---|
| 465 | /* pfnPowerOff */
|
---|
| 466 | NULL,
|
---|
| 467 | /* pfnSoftReset */
|
---|
| 468 | NULL,
|
---|
| 469 | /* u32VersionEnd */
|
---|
| 470 | PDM_DRVREG_VERSION
|
---|
| 471 | };
|
---|
| 472 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|