Accessing a USB WebCAM

      Accessing a USB WebCAM

      Admin note: This thread has been splittet from usbclient.lib

      No, of course I don't. I try to compile the MS open source webcam driver <!-- m --><a class="postlink" href="http://www.codeplex.com/cewebcam">http://www.codeplex.com/cewebcam</a><!-- m --> against your SDK. It does compile without any problems against the headers of your SDK but it misses a library to link the USB-functionality to. The precompiled binary distributions of the driver work well with your platform as long as you do not try to capture images, but I guess these are compiled for older versions of win CE so I would prefer to compile it explicitely for the picocom.

      I know there is an alternate camera driver shipping with CE6 providing a direct show interface but as I got as a first impression (with a windows XP desktop system) direct show behaves very unhandy when trying to do still captures instead of streaming video. (Streaming video will be a problem due to excessive USB-Bandwidth allocation when the system needs to support multiple USB-devices)

      Re: usbclient libs

      Ok now this is getting clearer.
      To compile this driver the PicoCOM SDK is not sufficient. You will need a Driver Development Kit which will be the platform builder for WindowsCE device drivers. For this reason I have compiled this library within the PicoCOM2 environment for you.
      Files
      • WebCAM-DLL.zip

        (68.19 kB, downloaded 156 times, last: )
      Software developer, F&amp;S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

      Re: usbclient libs

      I am wondering why all includes are already there. Just the .lib file is missing in your sdk. Anyway, thank you for compiling the driver. Would it be possible to provide me the debug version too? It contains several debug outputs that give information on driver failure.
      Btw. I am using picocom1 but I guess the difference will be not that huge, isn't it?

      Re: usbclient libs

      I have updated the ZIP package above. It now also includes the debug version of the camera driver.

      "goennema" wrote:

      Btw. I am using picocom1 but I guess the difference will be not that huge, isn't it?

      Yes, this should not be a problem, as the libraries the driver is build with are common for all WindowsCE 6.0 devices.

      Meanwhile we have tested the USB driver, too and we succedded in capturing a still image and write it into a file.
      Software developer, F&amp;S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

      Re: usbclient libs

      Oh, most likely you got further than me. The driver that you have compiled freezes when I try to capture a still or if I try to start streaming. That is the same behaviour I see with the precompiled release binary from codeplex. The debug binary from codeplex works better.

      And you did a capture using ioctl IOCTL_CAMERA_DEVICE_GETSTILLIMAGE? This did not work with any camera I tested. All of them returned error 258 stating something like "WebCam: Next Frame event not signaled rc 258" on the debug console (when using the debug binary from codeplex, your webcam.dll freezes on ioctl). This is strange thus IOCTL_CAMERA_DEVICE_QUERYSTILLFORMATS reports that my camera do support still frame modes. Can you tell me what type of camera you use?

      IOCTL_CAMERA_DEVICE_GETNEXTVIDEOFRAME in streaming mode indeed works fine (with the debug dll) but the timing overhead for starting and stopping streaming for each frame is inacceptable.

      EDIT: the debug binary you supplied in your last post does freeze too. The only one that does anything useful with my unit is the codeplex debug binary.

      Re: usbclient libs

      Here is the code how we are capturing an image, also tested on PicoCOM1. We are using logitec webcam.

      Source Code

      1. int CWebCamTestDlg::WriteJPEG (LPTSTR lpszName, PBYTE pData, int nSize)
      2. {
      3. BYTE MJPGDHTSeg[0x1A4] = {
      4. /* JPEG DHT Segment for YCrCb omitted from MJPG data */
      5. 0xFF,0xC4,0x01,0xA2,
      6. 0x00,0x00,0x01,0x05,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      7. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x01,0x00,0x03,0x01,0x01,0x01,0x01,
      8. 0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
      9. 0x08,0x09,0x0A,0x0B,0x10,0x00,0x02,0x01,0x03,0x03,0x02,0x04,0x03,0x05,0x05,0x04,0x04,0x00,
      10. 0x00,0x01,0x7D,0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12,0x21,0x31,0x41,0x06,0x13,0x51,0x61,
      11. 0x07,0x22,0x71,0x14,0x32,0x81,0x91,0xA1,0x08,0x23,0x42,0xB1,0xC1,0x15,0x52,0xD1,0xF0,0x24,
      12. 0x33,0x62,0x72,0x82,0x09,0x0A,0x16,0x17,0x18,0x19,0x1A,0x25,0x26,0x27,0x28,0x29,0x2A,0x34,
      13. 0x35,0x36,0x37,0x38,0x39,0x3A,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x53,0x54,0x55,0x56,
      14. 0x57,0x58,0x59,0x5A,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x73,0x74,0x75,0x76,0x77,0x78,
      15. 0x79,0x7A,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,
      16. 0x9A,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,
      17. 0xBA,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,
      18. 0xDA,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,
      19. 0xF8,0xF9,0xFA,0x11,0x00,0x02,0x01,0x02,0x04,0x04,0x03,0x04,0x07,0x05,0x04,0x04,0x00,0x01,
      20. 0x02,0x77,0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,
      21. 0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91,0xA1,0xB1,0xC1,0x09,0x23,0x33,0x52,0xF0,0x15,0x62,
      22. 0x72,0xD1,0x0A,0x16,0x24,0x34,0xE1,0x25,0xF1,0x17,0x18,0x19,0x1A,0x26,0x27,0x28,0x29,0x2A,
      23. 0x35,0x36,0x37,0x38,0x39,0x3A,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x53,0x54,0x55,0x56,
      24. 0x57,0x58,0x59,0x5A,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x73,0x74,0x75,0x76,0x77,0x78,
      25. 0x79,0x7A,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x92,0x93,0x94,0x95,0x96,0x97,0x98,
      26. 0x99,0x9A,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,
      27. 0xB9,0xBA,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,
      28. 0xD9,0xDA,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,
      29. 0xF9,0xFA
      30. };
      31. int rc = 0;
      32. DWORD dwBytes;
      33. HANDLE hFile = CreateFile (lpszName, GENERIC_WRITE | GENERIC_READ, 0, NULL, CREATE_ALWAYS, 0, NULL);
      34. if (hFile != INVALID_HANDLE_VALUE)
      35. {
      36. BYTE bHdr[] =
      37. {
      38. 0xff,0xd8, // SOI
      39. 0xff,0xe0, // APP0
      40. 0x00,0x10, // APP0 Hdr size
      41. 0x4a,0x46,0x49,0x46,0x00, // ID string
      42. 0x01,0x01, // Version
      43. 0x00, // Bits per type
      44. 0x00, 0x00, // X density
      45. 0x00, 0x00, // Y density
      46. 0x00, // X Thumbnail size
      47. 0x00, // Y Thumbnail size
      48. };
      49. WriteFile (hFile, bHdr, sizeof (bHdr), &dwBytes, NULL);
      50. // Write DHT color segment needed for stand-alone file
      51. WriteFile (hFile, MJPGDHTSeg, sizeof (MJPGDHTSeg), &dwBytes, NULL);
      52. // try removing AVI header from image
      53. #if 1
      54. int n = *(pData+4);
      55. n = n << 8;
      56. n += *(pData+5)+4;
      57. PBYTE p2 = pData + n;
      58. WriteFile (hFile, p2, nSize-n, &dwBytes, NULL);
      59. #else
      60. WriteFile (hFile, pData, nSize, &dwBytes, NULL);
      61. #endif
      62. DEBUGMSG (1, (TEXT("Write %d bytes to image file.\r\n"), dwBytes));
      63. CloseHandle (hFile);
      64. } else
      65. rc = GetLastError();
      66. return rc;
      67. }
      68. void CWebCamTestDlg::OnBnClickedCapture()
      69. {
      70. HANDLE hCam;
      71. BOOL bNoError = FALSE;
      72. FORMATPROPS cFormats[10];
      73. VIDFORMATSTRUCT cVideoFormat;
      74. DWORD dwBytes;
      75. DWORD dwFormat = 1;
      76. LPBYTE pData = 0;
      77. DWORD dwSize = 0;
      78. DWORD dwBuff;
      79. /* Open USB camera */
      80. hCam = CreateFile (L"CAM1:", GENERIC_WRITE | GENERIC_READ,
      81. 0, NULL, OPEN_EXISTING, 0, NULL);
      82. /* Query availble still image formats */
      83. bNoError = DeviceIoControl (hCam, IOCTL_CAMERA_DEVICE_QUERYSTILLFORMATS,
      84. (LPVOID)&dwFormat, sizeof (DWORD),
      85. &cFormats, 10*sizeof(FORMATPROPS), &dwBytes, NULL);
      86. if (!bNoError)
      87. {
      88. RETAILMSG(1, (L"IOCTL_CAMERA_DEVICE_QUERYSTILLFORMATS failed (LE:%d)\r\n",
      89. GetLastError()));
      90. goto CLEANUP;
      91. }
      92. /* Select image format and prepare image buffer based */
      93. memset (&cVideoFormat, 0, sizeof (VIDFORMATSTRUCT));
      94. cVideoFormat.cbSize = sizeof (VIDFORMATSTRUCT);
      95. /* Note: A list of available formats are queried before and stored in cFormats */
      96. cVideoFormat.wFormatIndex = 1;
      97. cVideoFormat.wFrameIndex = 2;
      98. bNoError = DeviceIoControl (hCam, IOCTL_CAMERA_DEVICE_GETSTILLIMAGE,
      99. &cVideoFormat, sizeof (VIDFORMATSTRUCT), 0, 0, &dwBytes, NULL);
      100. if (!bNoError)
      101. {
      102. RETAILMSG(1, (L"IOCTL_CAMERA_DEVICE_GETSTILLIMAGE failed (LE:%d)\r\n",
      103. GetLastError()));
      104. goto CLEANUP;
      105. }
      106. pData = (PBYTE) LocalAlloc (LPTR, dwBytes);
      107. dwBuff = dwBytes;
      108. /* Read the image */
      109. bNoError = DeviceIoControl (hCam, IOCTL_CAMERA_DEVICE_GETSTILLIMAGE,
      110. &cVideoFormat, sizeof (VIDFORMATSTRUCT), pData, dwBuff, &dwBytes, NULL);
      111. if (!bNoError)
      112. {
      113. RETAILMSG(1, (L"IOCTL_CAMERA_DEVICE_QUERYSTILLFORMATS failed (LE:%d)\r\n",
      114. GetLastError()));
      115. goto CLEANUP;
      116. }
      117. /* Write the JPG into a file */
      118. WriteJPEG (L"\\USBCam.jpg", pData, dwBuff);
      119. CLEANUP:
      120. if (pData)
      121. LocalFree(pData);
      122. if (INVALID_HANDLE_VALUE != hCam)
      123. CloseHandle(hCam);
      124. //return bNoError;
      125. }


      I must admit that I have added the driver directly into kernel. Could you tell me how you have installed the driver on PicoCOM? Maybe there might be a problem.
      Software developer, F&amp;S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

      Re: usbclient libs

      I put the webcam.dll to \\FFSDISK\Drivers\webcam.dll and associated it to the USB attach-process according to the manual delivered with the webcam driver.

      the NDCUCFG-script looks like this:

      Source Code

      1. reg open \Drivers\USB\ClientDrivers
      2. reg create key Video_Class
      3. reg create key Video_Class
      4. reg set value Prefix string "CAM"
      5. reg set value Dll string "Webcam.dll"
      6. reg open \Drivers\USB\LoadClients\Default\Default
      7. reg create key 14
      8. reg create key Video_Class
      9. reg set value DLL string "\FFSDISK\Drivers\webcam.dll"
      10. reg open \Drivers\USB\LoadClients
      11. reg create key 1133_2241
      12. reg create key Default
      13. reg create key Default
      14. reg create key Video_Class
      15. reg set value DLL string "\FFSDISK\Drivers\webcam.dll"
      16. reg open \Drivers\USB\LoadClients
      17. reg create key 1133_2242
      18. reg create key Default
      19. reg create key Default
      20. reg create key Video_Class
      21. reg set value DLL string "\FFSDISK\Drivers\webcam.dll"
      22. reg open \Drivers\USB\LoadClients
      23. reg create key 1133_2243
      24. reg create key Default
      25. reg create key Default
      26. reg create key Video_Class
      27. reg set value DLL string "\FFSDISK\Drivers\webcam.dll"
      28. reg open \Drivers\USB\LoadClients
      29. reg create key 1133_2245
      30. reg create key Default
      31. reg create key Default
      32. reg create key Video_Class
      33. reg set value DLL string "\FFSDISK\Drivers\webcam.dll"
      34. reg save


      I'll try out your code, but in its core functionality it looks too similiar to mine to expect too much of it. In parallel I will go and pick a logitech-camera to be sure to eliminate hardware issues.

      Re: usbclient libs

      Tried your code with my cameras, all of them report this (like expected):

      WebCam: Next Frame event not signaled rc 258
      IOCTL_CAMERA_DEVICE_QUERYSTILLFORMATS failed (LE:258)

      Note: I tried it with the codeplex debug-dll as it showed up the best results until now.

      Re: usbclient libs

      interesting issue:

      with your code, the debug-driver you supplied today, does NOT freeze, but shows more comprehensive errors on the debug console:

      Source Code

      1. WebCam: Error calling IssueIsochTransfer 87 87
      2. ORMAWebCam: Camera error code 0
      3. WebCam: Error calling IssueIsochTransfer 87 87
      4. TS WebCam: Camera error code 0
      5. WebCam: Error calling IssueIsochTransfer 87 87
      6. faiWebCam: Camera error code 0
      7. WebCam: Error calling IssueIsochTransfer 87 87
      8. led WebCam: Camera error code 0
      9. WebCam: Error calling IssueIsochTransfer 87 87
      10. (LE:WebCam: Camera error code 0
      11. WebCam: Error calling IssueIsochTransfer 87 87
      12. 258WebCam: Camera error code 0
      13. WebCam: Error calling IssueIsochTransfer 87 87
      14. )
      15. WebCam: Camera error code 0
      16. WebCam: Error calling IssueIsochTransfer 87 87
      17. WebCam: Camera error code 0
      18. WebCam: ReaReadIsocThreaddThread--
      19. WebCam: Error calling IssueVendorTransfer rc: 31 ExtErr: 31
      20. WebCam: Error set camera power rc 31


      The application console still shows:

      IOCTL_CAMERA_DEVICE_QUERYSTILLFORMATS failed (LE:258)

      Re: usbclient libs

      Please try to replace your registry settings with the following ones:

      Source Code

      1. reg open \Drivers\USB\ClientDrivers
      2. reg create key Video_Class
      3. reg set value Prefix string CAM
      4. reg set value Dll string \ffsdisk\drivers\webcam.dll
      5. reg open \Drivers\USB\LoadClients
      6. reg create key 1133_2245
      7. reg create key Default
      8. reg create key Default
      9. reg create key Video_Class
      10. reg set value dll string \ffsdisk\drivers\webcam.dll
      11. reg open \Drivers\USB\LoadClients
      12. reg create key Default
      13. reg create key Default
      14. reg create key 14
      15. reg create key Video_Class
      16. reg set value dll string \ffsdisk\drivers\webcam.dll
      17. reg save
      Software developer, F&amp;S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

      Re: usbclient libs

      tried that and verified correct application using the remote registry editor.

      This makes the picocom report an "unidentified USB device" on the desktop. Answering the prompt for "driver name" with \ffsdisk\drivers\webcam.dll makes the picocom generate the registry entries as stated in my previous post.

      Re: usbclient libs

      Sorry, there was an error in the script posted berfore. I have corrected this. ("reg create Video_Class" -> "reg create key Video_Class").
      I have tested it again and its working without any problems with our camera.
      Software developer, F&amp;S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

      Re: usbclient libs

      Thank you, but this did not change the cameras behaviour.

      But at last I succeeded after I tried a logitech quickcam. The Quickcam does its job quite good. And just for Info: There is at least one camera in my stock that freezes the driver you compiled for me (the debug binary from codeplex indeed works - or better, it does not crash/freeze). Some other cameras just do not work with the driver. I can use the register to read the camera properties but all tries to capture an image do fail.

      All in all not a really satisfactory result, but thank you for your help

      Re: Accessing a USB WebCAM

      Well I've put the WebCam.dll in the \FFSDSK\Drivers\ map and added the key's in the registry, but I'm getting an error on opening CAM1. Should I see anything on the display when I plug in the QuickCam Pro5000 or on the debug output on rebooting the PicoCOM2?
      You are already confirm with BSP?
      I assume to built the components and copy dependencies to release directory before make a runtime image is enouth.
      F&S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.