Recent

Author Topic: Web camera in WinCe  (Read 9919 times)

proxy3d

  • Jr. Member
  • **
  • Posts: 76
Web camera in WinCe
« on: July 31, 2013, 09:26:51 pm »

I'm trying to write a module receiving the camera images in WinCe.
1) There is a ready-made solutions to Lazarus to work with cameras in WinCe?
2) I did write the code to get a list of cameras in WinCe
Code: [Select]
procedure TRVWebCam.CreateVideoDeviceList;
var
     hr      : Integer;
     hDriver : THandle;
     di      : TDEVMGR_DEVICE_INFORMATION;
     DeviceName : PWideChar;
     guidCam : TGUID;
     nCount  : Integer;
begin
  {$IFDEF wince}CoInitializeEx(nil, COINIT_APARTMENTTHREADED);{$ENDIF}

  hr        := S_OK;
  guidCam   := StringToGUID('{CB998A05-122C-4166-846A-933E4D7E3C86}');
  di.dwSize := sizeof(di);

  hDriver := FindFirstDevice( DeviceSearchByGuid, @guidCam, @di );

  nCount  := 0;
  SetLength(MArray, 100);
  if( hDriver <> INVALID_HANDLE_VALUE ) then
  begin
    FVideoDeviceList  := TStringList.Create;
    FVideoDeviceIndex := 0;

    repeat
      DeviceName:=AllocMem((MAX_PATH+1)*sizeof(WideChar));
      StrLCopy(DeviceName, di.szLegacyName, Length(TDEVMGR_DEVICE_INFORMATION.szLegacyName));
      FVideoDeviceList.Add(DeviceName);
      Freemem(DeviceName);

      DeviceName:=AllocMem((MAX_PATH+1)*sizeof(WideChar));
      StrLCopy(DeviceName, di.szDeviceName, Length(TDEVMGR_DEVICE_INFORMATION.szDeviceName));
      MArray[nCount] := DeviceName;
      Inc(nCount);
      Freemem(DeviceName);
    until not FindNextDevice( hDriver, @di );
    FindClose( hDriver );
  end else
  begin
    FVideoDeviceIndex := -1;
  end;
  SetLength(MArray, nCount);
end;


3) I can not find the GUID to define interfaces for camera selection.
MSDN: http://msdn.microsoft.com/en-us/library/ms940046.aspx

Code: [Select]
// Initialize the video capture filter
pVideoCap.CoCreateInstance( CLSID_VideoCapture );
pVideoCap.QueryInterface( &pPropertyBag );
varCamName = L"CAM1:";
if(( varCamName.vt == VT_BSTR ) == NULL ) {
  return E_OUTOFMEMORY;
}
PropBag.Write( L"VCapName", &varCamName );   
pPropertyBag->Load( &PropBag, NULL );
pPropertyBag.Release();
pGraph->AddFilter( pVideoCap, L"Video capture source" );

lazarus:
Code: [Select]
procedure SetCameraDriver( pGraph : IGraphBuilder; pwzName : WCHAR);
var
     FPropertyBag : IPropertyBag;
     pVideoCap    : IBaseFilter;
     hr           : HRESULT;
     PropBag      : <b>?????????????</b>;
begin
  // Initialize the video capture filter
  CoCreateInstance(CLSID_VideoCapture, NIL, CLSCTX_INPROC,
    IID_IBaseFilter, pVideoCap);

  hr:= pVideoCap.QueryInterface(IID_IPropertyBag, FPropertyBag);
  if Failed(hr) then exit;

  PropBag.Write( 'VCapName', pwzName );
  FPropertyBag.Read( @PropBag, NULL );
  FPropertyBag.Release();
  pGraph.AddFilter( pVideoCap, 'Video capture source');
end;

I have a problem with the description PropBag. GUID? In Lazarus is a description of these interfaces?
« Last Edit: July 31, 2013, 09:30:12 pm by proxy3d »

proxy3d

  • Jr. Member
  • **
  • Posts: 76
Re: Web camera in WinCe
« Reply #1 on: August 16, 2013, 02:35:49 pm »
I try to solve problems for WinCE. In WinCe not implement interfaces SampleGrabber and NullRender

1) I am implementing SampleGrabber and Nullrenderer and class CTransInPlaceFilter and CBaseVideoRenderer
2) Another simple solution writing class VideoRendere. It is based on the class CBaseVideoRenderer, where you need to replace the two methods CheckMediaType and DoRenderSample
3) I'm trying to see the work DSPack, but when compiling I get errors. For example, the compiler writes that there is no CreateItemMoniker, but there CreateItemMoniker in WinCE.
http://msdn.microsoft.com/ru-ru/library/ms864395.aspx

The most simple solution is 2. If the rendering specify nil, the camera works and shows the video in a  window with the style of None, in the upper left.

Code: [Select]
hr:=FCaptureGraphBuilder.RenderStream(@PIN_CATEGORY_CAPTURE,
                         @MEDIATYPE_Video,
                         FVideoCaptureFilter,
                         nil,
                         nil);

proxy3d

  • Jr. Member
  • **
  • Posts: 76
Re: Web camera in WinCe
« Reply #2 on: August 16, 2013, 03:01:27 pm »
I try to use my VideoRenderer, which is the basis for the class CBaseVideoRenderer.

Code: [Select]
    if Succeeded(CoCreateInstance(CLSID_FilterGraph, NIL, CLSCTX_INPROC_SERVER,
         IID_IGraphBuilder, FGraphBuilder)) then //Объект для графа фильтров
      if Succeeded(CoCreateInstance(CLSID_CaptureGraphBuilder, NIL,
          CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, FCaptureGraphBuilder)) then
       FCaptureGraphBuilder.SetFiltergraph(FGraphBuilder); //Задаем граф фильтро

...
   FVideoRenderer := TRVVideoRenderer.Create(CLSID_RVVideoRenderer, 'VideoRenderer', nil, hr);
    if Failed(hr) then exit;
    hr:= FGraphBuilder.AddFilter(FVideoRenderer, 'VideoRenderer');
    if Failed(hr) then exit;
...
  hr:=FCaptureGraphBuilder.RenderStream(@PIN_CATEGORY_PREVIEW,
                         @MEDIATYPE_Video,
                         FVideoCaptureFilter,
                         nil,
                         FVideoRenderer)

On RenderStream an exception. How do I find the line where the error occurs? In the file "lcldebug.log" no information about the exception. I understand that the call to the FVideoRenderer and error in them (I think I made ​​a mistake when implementing CBaseVideoRenderer). How do I know which line of code or a method generates an error?

Quote
TApplication.HandleException Bus error or misaligned data access
  Stack trace:
  $4182A504
  $0020A4AC
  $4182CF58
« Last Edit: August 16, 2013, 03:21:40 pm by proxy3d »

proxy3d

  • Jr. Member
  • **
  • Posts: 76
Re: Web camera in WinCe
« Reply #3 on: August 17, 2013, 01:19:03 pm »
A simple solution to display in WebCamera WinCe, use CLSID_VideoRenderer. When the video output is possible to copy the video frame. For a 533MHz processor, the video from the camera is stretched to full screen 800x400 and displays fast (real frame resolution 200x200).
If each frame to use JPEG, it is slow.
How to Lazarus can speed JPEG? There are any solution?

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Web camera in WinCe
« Reply #4 on: August 17, 2013, 01:30:18 pm »
If each frame to use JPEG, it is slow.
How to Lazarus can speed JPEG? There are any solution?

You mean displaying JPEG on a desktop? You could look into imaging libraries such as imagemagick perhaps:
http://wiki.lazarus.freepascal.org/PascalMagick#About_PascalMagick

Other libraries like vampyre are perhaps also useful.

If on Windows CE: no idea if these libraries are ported/supported.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

proxy3d

  • Jr. Member
  • **
  • Posts: 76
Re: Web camera in WinCe
« Reply #5 on: August 17, 2013, 01:55:30 pm »

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Web camera in WinCe
« Reply #6 on: August 17, 2013, 09:03:01 pm »
Many thanks for all this information, appreciate it.

I don't know you if you're aware that a lot of the DirectShow functionality is already available for us.  I don't know what headers you're using, so you may have come across this already.  Search for DS Pack or visit:

http://forum.lazarus.freepascal.org/index.php?topic=16797.0

And, absolutely no idea if this will work under Win CE, though your work seems to indicate it might.

At the moment I'm only using DSPack for video playback, but happy to share code if you need it...
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

proxy3d

  • Jr. Member
  • **
  • Posts: 76
Re: Web camera in WinCe
« Reply #7 on: August 19, 2013, 03:52:15 pm »
Header files are the same. They will not write over another. I have DSPack-lazarus. In WinCe not implemented some interfaces (ISampleGrabber, INullRender and some others) and some API (I wrote a replacement).

If you want to display video from a camera, it is not difficult. You need to use CLSID_VideoRenderer. You can copy images from the Canvas, when the video is displayed (this is a bad decision).

The normal solution is the implementation of SampleGrabber (based on the class CTransInPlaceFilter) and Nullrenderer (based on the class CBaseVideoRenderer).
Or the realization of MyVideoRenderer (based on the class CBaseVideoRenderer).

The problem is the normal implementation of these classes under WinCe, since I do not know how you can debug the code in WinCe (I compile the code in Windows and run it on a real device with WinCe). So I do not know how you can look at what line an error occurs. Finding bugs will take some time.

Now I show an image with WebCamera the screen, choose the camera, get the camera list, get a list of available modes (permissions, video data format, etc.) and set mode.
« Last Edit: August 19, 2013, 03:58:42 pm by proxy3d »

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Web camera in WinCe
« Reply #8 on: August 19, 2013, 05:14:54 pm »
Ah, thanks for the clarification.  I was wondering why you weren't using the TFilterGraph and TSampleGrabber that is in the DSPack.  If you're needing to build your own filters, then that explains that.  Been a long time since I created any DS filters.  Don't want to do that again in a hurry, so well done on achieving what you have :-)

RE: Debugging under WINCE.   
I don't know anything that will directly help you (it may be possible to debug on one OS with the IDE on another, but I just don't know how).

I can only suggest you create a log file, and output to that as you go along.  The following two Includes may assist you to quickly copy paste...  I've never used them myself, but stumbled across them while scouring the FPC/Lazarus source code trying to find a TListView bug a few years ago. 

 {$I %FILE%} // Current pas file
 {$I %LINE%} // Current line number

I believe you just just treat the above Includes as Strings.

Code: [Select]
Var
  sLogEntry : String;

Begin
  sLogEntry := 'Exception raised in ' + {$I %FILE%}  + ' at line: ' + {$I %LINE%};

« Last Edit: August 19, 2013, 05:17:15 pm by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

 

TinyPortal © 2005-2018