Jump to content
Sign in to follow this  
frank10

DShow capture filter

Recommended Posts

frank10

I'm trying to adapt this C++ code to autoit to get access to the DS capture filter:

#include <dshow.h>
int main (void)
{
    IGraphBuilder *pGraph = 0;
    ICreateDevEnum *pDevEnum = 0;
    ICaptureGraphBuilder2 *pBuild = 0;
    HRESULT hr;
    CoInitialize(NULL);
    // Create the FGM.
    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
        IID_IGraphBuilder, (void **)&pGraph );
    // Create the capture graph builder helper object
    hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL,
        CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2,
        (void **)&pBuild );
    // Tell the capture graph builder about the FGM.
    hr = pBuild->SetFiltergraph(pGraph);
    // Create a helper object to find the capture device.
    hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
        CLSCTX_INPROC_SERVER,
        IID_ICreateDevEnum, (LPVOID*)&pDevEnum);
    // Use the first capture filter that we find.
    IEnumMoniker* pEnum = 0;
    IMoniker* pMoniker = 0;
    IBaseFilter *pCapture = 0;
    hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
        &pEnum, 0);

    if (S_OK == pEnum->Next(1, &pMoniker, NULL))
    {
        hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void
        **)&pCapture);
    }
    pMoniker->Release();
    pEnum->Release();
    pDevEnum->Release();


    // Add the capture filter to the filter graph
    hr = pGraph->AddFilter(pCapture, L"CaptureFilter");
    // Build the preview part of the graph.
    hr = pBuild->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,
        pCapture, NULL, NULL);
    // Build the file writing part of the graph.
    IBaseFilter *pMux = 0;
    pBuild->SetOutputFileName(&MEDIASUBTYPE_Avi, L"C:test.avi",
    &pMux, 0);
    hr = pBuild->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
       pCapture, NULL, pMux);
    // Run the graph. (Not shown.)
    pGraph->Release();
    pBuild->Release();
    pCapture->Release();
    pMux->Release();
    CoUninitialize();
    return 0;
}

I think I found all the CLSID (apart one: CLSID_CBaseFilter) and IID, so as my first try I got this:

#AutoIt3Wrapper_UseX64=n
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinApi.au3>
#include <array.au3>
#include "AutoitObject.au3"
Opt("MustDeclareVars", 1)
Opt("WinWaitDelay", 0) ; 0 ms
; Error monitoring
Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
_AutoItObject_StartUp()
; GUI
Global $hGUI = GUICreate("DirectShow Capture", 1280, 720, -1, -1, -1, $WS_EX_ACCEPTFILES)
Global $oGraphBuilder, $oVideoWindow,$oBasicAudio, $oBasicVideo, $oIBaseFilter, $oICreateDevEnum ,$oIEnumMoniker, $oIMoniker
Global $oCaptureGraphBuilder2
GUISetState()

_Init()

While 1
Switch GUIGetMsg()
  Case -3
   ExitLoop
EndSwitch
WEnd

Func _Init()
  const  $CLSCTX_INPROC_SERVER   = 0x1
Local $tIID_IVideoWindow = _AutoItObject_CLSIDFromString("{56A868B4-0AD4-11CE-B03A-0020AF0BA770}")
Local $tIID_IBasicAudio = _AutoItObject_CLSIDFromString("{56A868B3-0AD4-11CE-B03A-0020AF0BA770}")
Local $tIID_IBasicVideo = _AutoItObject_CLSIDFromString("{56A868B5-0AD4-11CE-B03A-0020AF0BA770}")

local $pBuild = 0
;===============================================================================
#interface "IGraphBuilder"
  ;~ // Create the FGM.
  Local $sCLSID_FilterGraph = "{E436EBB3-524F-11CE-9F53-0020AF0BA770}"
  Local $sIID_IGraphBuilder = "{56A868A9-0AD4-11CE-B03A-0020AF0BA770}"
  local $tIID_IGraphBuilder = _AutoItObject_CLSIDFromString("{56A868A9-0AD4-11CE-B03A-0020AF0BA770}")
  ; Define IGraphBuilder methods
  Local $dtagIGraphBuilder = $dtagIUnknown & _
    "AddFilter hresult(ptr;wstr);" & _
    "RemoveFilter hresult(ptr);" & _
    "EnumFilters hresult(ptr*);" & _
    "FindFilterByName hresult(wstr;ptr*);" & _
    "ConnectDirect hresult(ptr;ptr;ptr);" & _
    "Reconnect hresult(ptr);" & _
    "Disconnect hresult(ptr);" & _
    "SetDefaultSyncSource hresult();" & _ ; IFilterGraph
    "Connect hresult(ptr;ptr);" & _
    "Render hresult(ptr);" & _
    "RenderFile hresult(wstr;ptr);" & _
    "AddSourceFilter hresult(wstr;wstr;ptr*);" & _
    "SetLogFile hresult(dword_ptr);" & _
    "Abort hresult();" & _
    "ShouldOperationContinue hresult();" ; IGraphBuilder
;===============================END=============================================
;===============================================================================
#interface "ICaptureGraphBuilder2"
  local $sCLSID_CaptureGraphBuilder  = '{BF87B6E0-8C27-11D0-B3F0-00AA003761C5}'
  local $tIID_ICaptureGraphBuilder  = _AutoItObject_CLSIDFromString('{bf87b6e0-8c27-11d0-b3f0-00aa003761c5}' );
  local $sCLSID_CaptureGraphBuilder2 = '{BF87B6E1-8C27-11D0-B3F0-00AA003761C5}'
  Local $sIID_ICaptureGraphBuilder2   = '{93e5a4e0-2d50-11d2-abfa-00a0c9c6e38d}'
  local $tIID_ICaptureGraphBuilder2   = _AutoItObject_CLSIDFromString('{93e5a4e0-2d50-11d2-abfa-00a0c9c6e38d}');
  ; Definition
  Global Const $tagICaptureGraphBuilder2 = "SetFiltergraph hresult(ptr);" & _
   "GetFiltergraph hresult(ptr*);" & _
   "SetOutputFileName hresult(clsid;wstr;ptr*;ptr*);" & _
   "FindInterface hresult(clsid;clsid;ptr;clsid;ptr*);" & _
   "RenderStream hresult(clsid;clsid;ptr;ptr;ptr);" & _
   "ControlStream hresult(clsid;clsid;ptr;ptr;ptr;word;word);" & _
   "AllocCapFile hresult(wstr;uint64);" & _
   "CopyCaptureFile hresult(wstr;wstr;int;ptr*);" & _
   "FindPin hresult(ptr;int;clsid;clsid;bool;int;ptr*);"
;===============================END=============================================
;===============================================================================
#interface "ICreateDevEnum"
  Global Const $sCLSID_SystemDeviceEnum   = '{62BE5D10-60EB-11d0-BD3B-00A0C911CE86}'
  Global Const $sIID_ICreateDevEnum = '{29840822-5b84-11d0-bd3b-00a0c911ce86}'
  ; Definition
  Global Const $tagICreateDevEnum = "CreateClassEnumerator hresult( clsid ; ptr*; dword );"
;===============================END=============================================
;===============================================================================
#interface "IEnumMoniker"
  Global Const $sCLSID_IEnumMoniker = '{56a86895-0ad4-11ce-b03a-0020af0ba770}'
  Global Const $sIID_IEnumMoniker    = '{00000102-0000-0000-00c0-000000000046}'
  ; Definition
  Global Const $tagIEnumMoniker = "Next hresult( ulong;ptr*;ulong );" & _
  "Skip hresult( ulong );" & _
  "Reset hresult( );" & _
  "Clone hresult( ptr* );"
;===============================END=============================================
;===============================================================================
#interface "IBaseFilter"
  Global Const $sIID_IBaseFilter     = '{56a86895-0ad4-11ce-b03a-0020af0ba770}'
  ; Definition
  Global Const $tagIBaseFilter = "EnumPins hresult( ptr* )" & _
  "FindPin hresult(ushort;ptr*);" & _
  "QueryFilterInfo hresult( ptr);" & _
  "JoinFilterGraph hresult( ptr; ushort );" & _
  "QueryVendorInfo hresult( ushort );"
;===============================END=============================================
;===============================================================================
#interface "IMoniker"
  Global Const $sCLSID_IMoniker = '{79eac9e0-baf9-11ce-8c82-00aa004ba90b}'
  Global Const $sIID_IMoniker    = '{0000000f-0000-0000-C000-000000000046}'
  ; Definition
  Global Const $tagIMoniker = "GetClassID hresult( clsid )" & _
  "IsDirty hresult(  );" & _
  "Load hresult( ptr );" & _
  "Save hresult( ptr, bool );" & _
  "GetSizeMax hresult( uint64 );" & _
  "BindToObject hresult( ptr;ptr;clsid; void   *);" & _
  "BindToStorage hresult( ptr;ptr;clsid;    void   *);" & _
  "Reduce hresult( ptr;dword;ptr*;ptr*);" & _
  "ComposeWith hresult( ptr;bool;ptr*);" & _
  "Enum hresult( bool;ptr*);" & _
  "IsEqual hresult( ptr);" & _
  "Hash hresult( dword);" & _
  "IsRunning hresult( ptr;ptr;ptr);" & _
  "GetTimeOfLastChange hresult( ptr;ptr;uint64);" & _
  "Inverse hresult( ptr*);" & _
  "CommonPrefixWith hresult( ptr;ptr*);" & _
  "RelativePathTo hresult( ptr;ptr*);" & _
  "GetDisplayName hresult( ptr;ptr;ushort);" & _
  "ParseDisplayName hresult( ptr;ptr;ushort;ulong;ptr*);" & _
  "IsSystemMoniker hresult( dword);"
;===============================END=============================================

Global Const $sCLSID_VideoInputDeviceCategory = '{860bb310-5d01-11d0-bd3b-00a0c911ce86}'

; --------------- objects:
;$oGraphBuilder = ObjCreateInterface($sCLSID_FilterGraph, $sIID_IGraphBuilder, $dtagIGraphBuilder) ; it doesn't work with QueryInterface
$oGraphBuilder = _AutoItObject_ObjCreate($sCLSID_FilterGraph, $sIID_IGraphBuilder, $dtagIGraphBuilder)
If @error Then Return SetError(1, 0, False)

$oCaptureGraphBuilder2 = ObjCreateInterface($sCLSID_CaptureGraphBuilder2, $sIID_ICaptureGraphBuilder2, $tagICaptureGraphBuilder2)
$oICreateDevEnum = ObjCreateInterface($sCLSID_SystemDeviceEnum, $sIID_ICreateDevEnum, $tagICreateDevEnum)
$oIEnumMoniker = ObjCreateInterface($sCLSID_IEnumMoniker, $sIID_IEnumMoniker, $tagIEnumMoniker)
$oIMoniker= ObjCreateInterface($sCLSID_IMoniker, $sIID_IMoniker , $tagIMOniker)

    Local $pIBaseFilter = Number(DllStructGetPtr(_AutoItObject_CLSIDFromString($sIID_IBaseFilter)))
$oIBaseFilter = _AutoItObject_WrapperCreate($pIBaseFilter, $tagIBaseFilter)
If @error Then Return SetError(6, 0, 0)
;~ Local $oIBaseFilter= ObjCreateInterface($sCLSID_CBaseFilter, $sIID_IBaseFilter, $tagIBaseFilter) ; I didn't find the  CLSID CbaseFilter... so I used the WrapperCreate instead of ObjCreateInterface
; ---------------
;~   // Tell the capture graph builder about the FGM.
Local   $pGraph = Number(DllStructGetPtr($tIID_IGraphBuilder))
$oCaptureGraphBuilder2.SetFiltergraph( $pGraph);
;......
EndFunc  ; end _Init

Some questions:

1) when I have the 'This'

STDMETHOD(IsDirty)(THIS);

is it ok:

"IsDirty hresult( );" & _

2) FILETIME ---> uint64

LPOLESTR ---> ushort

3) I have:

STDMETHOD( BindToObject )( THIS_ IBindCtx *, IMoniker *, REFIID, void ** ) PURE;

how to put that 'void **'?

"BindToObject hresult( ptr;ptr;clsid; void *);" & _

4) if I use the old

_AutoItObject_ObjCreate,

the QueryInterface works, instead if I use the new

ObjCreateInterface

it doesn't work (I didn't write the first three methods in the definition as the help file said):

$oGraphBuilder = ObjCreateInterface($sCLSID_FilterGraph, $sIID_IGraphBuilder, $dtagIGraphBuilder)
;~   $oGraphBuilder = _AutoItObject_ObjCreate($sCLSID_FilterGraph, $sIID_IGraphBuilder, $dtagIGraphBuilder)
    If @error Then Return SetError(1, 0, False)
    Local $aCall = $oGraphBuilder.QueryInterface(Number(DllStructGetPtr($tIID_IMediaControl)), 0)
        _ArrayDisplay($aCall, 'oGraphBuild')

5) I didn't find the CLSID_CBaseFilter, so I tried to get a pointer to use in the WrapperCreate, it seems ok for $oIBaseFilter.

6) this crashes... :

Local   $pGraph = Number(DllStructGetPtr($tIID_IGraphBuilder))
$oCaptureGraphBuilder2.SetFiltergraph( $pGraph);

from this (in the c++ code above):

// Tell the capture graph builder about the FGM.
    hr = pBuild->SetFiltergraph(pGraph);

ok, stop here at the moment.

TIA

Edited by frank10

Share this post


Link to post
Share on other sites
frank10

No, it's the help file saying not to do that:

For COM objects (IUnknown based) first three methods are always QueryInterface, AddRef and Release. Don't specify them inside the description strings.

Like I had written, it could be interpreted both way :oops:

Share this post


Link to post
Share on other sites
trancexx

This is much simpler than you think. This should work after you define interfaces:

; Define interfaces and other consants here

;~  #include <dshow.h>
;~  int main(void)
;~  {
;~  IGraphBuilder * pGraph = 0;
;~  ICreateDevEnum * pDevEnum = 0;
;~  ICaptureGraphBuilder2 * pBuild = 0;
;~  HRESULT hr;
;~  CoInitialize(Null);
;~  / / Create the FGM.
;~  hr = CoCreateInstance(CLSID_FilterGraph, Null, CLSCTX_INPROC_SERVER,
;~  IID_IGraphBuilder, (void * *) & pGraph);
Local $oGraph = ObjCreateInterface($sCLSID_FilterGraph, $sIID_IGraphBuilder, $tagIGraphBuilder)

;~  / / Create the capture graph builder helper object
;~  hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, Null,
;~  CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2,
;~  (void * *) & pBuild);
Local $oBuild = ObjCreateInterface($sCLSID_CaptureGraphBuilder2, $sIID_ICaptureGraphBuilder2, $tagICaptureGraphBuilder2)

;~  / / Tell the capture graph builder about the FGM.
;~  hr = pBuild - > SetFiltergraph(pGraph);
$oBuild.SetFiltergraph($oGraph)

;~  / / Create a helper object To find the capture device.
;~  hr = CoCreateInstance(CLSID_SystemDeviceEnum, Null,
;~  CLSCTX_INPROC_SERVER,
;~  IID_ICreateDevEnum, (LPVOID *) & pDevEnum);
Local $oDevEnum = ObjCreateInterface($sCLSID_SystemDeviceEnum, $sIID_ICreateDevEnum, $tagICreateDevEnum)

;~  / / Use the first capture filter that we find.
;~  IEnumMoniker * pEnum = 0;
;~  IMoniker * pMoniker = 0;
;~  IBaseFilter * pCapture = 0;
;~  hr = pDevEnum - > CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
;~  & pEnum, 0);
Local $pEnum = 0
$oDevEnum.CreateClassEnumerator($sCLSID_VideoInputDeviceCategory, $pEnum, 0)
Local $oEnum = ObjCreateInterface($pEnum, $sIID_IEnumMoniker, $tagIEnumMoniker)
;~  If (S_OK == pEnum - > Next (1, &pMoniker, Null))
;~  {
;~  hr = pMoniker - > BindToObject(0, 0, IID_IBaseFilter, (void
;~  * *) & pCapture);
;~  }
Local $pMoniker, $oMoniker, $pCapture
If $oEnum.Next(1, $pMoniker, 0) = $S_OK Then
    $oMoniker = ObjCreateInterface($pMoniker, $sIID_IMoniker, $tagIMoniker)
    $oMoniker.BindToObject(0, 0, $sIID_IBaseFilter, $pCapture);
EndIf
Local $oCapture = ObjCreateInterface($pCapture, $sIID_IBaseFilter, $tagIBaseFilter)

;~  pMoniker - > Release();
;~  pEnum - > Release();
;~  pDevEnum - > Release();
$oMoniker = 0
$oEnum = 0
$oDevEnum = 0
;~  / / Add the capture filter To the filter graph
;~  hr = pGraph - > AddFilter(pCapture, L"CaptureFilter");
$oGraph.AddFilter($oCapture, "CaptureFilter")

;~  / / Build the preview part of the graph.
;~  hr = pBuild - > RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,
;~  pCapture, Null, Null);
$oBuild.RenderStream($PIN_CATEGORY_PREVIEW, $MEDIATYPE_Video, $oCapture(), 0, 0)

;~  / / Build the file writing part of the graph.
;~  IBaseFilter * pMux = 0;
;~  pBuild - > SetOutputFileName(&MEDIASUBTYPE_Avi, L"C:test.avi",
;~  & pMux, 0);

Local $pMux
$oBuild.SetOutputFileName($MEDIASUBTYPE_Avi, "C:test.avi", $pMux, 0)
Local $oMux = ObjCreateInterface($pMux, $sIID_IBaseFilter, $tagIBaseFilter)

;~  hr = pBuild - > RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
;~  pCapture, Null, pMux);
$oBuild.RenderStream($PIN_CATEGORY_CAPTURE, $MEDIATYPE_Video, $oCapture, 0, $oMux)

;~  / / Run the graph.(Not shown.)

;~  pGraph - > Release();
;~  pBuild - > Release();
;~  pCapture - > Release();
;~  pMux - > Release();
$oGraph = 0
$oBuild = 0
$oCapture = 0
$oMux = 0
;~  CoUninitialize();
;~  Return 0;
;~  }

Don't use AutoItObject for this. ObjectCreateInterface() covers all kind of object creation you will need.

When you write interface definitions try looking at the c++ definition rather than c. Then you wont be confused by "this" (the answer to your first question is yes).

For FILETIME you can use "struct" and pass structure, or use "int64" and pass that - whatever is simpler for you.

LPOLESTR is "wstr".

void** is "ptr*".

When definition specifies "clsid" then simply pass string representation of CLSID. AutoIt will do all the job for you internally (see posted code).

Sixth question is also answered in the code.

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
frank10

Thank you trancexx!

At this point I have:

#AutoIt3Wrapper_UseX64=n
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinApi.au3>
#include <array.au3>
#include "AutoitObject.au3"
Opt("MustDeclareVars", 1)
Opt("WinWaitDelay", 0) ; 0 ms
; Error monitoring
Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
_AutoItObject_StartUp()
; GUI
Global $hGUI = GUICreate("DirectShow Capture", 1280, 720, -1, -1, -1, $WS_EX_ACCEPTFILES)
Global $oGraphBuilder, $oVideoWindow,$oBasicAudio, $oBasicVideo, $oIBaseFilter, $oICreateDevEnum ,$oIEnumMoniker, $oIMoniker
Global $oCaptureGraphBuilder2, $oMediaControl
GUISetState()
_Init()
While 1
Switch GUIGetMsg()
  Case -3
   ExitLoop
EndSwitch
WEnd
Func _Init()
  const  $CLSCTX_INPROC_SERVER   = 0x1
local $pBuild = 0
;===============================================================================
#interface "IGraphBuilder"
  ;~ // Create the FGM.
  Local $sCLSID_FilterGraph = "{E436EBB3-524F-11CE-9F53-0020AF0BA770}"
  Local $sIID_IGraphBuilder = "{56A868A9-0AD4-11CE-B03A-0020AF0BA770}"
  local $tIID_IGraphBuilder = _AutoItObject_CLSIDFromString("{56A868A9-0AD4-11CE-B03A-0020AF0BA770}")
  ; Define IGraphBuilder methods
  Local $tagIGraphBuilder = $dtagIUnknown & _
    "AddFilter hresult(ptr;wstr);" & _
    "RemoveFilter hresult(ptr);" & _
    "EnumFilters hresult(ptr*);" & _
    "FindFilterByName hresult(wstr;ptr*);" & _
    "ConnectDirect hresult(ptr;ptr;ptr);" & _
    "Reconnect hresult(ptr);" & _
    "Disconnect hresult(ptr);" & _
    "SetDefaultSyncSource hresult();" & _ ; IFilterGraph
    "Connect hresult(ptr;ptr);" & _
    "Render hresult(ptr);" & _
    "RenderFile hresult(wstr;ptr);" & _
    "AddSourceFilter hresult(wstr;wstr;ptr*);" & _
    "SetLogFile hresult(dword_ptr);" & _
    "Abort hresult();" & _
    "ShouldOperationContinue hresult();" ; IGraphBuilder
;===============================END=============================================
;===============================================================================
#interface "ICaptureGraphBuilder2"
  local $sCLSID_CaptureGraphBuilder  = '{BF87B6E0-8C27-11D0-B3F0-00AA003761C5}'
  local $tIID_ICaptureGraphBuilder  = _AutoItObject_CLSIDFromString('{bf87b6e0-8c27-11d0-b3f0-00aa003761c5}' );
  local $sCLSID_CaptureGraphBuilder2 = '{BF87B6E1-8C27-11D0-B3F0-00AA003761C5}'
  Local $sIID_ICaptureGraphBuilder2   = '{93e5a4e0-2d50-11d2-abfa-00a0c9c6e38d}'
  local $tIID_ICaptureGraphBuilder2   = _AutoItObject_CLSIDFromString('{93e5a4e0-2d50-11d2-abfa-00a0c9c6e38d}');
  ; Definition
  Global Const $tagICaptureGraphBuilder2 = "SetFiltergraph hresult(ptr);" & _
   "GetFiltergraph hresult(ptr*);" & _
   "SetOutputFileName hresult(clsid;wstr;ptr*;ptr*);" & _
   "FindInterface hresult(clsid;clsid;ptr;clsid;ptr*);" & _
   "RenderStream hresult(clsid;clsid;ptr;ptr;ptr);" & _
   "ControlStream hresult(clsid;clsid;ptr;ptr;ptr;word;word);" & _
   "AllocCapFile hresult(wstr;int64);" & _
   "CopyCaptureFile hresult(wstr;wstr;int;ptr*);" & _
   "FindPin hresult(ptr;int;clsid;clsid;bool;int;ptr*);"
;===============================END=============================================
;===============================================================================
#interface "ICreateDevEnum"
  Global Const $sCLSID_SystemDeviceEnum   = '{62BE5D10-60EB-11d0-BD3B-00A0C911CE86}'
  Global Const $sIID_ICreateDevEnum = '{29840822-5b84-11d0-bd3b-00a0c911ce86}'
  ; Definition
  Global Const $tagICreateDevEnum = "CreateClassEnumerator hresult( clsid ; ptr*; dword );"
;===============================END=============================================
;===============================================================================
#interface "IEnumMoniker"
  Global Const $sCLSID_IEnumMoniker = '{56a86895-0ad4-11ce-b03a-0020af0ba770}'
  Global Const $sIID_IEnumMoniker    = '{00000102-0000-0000-c000-000000000046}'
  ; Definition
  Global Const $tagIEnumMoniker = "Next hresult( ulong;ptr*;ulong );" & _
  "Skip hresult( ulong );" & _
  "Reset hresult( );" & _
  "Clone hresult( ptr* );"
;===============================END=============================================
;===============================================================================
#interface "IBaseFilter"
  Global Const $sIID_IBaseFilter     = '{56a86895-0ad4-11ce-b03a-0020af0ba770}'
  ; Definition
  Global Const $tagIBaseFilter = "EnumPins hresult( ptr* )" & _
  "FindPin hresult(wstr;ptr*);" & _
  "QueryFilterInfo hresult( ptr);" & _
  "JoinFilterGraph hresult( ptr; wstr );" & _
  "QueryVendorInfo hresult( wstr );"
;===============================END=============================================
;===============================================================================
#interface "IMoniker"
  Global Const $sCLSID_IMoniker = '{79eac9e0-baf9-11ce-8c82-00aa004ba90b}'
  Global Const $sIID_IMoniker    = '{0000000f-0000-0000-C000-000000000046}'
  ; Definition
  Global Const $tagIMoniker = "GetClassID hresult( clsid )" & _
  "IsDirty hresult(  );" & _
  "Load hresult( ptr );" & _
  "Save hresult( ptr, bool );" & _
  "GetSizeMax hresult( uint64 );" & _
  "BindToObject hresult( ptr;ptr;clsid;ptr*);" & _
  "BindToStorage hresult( ptr;ptr;clsid;ptr*);" & _
  "Reduce hresult( ptr;dword;ptr*;ptr*);" & _
  "ComposeWith hresult( ptr;bool;ptr*);" & _
  "Enum hresult( bool;ptr*);" & _
  "IsEqual hresult( ptr);" & _
  "Hash hresult( dword);" & _
  "IsRunning hresult( ptr;ptr;ptr);" & _
  "GetTimeOfLastChange hresult( ptr;ptr;int64);" & _
  "Inverse hresult( ptr*);" & _
  "CommonPrefixWith hresult( ptr;ptr*);" & _
  "RelativePathTo hresult( ptr;ptr*);" & _
   "GetDisplayName hresult( ptr;ptr;wstr);" & _
  "ParseDisplayName hresult( ptr;ptr;wstr;ulong;ptr*);" & _
  "IsSystemMoniker hresult( dword);"
;===============================END=============================================
;===============================================================================
#interface "IVideoWindow"
  Global Const $SIID_IVideoWindow   = "{56A868B4-0AD4-11CE-B03A-0020AF0BA770}"
  ; IVideoWindow is dual interface. Defining vTable methods:
  Local $tagIVideoWindow = $dtagIDispatch & _
   "put_Caption hresult(bstr);" & _
   "get_Caption hresult(bstr*);" & _
   "put_WindowStyle hresult(long);" & _
   "get_WindowStyle hresult(long*);" & _
   "put_WindowStyleEx hresult(long);" & _
   "put_WindowStyleEx hresult(long*);" & _
   "put_AutoShow hresult(long);" & _
   "get_AutoShow hresult(long*);" & _
   "put_WindowState hresult(long);" & _
   "get_WindowState hresult(long*);" & _
   "put_BackgroundPalette hresult(long);" & _
   "get_BackgroundPalette hresult(long*);" & _
   "put_Visible hresult(long);" & _
   "get_Visible hresult(long*);" & _
   "put_Left hresult(long);" & _
   "get_Left hresult(long*);" & _
   "put_Width hresult(long);" & _
   "get_Width hresult(long*);" & _
   "put_Top hresult(long);" & _
   "get_Top hresult(long*);" & _
   "put_Height hresult(long);" & _
   "get_Height hresult(long*);" & _
   "put_Owner hresult(long_ptr);" & _
   "get_Owner hresult(long_ptr*);" & _
   "put_MessageDrain hresult(long_ptr);" & _
   "get_MessageDrain hresult(long_ptr*);" & _
   "get_BorderColor hresult(long*);" & _
   "put_BorderColor hresult(long);" & _
   "get_FullScreenMode hresult(long*);" & _
   "put_FullScreenMode hresult(long);" & _
   "SetWindowForeground hresult(long);" & _
   "NotifyOwnerMessage hresult(long_ptr;long;long_ptr;long_ptr);" & _
   "SetWindowPosition hresult(long;long;long;long);" & _
   "GetWindowPosition hresult(long*;long*;long*;long*);" & _
   "GetMinIdealImageSize hresult(long*;long*);" & _
   "GetMaxIdealImageSize hresult(long*;long*);" & _
   "GetRestorePosition hresult(long*;long*;long*;long*);" & _
   "HideCursor hresult(long);" & _
   "IsCursorHidden hresult(long*);" ; IVideoWindow
;===============================END=============================================
;===============================================================================
#interface "IBasicVideo"
  Global Const  $SIID_IBasicVideo  = "{56A868B5-0AD4-11CE-B03A-0020AF0BA770}"
  ; IBasicVideo is dual interface. Defining vTable methods:
  Local $tagIBasicVideo = $dtagIDispatch & _
   "get_AvgTimePerFrame hresult(double*);" & _
   "get_BitRate hresult(long*);" & _
   "get_BitErrorRate hresult(long*);" & _
   "get_VideoWidth hresult(long*);" & _
   "get_VideoHeight hresult(long*);" & _
   "put_SourceLeft hresult(long);" & _
   "get_SourceLeft hresult(long*);" & _
   "put_SourceWidth hresult(long);" & _
   "get_SourceWidth hresult(long*);" & _
   "put_SourceTop hresult(long);" & _
   "get_SourceTop hresult(long*);" & _
   "put_SourceHeight hresult(long);" & _
   "get_SourceHeight hresult(long*);" & _
   "put_DestinationLeft hresult(long);" & _
   "get_DestinationLeft hresult(long*);" & _
   "put_DestinationWidth hresult(long);" & _
   "get_DestinationWidth hresult(long*);" & _
   "put_DestinationTop hresult(long);" & _
   "get_DestinationTop hresult(long*);" & _
   "put_DestinationHeight hresult(long);" & _
   "get_DestinationHeight hresult(long*);" & _
   "SetSourcePosition hresult(long;long;long;long);" & _
   "GetSourcePosition hresult(long*;long*;long*;long*);" & _
   "SetDefaultSourcePosition hresult();" & _
   "SetDestinationPosition hresult(long;long;long;long);" & _
   "GetDestinationPosition hresult(long*;long*;long*;long*);" & _
   "SetDefaultDestinationPosition hresult();" & _
   "GetVideoSize hresult(long*;long*);" & _
   "GetVideoPaletteEntries hresult(long;long;long*;long*);" & _
   "GetCurrentImage hresult(long*;long*);" & _
   "IsUsingDefaultSource hresult();" & _
   "IsUsingDefaultDestination hresult();" ; IBasicVideo
;===============================END=============================================

Global const $SIID_IMediaEventEx     = "{56A868C0-0AD4-11CE-B03A-0020AF0BA770}"
Global const $sIID_IMediaControl     = '{56A868B1-0AD4-11CE-B03A-0020AF0BA770}'
Global const $SIID_IBasicAudio    = "{56A868B3-0AD4-11CE-B03A-0020AF0BA770}"
Global Const $sCLSID_VideoInputDeviceCategory = '{860bb310-5d01-11d0-bd3b-00a0c911ce86}'

Global Const $S_OK = 0
Global Const $PIN_CATEGORY_CAPTURE   = '{fb6c4281-0353-11d1-905f-0000c0cc16ba}'
Global Const $PIN_CATEGORY_PREVIEW  = '{fb6c4282-0353-11d1-905f-0000c0cc16ba}'
Global Const $MEDIASUBTYPE_Avi    = '{e436eb88-524f-11ce-9f53-0020af0ba770}'
Global Const $MEDIATYPE_Video     = '{73646976-0000-0010-8000-00aa00389b71}'

;~  #include <dshow.h>
;~  int main(void)
;~  {
;~  IGraphBuilder * pGraph = 0;
;~  ICreateDevEnum * pDevEnum = 0;
;~  ICaptureGraphBuilder2 * pBuild = 0;
;~  HRESULT hr;
;~  CoInitialize(Null);
;~  / / Create the FGM.
;~  hr = CoCreateInstance(CLSID_FilterGraph, Null, CLSCTX_INPROC_SERVER,
;~  IID_IGraphBuilder, (void * *) & pGraph);
Local $oGraph = ObjCreateInterface($sCLSID_FilterGraph, $sIID_IGraphBuilder, $tagIGraphBuilder)

;~  / / Create the capture graph builder helper object
;~  hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, Null,
;~  CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2,
;~  (void * *) & pBuild);
Local $oBuild = ObjCreateInterface($sCLSID_CaptureGraphBuilder2, $sIID_ICaptureGraphBuilder2, $tagICaptureGraphBuilder2)

;~  / / Tell the capture graph builder about the FGM.
;~  hr = pBuild - > SetFiltergraph(pGraph);
$oBuild.SetFiltergraph($oGraph)

;~  / / Create a helper object To find the capture device.
;~  hr = CoCreateInstance(CLSID_SystemDeviceEnum, Null,
;~  CLSCTX_INPROC_SERVER,
;~  IID_ICreateDevEnum, (LPVOID *) & pDevEnum);
Local $oDevEnum = ObjCreateInterface($sCLSID_SystemDeviceEnum, $sIID_ICreateDevEnum, $tagICreateDevEnum)

;~  / / Use the first capture filter that we find.
;~  IEnumMoniker * pEnum = 0;
;~  IMoniker * pMoniker = 0;
;~  IBaseFilter * pCapture = 0;
;~  hr = pDevEnum - > CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
;~  & pEnum, 0);
Local $pEnum = 0
$oDevEnum.CreateClassEnumerator($sCLSID_VideoInputDeviceCategory, $pEnum, 0)
Local $oEnum = ObjCreateInterface($pEnum, $sIID_IEnumMoniker, $tagIEnumMoniker)

;~  If (S_OK == pEnum - > Next (1, &pMoniker, Null))
;~  {
;~  hr = pMoniker - > BindToObject(0, 0, IID_IBaseFilter, (void
;~  * *) & pCapture);
;~  }
Local $pMoniker, $oMoniker, $pCapture

If $oEnum.Next(1, $pMoniker, 0) = $S_OK Then
    $oMoniker = ObjCreateInterface($pMoniker, $sIID_IMoniker, $tagIMoniker)
    $oMoniker.BindToObject(0, 0, $sIID_IBaseFilter, $pCapture);
EndIf
$oCapture = ObjCreateInterface($pCapture, $sIID_IBaseFilter, $tagIBaseFilter)

;~  pMoniker - > Release();
;~  pEnum - > Release();
;~  pDevEnum - > Release();
$oMoniker = 0
$oEnum = 0
$oDevEnum = 0

;~  / / Add the capture filter To the filter graph
;~  hr = pGraph - > AddFilter(pCapture, L"CaptureFilter");

;~ $E_Fail = 0x80004005  ;-2147467259
;~ $E_INVALIDARG = 0x80000003 ;-2147483645
;~ $E_POINTER = 0x80000005 ;-2147483643
;$VFW_S_NOPREVIEWPIN = 0x8004027 ; 134234151
;$VFW_E_NOT_IN_GRAPH = 0x8004025 ; 134234149

local $aCall = $oGraph.AddFilter($oCapture, "CaptureFilter")
MsgBox(0,'result oGraph  ',  $aCall) ; -2147220970

;~  / / Build the preview part of the graph.
;~  hr = pBuild - > RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,
;~  pCapture, Null, Null);


Local $aCall = $oBuild.RenderStream($PIN_CATEGORY_PREVIEW, $MEDIATYPE_Video, $oCapture, 0, 0)
MsgBox(0,'result renderstream  -2147467259',$aCall)
;~  / / Build the file writing part of the graph.
;~  IBaseFilter * pMux = 0;
;~  pBuild - > SetOutputFileName(&MEDIASUBTYPE_Avi, L"C:test.avi",
;~  & pMux, 0);
;~ Local $pMux
;~ $oBuild.SetOutputFileName($MEDIASUBTYPE_Avi, "E:test.avi", $pMux, 0)
;~ Local $oMux = ObjCreateInterface($pMux, $sIID_IBaseFilter, $tagIBaseFilter)
;~  hr = pBuild - > RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
;~  pCapture, Null, pMux);
;~ $oBuild.RenderStream($PIN_CATEGORY_CAPTURE, $MEDIATYPE_Video, $oCapture, 0, $oMux

;~ --------------------------- Run the graph.(Not shown.)

;I put Default to access IDispatch without the tagdefinition:
Local $oMediaControl = ObjCreateInterface($sCLSID_FilterGraph, $sIID_IMediaControl, Default)

local $aCall = $oMediaControl.get_FilterCollection()
_ArrayDisplay( $aCall )

Local $oVideoWindow = ObjCreateInterface($sCLSID_FilterGraph, $sIID_IVideoWindow, $tagIVideoWindow)
If @error Then Return SetError(5, 0, False)
$oBasicVideo = ObjCreateInterface($sCLSID_FilterGraph, $sIID_IBasicVideo , $tagIBasicVideo)
If @error Then Return SetError(11, 0, False)



$oVideoWindow.put_Owner(Number($hGUI))
$oVideoWindow.put_WindowStyle(BitOR($WS_CHILD, $WS_CLIPCHILDREN))


$oMediaControl.Run()
Sleep(5000)

;~  pGraph - > Release();
;~  pBuild - > Release();
;~  pCapture - > Release();
;~  pMux - > Release();
$oGraph = 0
$oBuild = 0
$oCapture = 0
;~ $oMux = 0
$oMediaControl = 0
$ovideoWindow = 0
$oBasicVideo = 0
;~  CoUninitialize();
;~  Return 0;
;~  }
EndFunc  ; end _Init

I have a return error code at this line:

local $ret= $oGraph.AddFilter($oCapture, "CaptureFilter")
MsgBox(0,'result oGraph  ', $ret) ; -2147220970

The other previous objects are created well (isObj=1), and the other calls return 0 that is S_OK.

So what could it be there?

I added some other objects, too, like $oBasicVideo, $ovideoWindow and $oMediaControl to run the graph (I hope, as this is my first approach with DS):

I put Default to access IDispatch without the tagdefinition:

Local $oMediaControl = ObjCreateInterface($sCLSID_FilterGraph, $sIID_IMediaControl, Default)

I saw your example of playing a video file with DS, so I extracted a bit some code.

My purpose is to access the capture pin of my webcam and to preview it in a GUI with some resolution greater than 640x480. Eventually after that, capture pics and avi compressed.

Instead of using the old method with avicap32 and user32 (that are limited at 640x480).

BTW: Before using ObjCreateInterface for oMediaControl I tried the QueryInterface to get a pointer to $sIIS_MediaControl,

but this crashed:

Local $aCall = $oGraph.QueryInterface($sIID_IMediaControl, 0)
  If IsArray($aCall) And $aCall[2] Then
   $oMediaControl = _AutoItObject_PtrToIDispatch($aCall[2])
  Else
   Return SetError(2, 0, False)
  EndIf

Only for curiosity, as I created oMediaControl with ObjCreateInterface, how do you use QueryInterface to get a pointer to a $sIID_?

[ I tried also $oGraph.QueryInterface(Number(DllStructGetPtr($tIID_IMediaControl)), 0) ]

BTW2:

you wrote:

$oBuild.RenderStream($PIN_CATEGORY_PREVIEW, $MEDIATYPE_Video, $oCapture(), 0, 0)

is oCapture() correct or should it be $oCapture ?

$oCapture is a pointer to an object, but oCapture() ?

Edited by frank10

Share this post


Link to post
Share on other sites
trancexx

Try this, I have cleaned some parts of your code:

#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

; Error monitoring
Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc()
    ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF)
EndFunc   ;==>_ErrFunc


;===============================================================================
#interface "IGraphBuilder"
Global Const $sCLSID_FilterGraph = "{E436EBB3-524F-11CE-9F53-0020AF0BA770}"
Global Const $sIID_IGraphBuilder = "{56A868A9-0AD4-11CE-B03A-0020AF0BA770}"
; Define IGraphBuilder methods
Global Const $tagIGraphBuilder = "AddFilter hresult(ptr;wstr);" & _
        "RemoveFilter hresult(ptr);" & _
        "EnumFilters hresult(ptr*);" & _
        "FindFilterByName hresult(wstr;ptr*);" & _
        "ConnectDirect hresult(ptr;ptr;ptr);" & _
        "Reconnect hresult(ptr);" & _
        "Disconnect hresult(ptr);" & _
        "SetDefaultSyncSource hresult();" & _ ; IFilterGraph
        "Connect hresult(ptr;ptr);" & _
        "Render hresult(ptr);" & _
        "RenderFile hresult(wstr;ptr);" & _
        "AddSourceFilter hresult(wstr;wstr;ptr*);" & _
        "SetLogFile hresult(dword_ptr);" & _
        "Abort hresult();" & _
        "ShouldOperationContinue hresult();" ; IGraphBuilder
;===============================END=============================================
;===============================================================================
#interface "ICaptureGraphBuilder2"
Global Const $sCLSID_CaptureGraphBuilder = '{BF87B6E0-8C27-11D0-B3F0-00AA003761C5}'
Global Const $sCLSID_CaptureGraphBuilder2 = '{BF87B6E1-8C27-11D0-B3F0-00AA003761C5}'
Global Const $sIID_ICaptureGraphBuilder2 = '{93e5a4e0-2d50-11d2-abfa-00a0c9c6e38d}'
; Definition
Global Const $tagICaptureGraphBuilder2 = "SetFiltergraph hresult(ptr);" & _
        "GetFiltergraph hresult(ptr*);" & _
        "SetOutputFileName hresult(clsid;wstr;ptr*;ptr*);" & _
        "FindInterface hresult(clsid;clsid;ptr;clsid;ptr*);" & _
        "RenderStream hresult(clsid;clsid;ptr;ptr;ptr);" & _
        "ControlStream hresult(clsid;clsid;ptr;ptr;ptr;word;word);" & _
        "AllocCapFile hresult(wstr;uint64);" & _
        "CopyCaptureFile hresult(wstr;wstr;int;ptr*);" & _
        "FindPin hresult(ptr;int;clsid;clsid;bool;int;ptr*);"
;===============================END=============================================
;===============================================================================
#interface "ICreateDevEnum"

Global Const $sCLSID_SystemDeviceEnum = '{62BE5D10-60EB-11d0-BD3B-00A0C911CE86}'
Global Const $sIID_ICreateDevEnum = '{29840822-5b84-11d0-bd3b-00a0c911ce86}'

; Definition
Global Const $tagICreateDevEnum = "CreateClassEnumerator hresult(clsid;ptr*;dword);"
;===============================END=============================================
;===============================================================================
#interface "IEnumMoniker"
Global Const $sCLSID_IEnumMoniker = '{56a86895-0ad4-11ce-b03a-0020af0ba770}'
Global Const $sIID_IEnumMoniker = '{00000102-0000-0000-00c0-000000000046}'
; Definition
Global Const $tagIEnumMoniker = "Next hresult(dword;ptr*;dword*);" & _
        "Skip hresult(dword);" & _
        "Reset hresult();" & _
        "Clone hresult(ptr*);"
;===============================END=============================================
;===============================================================================
#interface "IBaseFilter"
Global Const $sIID_IBaseFilter = '{56a86895-0ad4-11ce-b03a-0020af0ba770}'
; Definition
Global Const $tagIBaseFilter = "GetClassID hresult(ptr*);" & _; IPersist
        "Stop hresult();" & _
        "Pause hresult();" & _
        "Run hresult(int64);" & _
        "GetState hresult(dword;dword*);" & _
        "SetSyncSource hresult(ptr);" & _
        "GetSyncSource hresult(ptr*);" & _ ; IMediaFilter
        "EnumPins hresult(ptr*);" & _
        "FindPin hresult(wstr;ptr*);" & _
        "QueryFilterInfo hresult(ptr*);" & _
        "JoinFilterGraph hresult(ptr;wstr);" & _
        "QueryVendorInfo hresult(wstr*);" ; IBaseFilter
;===============================END=============================================
;===============================================================================
#interface "IMoniker"
Global Const $sCLSID_IMoniker = '{79eac9e0-baf9-11ce-8c82-00aa004ba90b}'
Global Const $sIID_IMoniker = '{0000000f-0000-0000-C000-000000000046}'
; Definition
Global Const $tagIMoniker = "GetClassID hresult( clsid )" & _
        "IsDirty hresult(  );" & _
        "Load hresult( ptr );" & _
        "Save hresult( ptr, bool );" & _
        "GetSizeMax hresult( uint64 );" & _
        "BindToObject hresult( ptr;ptr;clsid;ptr*);" & _
        "BindToStorage hresult( ptr;ptr;clsid;ptr*);" & _
        "Reduce hresult( ptr;dword;ptr*;ptr*);" & _
        "ComposeWith hresult( ptr;bool;ptr*);" & _
        "Enum hresult( bool;ptr*);" & _
        "IsEqual hresult( ptr);" & _
        "Hash hresult( dword);" & _
        "IsRunning hresult( ptr;ptr;ptr);" & _
        "GetTimeOfLastChange hresult( ptr;ptr;uint64);" & _
        "Inverse hresult( ptr*);" & _
        "CommonPrefixWith hresult( ptr;ptr*);" & _
        "RelativePathTo hresult( ptr;ptr*);" & _
        "GetDisplayName hresult( ptr;ptr;ushort);" & _
        "ParseDisplayName hresult( ptr;ptr;ushort;ulong;ptr*);" & _
        "IsSystemMoniker hresult( dword);"
;===============================END=============================================

Global Const $S_OK = 0
Global Const $PIN_CATEGORY_CAPTURE = '{fb6c4281-0353-11d1-905f-0000c0cc16ba}'
Global Const $PIN_CATEGORY_PREVIEW = '{fb6c4282-0353-11d1-905f-0000c0cc16ba}'
Global Const $MEDIASUBTYPE_Avi = '{e436eb88-524f-11ce-9f53-0020af0ba770}'
Global Const $MEDIATYPE_Video = '{73646976-0000-0010-8000-00aa00389b71}'
Global Const $sCLSID_VideoInputDeviceCategory = '{860bb310-5d01-11d0-bd3b-00a0c911ce86}'




;~  #include <dshow.h>
;~  int main(void)
;~  {
;~  IGraphBuilder * pGraph = 0;
;~  ICreateDevEnum * pDevEnum = 0;
;~  ICaptureGraphBuilder2 * pBuild = 0;
;~  HRESULT hr;
;~  CoInitialize(Null);
Local $hr

;~  / / Create the FGM.
;~  hr = CoCreateInstance(CLSID_FilterGraph, Null, CLSCTX_INPROC_SERVER,
;~  IID_IGraphBuilder, (void * *) & pGraph);
Local $oGraph = ObjCreateInterface($sCLSID_FilterGraph, $sIID_IGraphBuilder, $tagIGraphBuilder)


;~  / / Create the capture graph builder helper object
;~  hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, Null,
;~  CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2,
;~  (void * *) & pBuild);
Local $oBuild = ObjCreateInterface($sCLSID_CaptureGraphBuilder2, $sIID_ICaptureGraphBuilder2, $tagICaptureGraphBuilder2)


;~  / / Tell the capture graph builder about the FGM.
;~  hr = pBuild - > SetFiltergraph(pGraph);
$oBuild.SetFiltergraph($oGraph)


;~  / / Create a helper object To find the capture device.
;~  hr = CoCreateInstance(CLSID_SystemDeviceEnum, Null,
;~  CLSCTX_INPROC_SERVER,
;~  IID_ICreateDevEnum, (LPVOID *) & pDevEnum);
Local $oDevEnum = ObjCreateInterface($sCLSID_SystemDeviceEnum, $sIID_ICreateDevEnum, $tagICreateDevEnum)


;~  / / Use the first capture filter that we find.
;~  IEnumMoniker * pEnum = 0;
;~  IMoniker * pMoniker = 0;
;~  IBaseFilter * pCapture = 0;
;~  hr = pDevEnum - > CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
;~  & pEnum, 0);
Local $pEnum = 0
$oDevEnum.CreateClassEnumerator($sCLSID_VideoInputDeviceCategory, $pEnum, 0)

Local $oEnum = ObjCreateInterface($pEnum, $sIID_IEnumMoniker, $tagIEnumMoniker)

;~  If (S_OK == pEnum - > Next (1, &pMoniker, Null))
;~  {
;~  hr = pMoniker - > BindToObject(0, 0, IID_IBaseFilter, (void
;~  * *) & pCapture);
;~  }
Local $pMoniker, $oMoniker, $pCapture
If $oEnum.Next(1, $pMoniker, 0) = $S_OK Then
    $oMoniker = ObjCreateInterface($pMoniker, $sIID_IMoniker, $tagIMoniker)
    $oMoniker.BindToObject(0, 0, $sIID_IBaseFilter, $pCapture);
EndIf

Local $oCapture = ObjCreateInterface($pCapture, $sIID_IBaseFilter, $tagIBaseFilter)


;~  pMoniker - > Release();
;~  pEnum - > Release();
;~  pDevEnum - > Release();
$oMoniker = 0
$oEnum = 0
$oDevEnum = 0


;~  / / Add the capture filter To the filter graph
;~  hr = pGraph - > AddFilter(pCapture, L"CaptureFilter");
$hr = $oGraph.AddFilter($oCapture, "CaptureFilter")
ConsoleWrite(">>AddFilter hr = " & $hr & @CRLF)

;~  / / Build the preview part of the graph.
;~  hr = pBuild - > RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,
;~  pCapture, Null, Null);
$oBuild.RenderStream($PIN_CATEGORY_PREVIEW, $MEDIATYPE_Video, $oCapture, 0, 0)


;~  / / Build the file writing part of the graph.
;~  IBaseFilter * pMux = 0;
;~  pBuild - > SetOutputFileName(&MEDIASUBTYPE_Avi, L"C:\\test.avi",
;~  & pMux, 0);
Local $pMux
$oBuild.SetOutputFileName($MEDIASUBTYPE_Avi, "C:\test.avi", $pMux, 0)
Local $oMux = ObjCreateInterface($pMux, $sIID_IBaseFilter, $tagIBaseFilter)


;~  hr = pBuild - > RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
;~  pCapture, Null, pMux);
$oBuild.RenderStream($PIN_CATEGORY_CAPTURE, $MEDIATYPE_Video, $oCapture, 0, $oMux)


;~  / / Run the graph.(Not shown.)


;~  pGraph - > Release();
;~  pBuild - > Release();
;~  pCapture - > Release();
;~  pMux - > Release();
$oGraph = 0
$oBuild = 0
$oCapture = 0
$oMux = 0

;~  CoUninitialize();
;~  Return 0;
;~  }

As for QueryInterface:

Local $pMediaControl
$oGraph.QueryInterface($sIID_IMediaControl, $pMediaControl)
$oMediaControl = ObjCreateInterface($pMediaControl, $sIID_IMediaControl)

$oCapture() is the same as $oCapture because first is default $oCapture property and that's object pointer for InterfaceDispatchs (ObjCreateInterface). In case of no parenthesis AutoIt will internally query object for default property and pass that under parameter. This is standard COM procedure.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
frank10

EDIT:

The addFilter works and returns 0, so is good.

My error was in some tag definitions with the beginning with $dtagIDispatch &amp; _: I copied it from an old your example, but now it shouldn't be there...

But now, the next RenderStream gives a return error of 262782:

$hr = $oBuild.RenderStream($PIN_CATEGORY_PREVIEW, $MEDIATYPE_Video, $oCapture, 0, 0)
ConsoleWrite("&gt;&gt;Renderstream hr = " &amp; $hr &amp; @CRLF)

EDIT:

The second RenderStream with $PIN_CATEGORY_CAPTURE returns 0, instead. But it doesn't create a file.

Edited by frank10

Share this post


Link to post
Share on other sites
frank10

I put your $oMediaControl with QueryInterface and this time worked!

Also the file.

I don't know what is that return code 262782 in the Renderstream preview, anyway it the window appears...

Thank you, now I try to get proper resolution.

Share this post


Link to post
Share on other sites
frank10

On MSDN Renderstream, I found this:

Smart Tee. Some capture filters have a capture pin but no preview pin. To preview, the capture pin must be connected to the Smart Tee Filter. This filter splits the data into two streams, a capture stream and a preview stream. When you specify PIN_CATEGORY_PREVIEW or PIN_CATEGORY_CAPTURE, the method inserts a Smart Tee filter if one is needed. Then it renders the specified stream on the Smart Tee filter. If you render a preview stream and the method uses a Smart Tee filter, it returns VFW_S_NOPREVIEWPIN.

But the 262782 doesn't correspond to

#define VFW_S_NOPREVIEWPIN 0x8004027EL

Share this post


Link to post
Share on other sites
frank10

On msdn I found error list, so it's just that: VFW_S_NOPREVIEWPIN 0x0004027E

Preview was rendered throught the Smart Tee filter, because the capture filter does not have a preview pin.

I create also $oVideoWindow and $oBasicVideo:

Local $pVideoWindow
$oGraph.QueryInterface($sIID_IVideoWindow, $pVideoWindow)
Local $oVideoWindow = ObjCreateInterface($pVideoWindow, $sIID_IVideoWindow)

$hr = $oVideoWindow.put_Owner(Number($hGUI))

Local $iX=100, $iY=10
Local $iWidth = 640, $iHeight = 480
$hr =  $oVideoWindow.SetWindowPosition($iX, $iY, $iWidth, $iHeight)
MsgBox(0,'',$hr)

$oVideoWindow.put_WindowStyle(BitOR($WS_CHILD, $WS_CLIPCHILDREN))

Local $pBasicVideo
$oGraph.QueryInterface($sIID_IBasicVideo, $pBasicVideo)
$oBasicVideo = ObjCreateInterface($pBasicVideo, $sIID_IBasicVideo)
If @error Then  Return SetError(11, 0, False)

  Local $aCall = $oBasicVideo.IsUsingDefaultSource()
  MsgBox(0,'ISsource',$aCall)
_ArrayDisplay($aCall)

Local $aCall = $oBasicVideo.GetVideoSize()
_ArrayDisplay($aCall)

$oVideoWindow.put_Owner(Number($hGUI))

doesn't connect my video to the GUI: is floating in another video. Idem

$oVideoWindow.put_WindowStyle(BitOR($WS_CHILD, $WS_CLIPCHILDREN))
doesn't work.

But the $oVideoWindow exists and seems to work because with this:

$oVideoWindow.SetWindowPosition($iX, $iY, $iWidth, $iHeight)

I get the correct video size and position.

The $oBasicVideo does nothing instead...

Edited by frank10

Share this post


Link to post
Share on other sites
frank10

BTW:

If you are using the first script I posted, correct the line:

$sIID_IEnumMoniker = '{00000102-0000-0000-00c0-000000000046}'

to

$sIID_IEnumMoniker = '{00000102-0000-0000-c000-000000000046}'

Anyway, this is my actual script:

(I added VMR9 too, because the default renderer is crap quality)

#AutoIt3Wrapper_UseX64=n
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#include "AutoitObject.au3"
Opt("MustDeclareVars", 1)
Opt("WinWaitDelay", 0) ; 0 ms
; Error monitoring
Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
_AutoItObject_StartUp()
const  $CLSCTX_INPROC_SERVER     = 0x1
Global const $SIID_IMediaEventEx     = "{56A868C0-0AD4-11CE-B03A-0020AF0BA770}"
Global const $sIID_IMediaControl     = '{56A868B1-0AD4-11CE-B03A-0020AF0BA770}'
Global const $SIID_IBasicAudio    = "{56A868B3-0AD4-11CE-B03A-0020AF0BA770}"
Global Const $sCLSID_VideoInputDeviceCategory = '{860bb310-5d01-11d0-bd3b-00a0c911ce86}'
Global Const $S_OK = 0
Global Const $PIN_CATEGORY_CAPTURE   = '{fb6c4281-0353-11d1-905f-0000c0cc16ba}'
Global Const $PIN_CATEGORY_PREVIEW    = '{fb6c4282-0353-11d1-905f-0000c0cc16ba}'
Global Const $MEDIASUBTYPE_Avi    = '{e436eb88-524f-11ce-9f53-0020af0ba770}'
Global Const $MEDIATYPE_Video     = '{73646976-0000-0010-8000-00aa00389b71}'

; ############################ definitions ###############################
;===============================================================================
#interface "IGraphBuilder"
  ;~ // Create the FGM.
  Local $sCLSID_FilterGraph = "{E436EBB3-524F-11CE-9F53-0020AF0BA770}"
  Local $sIID_IGraphBuilder = "{56A868A9-0AD4-11CE-B03A-0020AF0BA770}"
  local $tIID_IGraphBuilder = _AutoItObject_CLSIDFromString("{56A868A9-0AD4-11CE-B03A-0020AF0BA770}")
  ; Define IGraphBuilder methods
  Local $tagIGraphBuilder = "AddFilter hresult(ptr;wstr);" & _
    "RemoveFilter hresult(ptr);" & _
    "EnumFilters hresult(ptr*);" & _
    "FindFilterByName hresult(wstr;ptr*);" & _
    "ConnectDirect hresult(ptr;ptr;ptr);" & _
    "Reconnect hresult(ptr);" & _
    "Disconnect hresult(ptr);" & _
    "SetDefaultSyncSource hresult();" & _ ; IFilterGraph
    "Connect hresult(ptr;ptr);" & _
    "Render hresult(ptr);" & _
    "RenderFile hresult(wstr;ptr);" & _
    "AddSourceFilter hresult(wstr;wstr;ptr*);" & _
    "SetLogFile hresult(dword_ptr);" & _
    "Abort hresult();" & _
    "ShouldOperationContinue hresult();" ; IGraphBuilder
;===============================END=============================================
;===============================================================================
#interface "ICaptureGraphBuilder2"
  local $sCLSID_CaptureGraphBuilder  = '{BF87B6E0-8C27-11D0-B3F0-00AA003761C5}'
  local $tIID_ICaptureGraphBuilder    = _AutoItObject_CLSIDFromString('{bf87b6e0-8c27-11d0-b3f0-00aa003761c5}' );
  local $sCLSID_CaptureGraphBuilder2 = '{BF87B6E1-8C27-11D0-B3F0-00AA003761C5}'
  Local $sIID_ICaptureGraphBuilder2   = '{93e5a4e0-2d50-11d2-abfa-00a0c9c6e38d}'
  local $tIID_ICaptureGraphBuilder2   = _AutoItObject_CLSIDFromString('{93e5a4e0-2d50-11d2-abfa-00a0c9c6e38d}');
  ; Definition
  Global Const $tagICaptureGraphBuilder2 = "SetFiltergraph hresult(ptr);" & _
   "GetFiltergraph hresult(ptr*);" & _
   "SetOutputFileName hresult(clsid;wstr;ptr*;ptr*);" & _
   "FindInterface hresult(clsid;clsid;ptr;clsid;ptr*);" & _
   "RenderStream hresult(clsid;clsid;ptr;ptr;ptr);" & _
   "ControlStream hresult(clsid;clsid;ptr;ptr;ptr;word;word);" & _
   "AllocCapFile hresult(wstr;int64);" & _
   "CopyCaptureFile hresult(wstr;wstr;int;ptr*);" & _
   "FindPin hresult(ptr;int;clsid;clsid;bool;int;ptr*);"
;===============================END=============================================
;===============================================================================
#interface "ICreateDevEnum"
  Global Const $sCLSID_SystemDeviceEnum   = '{62BE5D10-60EB-11d0-BD3B-00A0C911CE86}'
  Global Const $sIID_ICreateDevEnum    = '{29840822-5b84-11d0-bd3b-00a0c911ce86}'
  ; Definition
  Global Const $tagICreateDevEnum = "CreateClassEnumerator hresult( clsid ; ptr*; dword );"
;===============================END=============================================
;===============================================================================
#interface "IEnumMoniker"
  Global Const $sCLSID_IEnumMoniker    = '{56a86895-0ad4-11ce-b03a-0020af0ba770}'
  Global Const $sIID_IEnumMoniker    = '{00000102-0000-0000-c000-000000000046}'
  ; Definition
  Global Const $tagIEnumMoniker = "Next hresult(dword;ptr*;dword*);" & _
        "Skip hresult(dword);" & _
        "Reset hresult();" & _
        "Clone hresult(ptr*);"
;===============================END=============================================
;===============================================================================
#interface "IBaseFilter"
  Global Const $sIID_IBaseFilter     = '{56a86895-0ad4-11ce-b03a-0020af0ba770}'
  ; Definition
  Global Const $tagIBaseFilter = "GetClassID hresult(ptr*);" & _; IPersist
        "Stop hresult();" & _
        "Pause hresult();" & _
        "Run hresult(int64);" & _
        "GetState hresult(dword;dword*);" & _
        "SetSyncSource hresult(ptr);" & _
        "GetSyncSource hresult(ptr*);" & _ ; IMediaFilter
        "EnumPins hresult(ptr*);" & _
        "FindPin hresult(wstr;ptr*);" & _
        "QueryFilterInfo hresult(ptr*);" & _
        "JoinFilterGraph hresult(ptr;wstr);" & _
        "QueryVendorInfo hresult(wstr*);" ; IBaseFilter
;===============================END=============================================
;===============================================================================
#interface "IMoniker"
  Global Const $sCLSID_IMoniker    = '{79eac9e0-baf9-11ce-8c82-00aa004ba90b}'
  Global Const $sIID_IMoniker    = '{0000000f-0000-0000-C000-000000000046}'
  ; Definition
  Global Const $tagIMoniker = "GetClassID hresult( clsid )" & _
  "IsDirty hresult(  );" & _
  "Load hresult( ptr );" & _
  "Save hresult( ptr, bool );" & _
  "GetSizeMax hresult( uint64 );" & _
  "BindToObject hresult( ptr;ptr;clsid;ptr*);" & _
  "BindToStorage hresult( ptr;ptr;clsid;ptr*);" & _
  "Reduce hresult( ptr;dword;ptr*;ptr*);" & _
  "ComposeWith hresult( ptr;bool;ptr*);" & _
  "Enum hresult( bool;ptr*);" & _
  "IsEqual hresult( ptr);" & _
  "Hash hresult( dword);" & _
  "IsRunning hresult( ptr;ptr;ptr);" & _
  "GetTimeOfLastChange hresult( ptr;ptr;int64);" & _
  "Inverse hresult( ptr*);" & _
  "CommonPrefixWith hresult( ptr;ptr*);" & _
  "RelativePathTo hresult( ptr;ptr*);" & _
   "GetDisplayName hresult( ptr;ptr;wstr);" & _
  "ParseDisplayName hresult( ptr;ptr;wstr;ulong;ptr*);" & _
  "IsSystemMoniker hresult( dword);"
;===============================END=============================================
;===============================================================================
#interface "IVideoWindow"
  Global Const $sIID_IVideoWindow  = "{56A868B4-0AD4-11CE-B03A-0020AF0BA770}"
  ; IVideoWindow is dual interface. Defining vTable methods:  TOLTI asterischi!
  Local $tagIVideoWindow = "put_Caption hresult(bstr);" & _
   "get_Caption hresult(bstr);" & _
   "put_WindowStyle hresult(long);" & _
   "get_WindowStyle hresult(long);" & _
   "put_WindowStyleEx hresult(long);" & _
   "put_WindowStyleEx hresult(long);" & _
   "put_AutoShow hresult(long);" & _
   "get_AutoShow hresult(long);" & _
   "put_WindowState hresult(long);" & _
   "get_WindowState hresult(long);" & _
   "put_BackgroundPalette hresult(long);" & _
   "get_BackgroundPalette hresult(long);" & _
   "put_Visible hresult(long);" & _
   "get_Visible hresult(long);" & _
   "put_Left hresult(long);" & _
   "get_Left hresult(long);" & _
   "put_Width hresult(long);" & _
   "get_Width hresult(long);" & _
   "put_Top hresult(long);" & _
   "get_Top hresult(long);" & _
   "put_Height hresult(long);" & _
   "get_Height hresult(long);" & _
   "put_Owner hresult(long_ptr);" & _
   "get_Owner hresult(long_ptr);" & _
   "put_MessageDrain hresult(long_ptr);" & _
   "get_MessageDrain hresult(long_ptr);" & _
   "get_BorderColor hresult(long);" & _
   "put_BorderColor hresult(long);" & _
   "get_FullScreenMode hresult(long);" & _
   "put_FullScreenMode hresult(long);" & _
   "SetWindowForeground hresult(long);" & _
   "NotifyOwnerMessage hresult(long_ptr;long;long_ptr;long_ptr);" & _
   "SetWindowPosition hresult(long;long;long;long);" & _
   "GetWindowPosition hresult(long;long;long;long);" & _
   "GetMinIdealImageSize hresult(long;long);" & _
   "GetMaxIdealImageSize hresult(long;long);" & _
   "GetRestorePosition hresult(long;long;long;long);" & _
   "HideCursor hresult(long);" & _
   "IsCursorHidden hresult(long);" ; IVideoWindow
;===============================END=============================================
;===============================================================================
#interface "IBasicVideo"
  Global Const  $sIID_IBasicVideo = "{56A868B5-0AD4-11CE-B03A-0020AF0BA770}"
  Local $tagIBasicVideo = "get_AvgTimePerFrame hresult(double);" & _
   "get_BitRate hresult(long);" & _
   "get_BitErrorRate hresult(long);" & _
   "get_VideoWidth hresult(long);" & _
   "get_VideoHeight hresult(long);" & _
   "put_SourceLeft hresult(long);" & _
   "get_SourceLeft hresult(long);" & _
   "put_SourceWidth hresult(long);" & _
   "get_SourceWidth hresult(long);" & _
   "put_SourceTop hresult(long);" & _
   "get_SourceTop hresult(long);" & _
   "put_SourceHeight hresult(long);" & _
   "get_SourceHeight hresult(long);" & _
   "put_DestinationLeft hresult(long);" & _
   "get_DestinationLeft hresult(long);" & _
   "put_DestinationWidth hresult(long);" & _
   "get_DestinationWidth hresult(long);" & _
   "put_DestinationTop hresult(long);" & _
   "get_DestinationTop hresult(long);" & _
   "put_DestinationHeight hresult(long);" & _
   "get_DestinationHeight hresult(long);" & _
   "SetSourcePosition hresult(long;long;long;long);" & _
   "GetSourcePosition hresult(long;long;long;long);" & _
   "SetDefaultSourcePosition hresult();" & _
   "SetDestinationPosition hresult(long;long;long;long);" & _
   "GetDestinationPosition hresult(long;long;long;long);" & _
   "SetDefaultDestinationPosition hresult();" & _
   "GetVideoSize hresult(long;long);" & _
   "GetVideoPaletteEntries hresult(long;long;long;long);" & _
   "GetCurrentImage hresult(long;long);" & _
   "IsUsingDefaultSource hresult();" & _
   "IsUsingDefaultDestination hresult();" ; IBasicVideo
;===============================END=============================================

; ############################ end definitions ###############################

; GUI
Global $hGUI = GUICreate("DirectShow Capture", 1280, 720, -1, -1, -1, $WS_EX_ACCEPTFILES)

global $oBasicAudio, $oBasicVideo, $oBuild, $oCapture, $oDevEnum, $oEnum, $oGraph, $oIBaseFilter, $oMediaControl, $oICreateDevEnum,$oIEnumMoniker
Global $oVideoWindow, $oVmr9, $outputFile, $Vmr9
GUISetState()
_RenderWebcam()
While 1
Switch GUIGetMsg()
  Case -3
   ExitLoop
EndSwitch
WEnd
_ReleaseObjects()

Func _RenderWebcam()
Local $hr, $aCall
;~  / / Create the FGM.
$oGraph = ObjCreateInterface($sCLSID_FilterGraph, $sIID_IGraphBuilder, $tagIGraphBuilder)
;~  / / Create the capture graph builder helper object
$oBuild = ObjCreateInterface($sCLSID_CaptureGraphBuilder2, $sIID_ICaptureGraphBuilder2, $tagICaptureGraphBuilder2)
;~  / / Tell the capture graph builder about the FGM.
$oBuild.SetFiltergraph($oGraph)
;~  / / Create a helper object To find the capture device.
$oDevEnum = ObjCreateInterface($sCLSID_SystemDeviceEnum, $sIID_ICreateDevEnum, $tagICreateDevEnum)
;~  / / Use the first capture filter that we find.
Local $pEnum = 0
$oDevEnum.CreateClassEnumerator($sCLSID_VideoInputDeviceCategory, $pEnum, 0)
$oEnum = ObjCreateInterface($pEnum, $sIID_IEnumMoniker, $tagIEnumMoniker)
Local $pMoniker, $oMoniker, $pCapture
If $oEnum.Next(1, $pMoniker, 0) = $S_OK Then
  $oMoniker = ObjCreateInterface($pMoniker, $sIID_IMoniker, $tagIMoniker)
  $oMoniker.BindToObject(0, 0, $sIID_IBaseFilter, $pCapture);
EndIf
Local $oCapture = ObjCreateInterface($pCapture, $sIID_IBaseFilter, $tagIBaseFilter)
$oMoniker = 0
$oEnum = 0
$oDevEnum = 0
;~  / / Add the capture filter To the filter graph
$hr = $oGraph.AddFilter($oCapture, "CaptureFilter")
$Vmr9 = 1
if $Vmr9 = 0 Then
  ; renderer default: bad looking!
  ;~  / / Build the preview part of the graph.
  $hr = $oBuild.RenderStream($PIN_CATEGORY_PREVIEW, $MEDIATYPE_Video, $oCapture, 0, 0)
  ConsoleWrite(">>RenderstreamPrev hr = " & $hr & @CRLF) ; no preview pin, so Smart Tee
  ;~ Optionally, call RenderStream again to render the audio stream:
;~  $hr = $oBuild.RenderStream(0, $MEDIATYPE_Audio, $oCapture, 0, 0)
Else
  ; ------------------------ VMR9 -------------------
  global const $sCLSID_VideoMixingRenderer9 = '{51b4abf3-748f-4e3b-a276-c828330e926a}';
  $oVmr9 = ObjCreateInterface($sCLSID_VideoMixingRenderer9, $sIID_IBaseFilter, $tagIBaseFilter)
  ;~ Call IFilterGraph::AddFilter on the Filter Graph Manager to add the VMR-9 to the filter graph:
  $hr = $oGraph.AddFilter($oVmr9, "VMR9")
  ConsoleWrite(">>AddFilter VMR9 hr = " & $hr & @CRLF)
  ;~ Call the ICaptureGraphBuilder2::RenderStream method to render the video stream to the VMR:
  $hr = $oBuild.RenderStream($PIN_CATEGORY_PREVIEW, $MEDIATYPE_Video, $oCapture, 0, $oVmr9)
  ConsoleWrite(">>RenderstreamPrev VMR9 hr = " & $hr & @CRLF)
  ;~ Optionally, call RenderStream again to render the audio stream:
;~  $hr = $oBuild.RenderStream(0, $MEDIATYPE_Audio, $oCapture, 0, 0)
EndIf
$outputFile = 0
if $outputFile = 1 Then
  ; save to disk
  ; // Build the file writing part of the graph.
  Local $pMux, $oMux
  $hr = $oBuild.SetOutputFileName($MEDIASUBTYPE_Avi, "e:test.avi", $pMux, 0)
  ConsoleWrite(">>File hr = " & $hr & @CRLF)
  $oMux = ObjCreateInterface($pMux, $sIID_IBaseFilter, $tagIBaseFilter)
  ConsoleWrite(">>oMux = " & IsObj($oMux) & @CRLF)
  $hr = $oBuild.RenderStream($PIN_CATEGORY_CAPTURE, $MEDIATYPE_Video, $oCapture, 0, $oMux)
  ConsoleWrite(">>RenderstreamCap hr = " & $hr & @CRLF)
  $oMux = 0
EndIf
Local $pMediaControl
$oGraph.QueryInterface($sIID_IMediaControl, $pMediaControl)
$oMediaControl = ObjCreateInterface($pMediaControl, $sIID_IMediaControl)
Local $pVideoWindow
$oGraph.QueryInterface($sIID_IVideoWindow, $pVideoWindow)
$oVideoWindow = ObjCreateInterface($pVideoWindow, $sIID_IVideoWindow) ; non mettere la tag definition!
; connect video to GUI : doesn't work
$hr = $oVideoWindow.put_Owner(Number($hGUI))
; setta la posizione e dimensioni del filmato interno alla GUI: RISCALA l'input originale
Local $iX=100, $iY=10
Local $iWidth = 640, $iHeight = 480
$hr =  $oVideoWindow.SetWindowPosition($iX, $iY, $iWidth, $iHeight)
; serve per avere una finestra interna alla GUI senza bordi  : doesn't work
$oVideoWindow.put_WindowStyle(BitOR($WS_CHILD, $WS_CLIPCHILDREN))

Local $pBasicVideo
$oGraph.QueryInterface($sIID_IBasicVideo, $pBasicVideo)
$oBasicVideo = ObjCreateInterface($pBasicVideo, $sIID_IBasicVideo)
If @error Then Return SetError(11, 0, False)
$aCall = $oBasicVideo.put_SourceWidth('1280')
$aCall = $oBasicVideo.put_SourceHeight('720')
$aCall = $oBasicVideo.GetVideoSize()
_ArrayDisplay($aCall)
$oMediaControl.Run()
EndFunc  ; end _Renderwebcam

Func _ReleaseObjects()
$oBasicAudio = 0
$oBasicVideo = 0
$oVideoWindow = 0
$oMediaControl = 0
$oGraph = 0
$oBuild = 0
EndFunc   ;==>_ReleaseBuilder

Share this post


Link to post
Share on other sites
trancexx

On msdn I found error list, so it's just that: VFW_S_NOPREVIEWPIN 0x0004027E

Preview was rendered throught the Smart Tee filter, because the capture filter does not have a preview pin.

I create also $oVideoWindow and $oBasicVideo:

Local $pVideoWindow
$oGraph.QueryInterface($sIID_IVideoWindow, $pVideoWindow)
Local $oVideoWindow = ObjCreateInterface($pVideoWindow, $sIID_IVideoWindow)

$hr = $oVideoWindow.put_Owner(Number($hGUI))

Local $iX=100, $iY=10
Local $iWidth = 640, $iHeight = 480
$hr =  $oVideoWindow.SetWindowPosition($iX, $iY, $iWidth, $iHeight)
MsgBox(0,'',$hr)

$oVideoWindow.put_WindowStyle(BitOR($WS_CHILD, $WS_CLIPCHILDREN))

Local $pBasicVideo
$oGraph.QueryInterface($sIID_IBasicVideo, $pBasicVideo)
$oBasicVideo = ObjCreateInterface($pBasicVideo, $sIID_IBasicVideo)
If @error Then  Return SetError(11, 0, False)

  Local $aCall = $oBasicVideo.IsUsingDefaultSource()
  MsgBox(0,'ISsource',$aCall)
_ArrayDisplay($aCall)

Local $aCall = $oBasicVideo.GetVideoSize()
_ArrayDisplay($aCall)

$oVideoWindow.put_Owner(Number($hGUI))

doesn't connect my video to the GUI: is floating in another video. Idem

$oVideoWindow.put_WindowStyle(BitOR($WS_CHILD, $WS_CLIPCHILDREN))
doesn't work.

But the $oVideoWindow exists and seems to work because with this:

$oVideoWindow.SetWindowPosition($iX, $iY, $iWidth, $iHeight)

I get the correct video size and position.

The $oBasicVideo does nothing instead...

IBasicVideo and IVideoWindow inherit from IDispatch, they are dual interfaces. That means that your definitions for them are not right. Description strings miss $tagIDispatch.

Global Const $sIID_IDispatch = "..."
Global Const $tagIDispatch = "GetTypeInfoCount hresult(dword*);" & _
   "GetTypeInfo hresult(dword;dword;ptr*);" & _
   "GetIDsOfNames hresult(clsid;ptr;dword;dword;ptr);" & _
   "Invoke hresult(dword;clsid;dword;word;ptr;ptr;ptr;dword*);"
;...
Global Const $tagIVideoWindow = $tagIDispatch & ...
Global Const $tagIBasicVideo = $tagIDispatch & ...

Don't use Number(hGUI), just normal $oVideoWindow.put_Owner($hGUI)


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
frank10

I added the definitions, but I get a crash with this:

Local $pVideoWindow
$oGraph.QueryInterface($sIID_IVideoWindow, $pVideoWindow)
$oVideoWindow = ObjCreateInterface($pVideoWindow, $sIID_IVideoWindow, $tagIVideoWindow)
$hr = $oVideoWindow.put_Owner($hGUI) ;-----> crash

Share this post


Link to post
Share on other sites
frank10

Never mind.

I used the definitions contained in Autoit_Object, but they have IUnknown too, and that crashed!

So I rewrote without that and it works.

Share this post


Link to post
Share on other sites
frank10

I am here again :oops:

So, $oBasicVideo gives me nothing:

$hr = $oBasicVideo.put_SourceHeight(300)

$hr = $oBasicVideo.get_DestinationHeight()

$aCall = $oBasicVideo.GetVideoSize()

Instead, $oVideoWindow with some methods work:

$hr = $oVideowindow.put_Owner($hGUI)

$hr = $oVideowindow.SetWindowPosition($iX, $iY, $iWidth, $iHeight)

but a lot of 'get' methods don't work:

$hr = $oVideowindow.get_Height()

$hr = $oVideowindow.get_Owner()

$hr = $oVideowindow.get_WindowState()

$hr = $oVideowindow.GetMinIdealImageSize()

I get all $hr=''

EDIT:

I solved.

Edited by frank10

Share this post


Link to post
Share on other sites
frank10

I want to use this method:

http://msdn.microsoft.com/en-us/library/windows/desktop/dd319787%28v=vs.85%29.aspx

In the tag i wrote:

'GetStreamCaps hresult(int;struct*;byte*)'

and call it:

$hr = $oConfig.GetStreamCaps($iFormat, $pmtConfig, $scc);

so I think I need to declare $pmtConfig as a struct of type AM_MEDIA_TYPE:

;~ typedef struct _MediaType {
;~   GUID    majortype;
;~   GUID    subtype;
;~   BOOL    bFixedSizeSamples;
;~   BOOL    bTemporalCompression;
;~   ULONG  lSampleSize;
;~   GUID    formattype;
;~   IUnknown *pUnk;
;~   ULONG  cbFormat;
;~   BYTE    *pbFormat;
;~ } AM_MEDIA_TYPE;

Local $_MediaType = 'clsid majortype;clsid subtype;bool bFixedSizeSamples;bool bTemporalCompression;ulong lSampleSize;clsid formattype;ptr pUnk;ulong cbFormat;byte pbFormat'
Local $pmtConfig = DllStructCreate($_MediaType)
If @error Then
  MsgBox(4096, "", "Error in DllStructCreate " & @error);
  Exit
EndIf
local $scc[$iSize]
  $hr = $oConfig.GetStreamCaps($iFormat, $pmtConfig, $scc);

But in the DllStructCreate there isn't the clsid type. It gives me error.

@error= 2 : There is an unknown Data Type in the string passed.

The $scc should be an array, too.

How can I do?

Edited by frank10

Share this post


Link to post
Share on other sites
frank10

So I have this code:

IAMStreamConfig *pConfig = NULL;
hr = pBuild->FindInterface(
    &PIN_CATEGORY_CAPTURE, // Capture pin.
    0,  // Any media type.
    pCap, // Pointer to the capture filter.
    IID_IAMStreamConfig, (void**)&pConfig);
     AM_MEDIA_TYPE *pFormat;
    int iCount = 0, iSize = 0;
hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize);

    for (int iFormat = 0; iFormat < iCount; iFormat++)
    {
        VIDEO_STREAM_CONFIG_CAPS scc;
        AM_MEDIA_TYPE *pmtConfig;
        hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE*)&scc);
        if (SUCCEEDED(hr))
        {
            /* Examine the format, and possibly use it. */

            // Delete the media type when you are done.
            DeleteMediaType(pmtConfig);
        }
}

     VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmtConfig.pbFormat;
     // pVih contains the detailed format information.
     LONG lWidth = pVih->bmiHeader.biWidth;
     LONG lHeight = pVih->bmiHeader.biHeight;

     pVih.bmiHeader.biWidth = 1280;
     pVih.bmiHeader.biHeight = 720;
     pVih.bmiHeader.biSizeImage = DIBSIZE(pVih.bmiHeader);

hr = pConfig->SetFormat(pmtConfig);

I made:

global const $sIID_IAMStreamConfig = '{c6e13340-30ac-11d0-a18c-00a0c9118956}'
        ;define IAMStreamConfig interface
        global Const $tagIAMStreamConfig = 'SetFormat hresult(struct)' & _
            'GetFormat hresult(struct*)' & _
            'GetNumberOfCapabilities hresult(int*;int*)' & _
            'GetStreamCaps hresult(int;struct*;byte*)'

Local $oCapture = ObjCreateInterface($pCapture, $sIID_IBaseFilter, $tagIBaseFilter)

$hr = $oGraph.AddFilter($oCapture, "CaptureFilter")

Local $pConfig

$hr = $oBuild.FindInterface($PIN_CATEGORY_CAPTURE,$MEDIATYPE_Video,$oCapture,$sIID_IAMStreamConfig,$pConfig)
Global $oConfig = ObjCreateInterface($pConfig, $sIID_IAMStreamConfig, $tagIAMStreamConfig)

local $iCount=0,$iSize=0
$oConfig.GetNumberOfCapabilities($iCount,$iSize)

For $iFormat = 0 To $iCount step 1
     local $scc, $pmtConfig
     $hr = $oConfig.GetStreamCaps($iFormat, $pmtConfig, $scc);
     ; examine $pmtConfig...
Next

$pmtConfig is a struct AM_MEDIA_TYPE, and his pbFormat should be another struct:

VIDEOINFOHEADER structure describes the bitmap and color information for a video image.

typedef struct tagVIDEOINFOHEADER {

RECT rcSource;

RECT rcTarget;

DWORD dwBitRate;

DWORD dwBitErrorRate;

REFERENCE_TIME AvgTimePerFrame;

BITMAPINFOHEADER bmiHeader;

} VIDEOINFOHEADER;

From this struct, I should modify the bmiHeader that is another struct (the third inside!) to set new Width & Height values.

After this I should set the new values with:

hr = $oConfig.SetFormat($pmtConfig);

If I understand it correctly I should modify the struct bmiHeader (BITMAPINFOHEADER) contained by the struct pbFormat (VIDEOINFOHEADER) contained by the struct pmtConfig(AM_Media_TYPE),

I'm a bit lost here...

Anyway I get a crash before of these problems, at line:

$hr = $oConfig.GetStreamCaps($iFormat, $pmtConfig, $scc)

The object should be created well because the precedent line

$oConfig.GetNumberOfCapabilities($iCount,$iSize)

works.

Can you help me?

Edited by frank10

Share this post


Link to post
Share on other sites
frank10

It should be also another line in C code that checks that we are dealing with the correct video structure because it could be also an audio pin:

int iCount = 0, iSize = 0;
hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize);
// Check the size to make sure we pass in the correct structure.
if (iSize == sizeof(VIDEO_STREAM_CONFIG_CAPS))
{
    // Use the video capabilities structure.
    for (int iFormat = 0; iFormat < iCount; iFormat++)
    {
     ...

But in the precedent call:

hr = pBuild->FindInterface(
    &PIN_CATEGORY_CAPTURE, // Capture pin.
    0,  // Any media type.
    pCap, // Pointer to the capture filter.
...

I set it with $MEDIATYPE_Video:

$hr = $oBuild.FindInterface($PIN_CATEGORY_CAPTURE,$MEDIATYPE_Video,$oCapture,...

so it should find only the video pin... so I didn't checked the

if (iSize == sizeof(VIDEO_STREAM_CONFIG_CAPS))

(I don't know how to check it anyway...)

the $iSize from:

$oConfig.GetNumberOfCapabilities($iCount,$iSize)

gives me 128.

Edited by frank10

Share this post


Link to post
Share on other sites
trancexx

It should be:

"GetStreamCaps hresult(int;ptr*;struct*)"

MSDN is very clear about who does what. API allocates AM_MEDIA_TYPE structure and get you the pointer (second param), and you should allocate VIDEO_STREAM_CONFIG_CAPS structure and pass pointer to it as third parameter. I fail to see what's confusing there.

As for the size of he structure, there is DllStructGetSize(), or just count bytes manually..


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
frank10

You're completely right...

But in the VIDEO_STREAM_CONFIG_CAPS I have GUID and SIZE types:

how can I put these structs in a struct?

I create them separately but how do I insert them in the VIDEO_STREAM_CONFIG_CAPS struct?

Local $_GUID = "DWORD Data1;" & _
  "WORD  Data2;" & _
  "WORD  Data3;" & _
  "BYTE  Data4[8]"
  Local $tGuid = DllStructCreate($_GUID)
Local $_SIZE = "LONG cx;" & _
  "LONG cy"
  Local $tSize = DllStructCreate($_SIZE)

Local $_VIDEO_STREAM_CONFIG_CAPS = "GUID guid;" & _
  "ULONG    VideoStandard;" & _
  "SIZE  InputSize;" & _
  "SIZE  MinCroppingSize;" & _
  "SIZE  MaxCroppingSize;" & _
  "int    CropGranularityX;" & _
  "int    CropGranularityY;" & _
  "int    CropAlignX;" & _
  "int    CropAlignY;" & _
  "SIZE  MinOutputSize;" & _
  "SIZE  MaxOutputSize;" & _
  "int    OutputGranularityX;" & _
  "int    OutputGranularityY;" & _
  "int    StretchTapsX;" & _
  "int    StretchTapsY;" & _
  "int    ShrinkTapsX;" & _
  "int    ShrinkTapsY;" & _
  "int64  MinFrameInterval;" & _
  "int64  MaxFrameInterval;" & _
  "LONG  MinBitsPerSecond;" & _
  "LONG  MaxBitsPerSecond"
Edited by frank10

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×