Camera Control needed for Tablet

Re: Camera Control needed for Tablet

Postby Antonio Linares » Wed Aug 24, 2016 11:10 pm

Tim,

Please copy my PRG to FWH\samples\dshow.prg and do buildh32.bat dshow

Thats how I am testing it here
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Camera Control needed for Tablet

Postby Antonio Linares » Wed Aug 24, 2016 11:15 pm

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Camera Control needed for Tablet

Postby TimStone » Wed Aug 24, 2016 11:19 pm

Are these still Borland builds ? I still cannot get it to compile with MSVC 2015

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2946
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Camera Control needed for Tablet

Postby Antonio Linares » Wed Aug 24, 2016 11:20 pm

I am using MSVC 2015 Community Edition

do samples\buildh32.bat dshow
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Camera Control needed for Tablet

Postby Antonio Linares » Wed Aug 24, 2016 11:23 pm

going to bed :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Camera Control needed for Tablet

Postby TimStone » Wed Aug 24, 2016 11:30 pm

I'm getting an error at line 5, and the a has an ' over it.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2946
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Camera Control needed for Tablet

Postby TimStone » Thu Aug 25, 2016 2:42 am

I cleaned up the space around that line, and now get the following build error following your instructions:

Code: Select all  Expand view  RUN

Lines 4861, Functions/Procedures 1
Generating C source output to 'dshow.c'... Done.
dshow.c
dshow.prg(22): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(22): error C2065: 'ÿ': undeclared identifier
dshow.prg(22): error C2146: syntax error: missing ';' before identifier 'ÿHRESULT'
dshow.prg(22): error C2065: 'ÿHRESULT': undeclared identifier
dshow.prg(22): error C2146: syntax error: missing ';' before identifier 'hr'
dshow.prg(22): error C2065: 'hr': undeclared identifier
dshow.prg(23): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(23): error C2065: 'ÿ': undeclared identifier
dshow.prg(23): error C2146: syntax error: missing ';' before identifier 'ÿICreateDevEnum'
dshow.prg(23): error C2065: 'ÿICreateDevEnum': undeclared identifier
dshow.prg(23): error C2065: 'pDevEnum': undeclared identifier
dshow.prg(24): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(24): error C2065: 'ÿ': undeclared identifier
dshow.prg(24): error C2146: syntax error: missing ';' before identifier 'ÿIEnumMoniker'
dshow.prg(24): error C2065: 'ÿIEnumMoniker': undeclared identifier
dshow.prg(24): error C2065: 'pEnum': undeclared identifier
dshow.prg(25): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(25): error C2065: 'ÿ': undeclared identifier
dshow.prg(25): error C2146: syntax error: missing ';' before identifier 'ÿIMoniker'
dshow.prg(25): error C2065: 'ÿIMoniker': undeclared identifier
dshow.prg(25): error C2065: 'pMoniker': undeclared identifier
dshow.prg(26): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(26): error C2065: 'ÿ': undeclared identifier
dshow.prg(26): error C2146: syntax error: missing ';' before identifier 'ÿIPropertyBag'
dshow.prg(26): error C2065: 'ÿIPropertyBag': undeclared identifier
dshow.prg(26): error C2065: 'pPropBag': undeclared identifier
dshow.prg(27): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(27): error C2065: 'ÿ': undeclared identifier
dshow.prg(27): error C2146: syntax error: missing ';' before identifier 'ÿIGraphBuilder'
dshow.prg(27): error C2065: 'ÿIGraphBuilder': undeclared identifier
dshow.prg(27): error C2065: 'pGraph': undeclared identifier
dshow.prg(28): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(28): error C2065: 'ÿ': undeclared identifier
dshow.prg(28): error C2146: syntax error: missing ';' before identifier 'ÿICaptureGraphBuilder2'
dshow.prg(28): error C2065: 'ÿICaptureGraphBuilder2': undeclared identifier
dshow.prg(28): error C2065: 'pBuilder': undeclared identifier
dshow.prg(29): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(29): error C2065: 'ÿ': undeclared identifier
dshow.prg(29): error C2146: syntax error: missing ';' before identifier 'ÿIBaseFilter'
dshow.prg(29): error C2065: 'ÿIBaseFilter': undeclared identifier
dshow.prg(29): error C2065: 'pCap': undeclared identifier
dshow.prg(30): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(30): error C2065: 'ÿ': undeclared identifier
dshow.prg(30): error C2146: syntax error: missing ';' before identifier 'ÿIBaseFilter'
dshow.prg(30): error C2065: 'ÿIBaseFilter': undeclared identifier
dshow.prg(30): error C2065: 'pSampleGrabberFilter': undeclared identifier
dshow.prg(31): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(31): error C2065: 'ÿ': undeclared identifier
dshow.prg(31): error C2146: syntax error: missing ';' before identifier 'ÿIBaseFilter'
dshow.prg(31): error C2065: 'ÿIBaseFilter': undeclared identifier
dshow.prg(31): error C2065: 'pNullRenderer': undeclared identifier
dshow.prg(32): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(32): error C2065: 'ÿ': undeclared identifier
dshow.prg(32): error C2146: syntax error: missing ';' before identifier 'ÿIMediaControl'
dshow.prg(32): error C2065: 'ÿIMediaControl': undeclared identifier
dshow.prg(32): error C2065: 'pMediaControl': undeclared identifier
dshow.prg(33): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(33): error C2065: 'ÿ': undeclared identifier
dshow.prg(33): error C2146: syntax error: missing ';' before identifier 'ÿchar'
dshow.prg(33): error C2065: 'ÿchar': undeclared identifier
dshow.prg(33): error C2065: 'pBuffer': undeclared identifier
dshow.prg(34): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(34): error C2065: 'ÿ': undeclared identifier
dshow.prg(34): error C2146: syntax error: missing ';' before identifier 'ÿVARIANT'
dshow.prg(34): error C2065: 'ÿVARIANT': undeclared identifier
dshow.prg(34): error C2146: syntax error: missing ';' before identifier 'var'
dshow.prg(34): error C2065: 'var': undeclared identifier
dshow.prg(35): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(35): error C2065: 'ÿ': undeclared identifier
dshow.prg(35): error C2146: syntax error: missing ';' before identifier 'ÿ'
dshow.prg(35): error C2144: syntax error: 'int' should be preceded by ';'
dshow.prg(36): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(36): error C2065: 'ÿ': undeclared identifier
dshow.prg(36): error C2146: syntax error: missing ';' before identifier 'ÿ'
dshow.prg(36): error C2144: syntax error: 'int' should be preceded by ';'
dshow.prg(37): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(37): error C2065: 'ÿ': undeclared identifier
dshow.prg(37): error C2146: syntax error: missing ';' before identifier 'ÿ'
dshow.prg(37): error C2144: syntax error: 'char' should be preceded by ';'
dshow.prg(38): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(38): error C2065: 'ÿ': undeclared identifier
dshow.prg(38): error C2146: syntax error: missing ';' before identifier 'ÿchar'
dshow.prg(38): error C2065: 'ÿchar': undeclared identifier
dshow.prg(38): error C2146: syntax error: missing ';' before identifier 'char_buffer'
dshow.prg(38): error C2065: 'char_buffer': undeclared identifier
dshow.prg(39): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(39): error C2653: 'ÿDexterLib': is not a class or namespace name
dshow.prg(39): error C2065: 'ÿ': undeclared identifier
dshow.prg(39): error C2146: syntax error: missing ';' before identifier 'ISampleGrabber'
dshow.prg(39): error C2065: 'ISampleGrabber': undeclared identifier
dshow.prg(39): error C2065: 'pSampleGrabber': undeclared identifier
dshow.prg(41): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(41): error C2065: 'ÿ': undeclared identifier
dshow.prg(41): error C2146: syntax error: missing ';' before identifier 'ÿstrcpy'
dshow.prg(41): error C3861: 'ÿstrcpy': identifier not found
dshow.prg(43): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(43): error C2065: 'ÿ': undeclared identifier
dshow.prg(43): error C2146: syntax error: missing ';' before identifier 'ÿhr'
dshow.prg(43): error C2065: 'ÿhr': undeclared identifier
dshow.prg(45): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(45): error C2065: 'ÿ': undeclared identifier
dshow.prg(45): fatal error C1003: error count exceeds 100; stopping compilation
LINK : fatal error LNK1181: cannot open input file 'dshow.obj'
* Linking errors *
 


I must be missing something in my available files.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2946
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Camera Control needed for Tablet

Postby Antonio Linares » Thu Aug 25, 2016 3:07 pm

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Camera Control needed for Tablet

Postby rhlawek » Thu Aug 25, 2016 5:01 pm

Antonio,

I am able to get this to compile and run using VS 2015, but I needed to do/change a couple things:

1) Explicitly set to compile as CPP code instead of C.
2) Changed MessageBox() calls to MessageBoxA() to get around a unicode/casting error.
User avatar
rhlawek
 
Posts: 194
Joined: Sun Jul 22, 2012 7:01 pm

Re: Camera Control needed for Tablet

Postby Antonio Linares » Thu Aug 25, 2016 5:05 pm

Robb,

Yes, it has to be compiled in C++ mode

FWH\samples\buildh32.bat does it automatically
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Camera Control needed for Tablet

Postby Antonio Linares » Thu Aug 25, 2016 5:07 pm

> 2) Changed MessageBox() calls to MessageBoxA() to get around a unicode/casting error

that may be as you are using unicode at compiling time.

buildh32.bat works fine and does not use unicode
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Camera Control needed for Tablet

Postby rhlawek » Thu Aug 25, 2016 5:14 pm

One other thing I forgot is I had to add "strmiids" to my list of libs to resolve a bunch of unresolved externals. I don't see that lib referenced in buildh32.bat so I'm not sure why I see the missing externals and you don't.

I am able to get it to run both as 32 and 64 bit.
User avatar
rhlawek
 
Posts: 194
Joined: Sun Jul 22, 2012 7:01 pm

Re: Camera Control needed for Tablet

Postby Antonio Linares » Thu Aug 25, 2016 5:27 pm

Robb,

I mentioned here that strmiids.lib has to be linked:

viewtopic.php?p=193422#p193422

many thanks for your feedback
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Camera Control needed for Tablet

Postby Antonio Linares » Thu Aug 25, 2016 5:28 pm

This version turns the ActiveMovie Window as a child window of our app:

dshow.prg
Code: Select all  Expand view  RUN
#include "FiveWin.ch"

function Main()

   local oWnd, hWnd
   
   DEFINE WINDOW oWnd

   ACTIVATE WINDOW oWnd MAXIMIZED ;
      ON INIT ( DShowCamera(),;
                SetParent( hWnd := FindWindow( 0, "ActiveMovie Window" ), oWnd:hWnd ),;
                SetWindowPos( hWnd, 0, 10, 10, 300, 300 ) )

return nil

#pragma BEGINDUMP

#include <dshow.h>
#include <uuids.h>
#include <objbase.h>

#import "qedit.dll" raw_interfaces_only named_guids

EXTERN_C const CLSID CLSID_NullRenderer;
EXTERN_C const CLSID CLSID_SampleGrabber;

HB_FUNC( DSHOWCAMERA )
{
   HRESULT hr;
   ICreateDevEnum *pDevEnum = NULL;
   IEnumMoniker *pEnum = NULL;
   IMoniker *pMoniker = NULL;
   IPropertyBag *pPropBag = NULL;
   IGraphBuilder *pGraph = NULL;
   ICaptureGraphBuilder2 *pBuilder = NULL;
   IBaseFilter *pCap = NULL;
   IBaseFilter *pSampleGrabberFilter = NULL;
   IBaseFilter *pNullRenderer = NULL;
   IMediaControl *pMediaControl = NULL;
   char *pBuffer = NULL;
   VARIANT var;
    int n = 0;
    int device_number = 0;
    char device_name[ 100 ];
   char char_buffer[100];
   DexterLib::ISampleGrabber *pSampleGrabber = NULL;

   strcpy( device_name, "" );

   hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );

   if( hr != S_OK )
      MessageBox( 0, "CoInitializeEx error", "ok", 0 );

   hr = CoCreateInstance( CLSID_FilterGraph, NULL,
              CLSCTX_INPROC_SERVER, IID_IGraphBuilder,
              ( void ** ) &pGraph );
           
   if( hr != S_OK )
      MessageBox( 0, "CoCreateInstance error", "ok", 0 );
     
    hr = CoCreateInstance( CLSID_CaptureGraphBuilder2, NULL,
            CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2,
            ( void ** ) &pBuilder );      

   if( hr != S_OK )
      MessageBox( 0, "CoCreateInstance 2 error", "ok", 0 );

    hr = ( ( ICaptureGraphBuilder * ) pBuilder )->SetFiltergraph( pGraph );
   
    if( hr != S_OK )
        MessageBox( 0, "Could not attach capture graph builder to graph", "ok", 0 );
     
    hr = CoCreateInstance( CLSID_SystemDeviceEnum, NULL,
            CLSCTX_INPROC_SERVER, IID_PPV_ARGS( &pDevEnum ) );
         
    if( hr != S_OK )
        MessageBox( 0, "Could not crerate system device enumerator", "ok", 0 );
     
    hr = pDevEnum->CreateClassEnumerator(
                    CLSID_VideoInputDeviceCategory, &pEnum, 0 );
               
    if( hr != S_OK )
        MessageBox( 0, "No video devices found", "ok", 0 );      
     
    while(1)
    {
        // Access next device
        hr = pEnum->Next(1, &pMoniker, NULL);
        if( hr == S_OK )
            n++; // increment device count
      else  
         break;
       
        // If device was specified by name rather than number...
        if( device_number == 0 )
        {
            // Get video input device name
            hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
            if (hr == S_OK)
            {
                // Get current device name
                VariantInit(&var);
                hr = pPropBag->Read(L"FriendlyName", &var, 0);
               
                // Convert to a normal C string, i.e. char*
                sprintf(char_buffer, "%ls", var.bstrVal);
                VariantClear(&var);
                pPropBag->Release();
                pPropBag = NULL;
               
                // Exit loop if current device name matched devname
            // MessageBox( 0, char_buffer, "device_name", 0 );
           
                if (strcmp(device_name, char_buffer) == 0) break;
            }
            else
         {
                MessageBox( 0, "Error getting device names", "ok", 0 );
            break;
         }  
        }
        else if (n >= device_number) break;
    }  
   
    // Get video input device name
    hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
    VariantInit(&var);
    hr = pPropBag->Read(L"FriendlyName", &var, 0);
    // MessageBoxW( 0, L"Capture device", var.bstrVal, 0 );
    VariantClear(&var);  
   
    // Create capture filter and add to graph
    hr = pMoniker->BindToObject(0, 0,
                    IID_IBaseFilter, (void**)&pCap);
               
    if( hr != S_OK )
      MessageBox( 0, "Could not create capture filter", "ok", 0 );  

    // Add capture filter to graph
    hr = pGraph->AddFilter(pCap, L"Capture Filter");
   
    if( hr != S_OK )
      MessageBox( 0, "Could not add capture filter to graph", "ok", 0 );

    // Create sample grabber filter
    hr = CoCreateInstance(CLSID_SampleGrabber, NULL,
        CLSCTX_INPROC_SERVER, IID_IBaseFilter,
        (void**)&pSampleGrabberFilter);
     
    if( hr != S_OK )
        MessageBox( 0, "Could not create Sample Grabber filter", "ok", 0 );

    // Query the ISampleGrabber interface of the sample grabber filter
    hr = pSampleGrabberFilter->QueryInterface(
            DexterLib::IID_ISampleGrabber, (void**)&pSampleGrabber);
         
    if( hr != S_OK )
        MessageBox( 0, "Could not get ISampleGrabber interface to sample grabber filter", "ok", 0 );

    // Enable sample buffering in the sample grabber filter
    hr = pSampleGrabber->SetBufferSamples(TRUE);
   
    if( hr != S_OK )
        MessageBox( 0, "Could not enable sample buffering in the sample grabber", "ok", 0 );

    // Set media type in sample grabber filter
    AM_MEDIA_TYPE mt;
    ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE));
    mt.majortype = MEDIATYPE_Video;
    mt.subtype = MEDIASUBTYPE_RGB24;
    hr = pSampleGrabber->SetMediaType((DexterLib::_AMMediaType *)&mt);
   
    if( hr != S_OK )
        MessageBox( 0, "Could not set media type in sample grabber", "ok", 0 );

    // Add sample grabber filter to filter graph
    hr = pGraph->AddFilter(pSampleGrabberFilter, L"SampleGrab");
   
    if( hr != S_OK )
        MessageBox( 0, "Could not add Sample Grabber to filter graph", "ok", 0 );

    // Create Null Renderer filter
    hr = CoCreateInstance(CLSID_NullRenderer, NULL,
        CLSCTX_INPROC_SERVER, IID_IBaseFilter,
        (void**)&pNullRenderer);

   if( hr != S_OK )
        MessageBox( 0, "Could not create Null Renderer filter", "ok", 0 );

    // Add Null Renderer filter to filter graph
    hr = pGraph->AddFilter(pNullRenderer, L"NullRender");

   if( hr != S_OK )
        MessageBox( 0, "Could not add Null Renderer to filter graph", "ok", 0 );
     
   // Connect up the filter graph's capture stream
    hr = pBuilder->RenderStream(
        &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
        pCap,  pSampleGrabberFilter, pNullRenderer);
     
    if( hr != S_OK )
        MessageBox( 0, "Could not render capture video stream", "ok", 0 );

    hr = pBuilder->RenderStream(
                &PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,
                pCap, NULL, NULL);
   
   if (hr != S_OK && hr != VFW_S_NOPREVIEWPIN)
            MessageBox( 0, "Could not render preview video stream", "ok", 0 );

    // Get media control interfaces to graph builder object
    hr = pGraph->QueryInterface(IID_IMediaControl,
                    (void**)&pMediaControl);

   if( hr != S_OK )
      MessageBox( 0, "Could not get media control interface", "ok", 0 );

    // Run graph
    while(1)
    {
        hr = pMediaControl->Run();
       
        // Hopefully, the return value was S_OK or S_FALSE
        if (hr == S_OK) break; // graph is now running
        if (hr == S_FALSE) continue; // graph still preparing to run
       
        // If the Run function returned something else,
        // there must be a problem
        // fprintf(stderr, "Error: %u\n", hr);
        MessageBox( 0, "Could not run filter graph", "ok", 0 );
    }
}

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Camera Control needed for Tablet

Postby Antonio Linares » Thu Aug 25, 2016 5:36 pm

Now we turn it into a control :-)

Code: Select all  Expand view  RUN
#include "FiveWin.ch"

#define GWL_STYLE -16

function Main()

   local oWnd, hWnd
   
   DEFINE WINDOW oWnd

   ACTIVATE WINDOW oWnd MAXIMIZED ;
      ON INIT ( DShowCamera(),;
                SetParent( hWnd := FindWindow( 0, "ActiveMovie Window" ), oWnd:hWnd ),;
                SetWindowLong( hWnd, GWL_STYLE, nOr( WS_CHILD, WS_VISIBLE ) ),;
                SetWindowPos( hWnd, 0, 10, 10, 300, 300 ) )

return nil

#pragma BEGINDUMP

#include <dshow.h>
#include <uuids.h>
#include <objbase.h>

#import "qedit.dll" raw_interfaces_only named_guids

EXTERN_C const CLSID CLSID_NullRenderer;
EXTERN_C const CLSID CLSID_SampleGrabber;

HB_FUNC( DSHOWCAMERA )
{
   HRESULT hr;
   ICreateDevEnum *pDevEnum = NULL;
   IEnumMoniker *pEnum = NULL;
   IMoniker *pMoniker = NULL;
   IPropertyBag *pPropBag = NULL;
   IGraphBuilder *pGraph = NULL;
   ICaptureGraphBuilder2 *pBuilder = NULL;
   IBaseFilter *pCap = NULL;
   IBaseFilter *pSampleGrabberFilter = NULL;
   IBaseFilter *pNullRenderer = NULL;
   IMediaControl *pMediaControl = NULL;
   char *pBuffer = NULL;
   VARIANT var;
    int n = 0;
    int device_number = 0;
    char device_name[ 100 ];
   char char_buffer[100];
   DexterLib::ISampleGrabber *pSampleGrabber = NULL;

   strcpy( device_name, "" );

   hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );

   if( hr != S_OK )
      MessageBox( 0, "CoInitializeEx error", "ok", 0 );

   hr = CoCreateInstance( CLSID_FilterGraph, NULL,
              CLSCTX_INPROC_SERVER, IID_IGraphBuilder,
              ( void ** ) &pGraph );
           
   if( hr != S_OK )
      MessageBox( 0, "CoCreateInstance error", "ok", 0 );
     
    hr = CoCreateInstance( CLSID_CaptureGraphBuilder2, NULL,
            CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2,
            ( void ** ) &pBuilder );      

   if( hr != S_OK )
      MessageBox( 0, "CoCreateInstance 2 error", "ok", 0 );

    hr = ( ( ICaptureGraphBuilder * ) pBuilder )->SetFiltergraph( pGraph );
   
    if( hr != S_OK )
        MessageBox( 0, "Could not attach capture graph builder to graph", "ok", 0 );
     
    hr = CoCreateInstance( CLSID_SystemDeviceEnum, NULL,
            CLSCTX_INPROC_SERVER, IID_PPV_ARGS( &pDevEnum ) );
         
    if( hr != S_OK )
        MessageBox( 0, "Could not crerate system device enumerator", "ok", 0 );
     
    hr = pDevEnum->CreateClassEnumerator(
                    CLSID_VideoInputDeviceCategory, &pEnum, 0 );
               
    if( hr != S_OK )
        MessageBox( 0, "No video devices found", "ok", 0 );      
     
    while(1)
    {
        // Access next device
        hr = pEnum->Next(1, &pMoniker, NULL);
        if( hr == S_OK )
            n++; // increment device count
      else  
         break;
       
        // If device was specified by name rather than number...
        if( device_number == 0 )
        {
            // Get video input device name
            hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
            if (hr == S_OK)
            {
                // Get current device name
                VariantInit(&var);
                hr = pPropBag->Read(L"FriendlyName", &var, 0);
               
                // Convert to a normal C string, i.e. char*
                sprintf(char_buffer, "%ls", var.bstrVal);
                VariantClear(&var);
                pPropBag->Release();
                pPropBag = NULL;
               
                // Exit loop if current device name matched devname
            // MessageBox( 0, char_buffer, "device_name", 0 );
           
                if (strcmp(device_name, char_buffer) == 0) break;
            }
            else
         {
                MessageBox( 0, "Error getting device names", "ok", 0 );
            break;
         }  
        }
        else if (n >= device_number) break;
    }  
   
    // Get video input device name
    hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
    VariantInit(&var);
    hr = pPropBag->Read(L"FriendlyName", &var, 0);
    // MessageBoxW( 0, L"Capture device", var.bstrVal, 0 );
    VariantClear(&var);  
   
    // Create capture filter and add to graph
    hr = pMoniker->BindToObject(0, 0,
                    IID_IBaseFilter, (void**)&pCap);
               
    if( hr != S_OK )
      MessageBox( 0, "Could not create capture filter", "ok", 0 );  

    // Add capture filter to graph
    hr = pGraph->AddFilter(pCap, L"Capture Filter");
   
    if( hr != S_OK )
      MessageBox( 0, "Could not add capture filter to graph", "ok", 0 );

    // Create sample grabber filter
    hr = CoCreateInstance(CLSID_SampleGrabber, NULL,
        CLSCTX_INPROC_SERVER, IID_IBaseFilter,
        (void**)&pSampleGrabberFilter);
     
    if( hr != S_OK )
        MessageBox( 0, "Could not create Sample Grabber filter", "ok", 0 );

    // Query the ISampleGrabber interface of the sample grabber filter
    hr = pSampleGrabberFilter->QueryInterface(
            DexterLib::IID_ISampleGrabber, (void**)&pSampleGrabber);
         
    if( hr != S_OK )
        MessageBox( 0, "Could not get ISampleGrabber interface to sample grabber filter", "ok", 0 );

    // Enable sample buffering in the sample grabber filter
    hr = pSampleGrabber->SetBufferSamples(TRUE);
   
    if( hr != S_OK )
        MessageBox( 0, "Could not enable sample buffering in the sample grabber", "ok", 0 );

    // Set media type in sample grabber filter
    AM_MEDIA_TYPE mt;
    ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE));
    mt.majortype = MEDIATYPE_Video;
    mt.subtype = MEDIASUBTYPE_RGB24;
    hr = pSampleGrabber->SetMediaType((DexterLib::_AMMediaType *)&mt);
   
    if( hr != S_OK )
        MessageBox( 0, "Could not set media type in sample grabber", "ok", 0 );

    // Add sample grabber filter to filter graph
    hr = pGraph->AddFilter(pSampleGrabberFilter, L"SampleGrab");
   
    if( hr != S_OK )
        MessageBox( 0, "Could not add Sample Grabber to filter graph", "ok", 0 );

    // Create Null Renderer filter
    hr = CoCreateInstance(CLSID_NullRenderer, NULL,
        CLSCTX_INPROC_SERVER, IID_IBaseFilter,
        (void**)&pNullRenderer);

   if( hr != S_OK )
        MessageBox( 0, "Could not create Null Renderer filter", "ok", 0 );

    // Add Null Renderer filter to filter graph
    hr = pGraph->AddFilter(pNullRenderer, L"NullRender");

   if( hr != S_OK )
        MessageBox( 0, "Could not add Null Renderer to filter graph", "ok", 0 );
     
   // Connect up the filter graph's capture stream
    hr = pBuilder->RenderStream(
        &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
        pCap,  pSampleGrabberFilter, pNullRenderer);
     
    if( hr != S_OK )
        MessageBox( 0, "Could not render capture video stream", "ok", 0 );

    hr = pBuilder->RenderStream(
                &PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,
                pCap, NULL, NULL);
   
   if (hr != S_OK && hr != VFW_S_NOPREVIEWPIN)
            MessageBox( 0, "Could not render preview video stream", "ok", 0 );

    // Get media control interfaces to graph builder object
    hr = pGraph->QueryInterface(IID_IMediaControl,
                    (void**)&pMediaControl);

   if( hr != S_OK )
      MessageBox( 0, "Could not get media control interface", "ok", 0 );

    // Run graph
    while(1)
    {
        hr = pMediaControl->Run();
       
        // Hopefully, the return value was S_OK or S_FALSE
        if (hr == S_OK) break; // graph is now running
        if (hr == S_FALSE) continue; // graph still preparing to run
       
        // If the Run function returned something else,
        // there must be a problem
        // fprintf(stderr, "Error: %u\n", hr);
        MessageBox( 0, "Could not run filter graph", "ok", 0 );
    }
}

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 50 guests