hi everyone

somebody know hou to convert this small piece to masm syntax?
i thought it was some sort of struct

typedef enum _PinDirection {
  PINDIR_INPUT,
  PINDIR_OUTPUT
} PIN_DIRECTION;


Kind Regards
jpam
Posted on 2011-08-18 15:01:01 by jpam
_PinDirection STRUCT
  PINDIR_INPUT DB ?
  PINDIR_OUTPUT DB ?
_PinDirection ENDS

PIN_DIRECTION TYPEDEF _PinDirection


Then you can access the values using:

mov eax, PIN_DIRECTION.PINDIR_INPUT
mov ebx, _PinDirection.PINDIR_OUTPUT


That's probably more of a hack though since _PinDirection and PIN_DIRECTION are supposed to be a DWORD type and this isn't going to be the case. The following code might be a bit more "correct"...

PINDIR_INPUT = 0
PINDIR_OUTPUT = 1
_PinDirection TYPEDEF DWORD
PIN_DIRECTION TYPEDEF _PinDirection

Posted on 2011-08-18 15:26:24 by Synfire
Nah, an enum is just a way to automatically define a series of constants. It starts at 0, and increases each next constant by 1 (and optionally you can force a constant to a value, and it will continue from there).
Basically it says something like this:
PINDIR_INPUT equ 0
PINDIR_OUTPUT equ 1
Posted on 2011-08-18 15:27:48 by Scali
C-Style enumerations don't have to begin at zero, but they will if you don't assign any value to the first element in the enum. So they start at zero by default - however you might want to start at, say, 63. I'm not sure why but I'm sure there are situations where this is handy.
Posted on 2011-08-19 04:37:15 by Homer
mybe some more info is needed

c++ code

HRESULT GetUnconnectedPin(
    IBaseFilter *pFilter,  // Pointer to the filter.
    PIN_DIRECTION PinDir,  // Direction of the pin to find.
    IPin **ppPin)          // Receives a pointer to the pin.
{
    *ppPin = 0;
    IEnumPins *pEnum = 0;
    IPin *pPin = 0;
    HRESULT hr = pFilter->EnumPins(&pEnum);
    if (FAILED(hr))
    {
        return hr;
    }
    while (pEnum->Next(1, &pPin, NULL) == S_OK)
    {
        PIN_DIRECTION ThisPinDir;
        pPin->QueryDirection(&ThisPinDir);
        if (ThisPinDir == PinDir)
        {
            IPin *pTmp = 0;
            hr = pPin->ConnectedTo(&pTmp);
            if (SUCCEEDED(hr))  // Already connected, not the pin we want.
            {
                pTmp->Release();
            }
            else  // Unconnected, this is the pin we want.
            {
                pEnum->Release();
                *ppPin = pPin;
                return S_OK;
            }
        }
        pPin->Release();
    }
    pEnum->Release();
    // Did not find a matching pin.
    return E_FAIL;
}


this is a part of the code i have made:

         
_PinDirection STRUCT
  PINDIR_INPUT equ 0
  PINDIR_OUTPUT equ 1
_PinDirection ENDS

PIN_DIRECTION TYPEDEF _PinDirection

mov eax,PIN_DIRECTION
mov ThisPinDir,eax

@@:
coinvoke pEnum,IEnumMoniker,Next,1,addr pPin,ADDR pcFetched
cmp eax,0
jne @F

coinvoke pPin,IPin,QueryDirection,addr ThisPinDir
PrintHex eax,"QueryDirection"
PrintDec ThisPinDir ; show Direction

cmp eax,1
jne @B

coinvoke pPin,IPin,ConnectedTo,addr ppPin ; CRASH!
PrintHec eax ; show result
PrintDec ppPin ; do i have a pointer ?

@@:


PrintHex eax,"QueryDirection" gives error code (80004003) Invalid pointer
Posted on 2011-08-19 05:25:09 by jpam
Yes I understand the problem.


PIN_DIRECTION ThisPinDir;


This type is a MEMBER of the enumeration, and an enumeration (and its members) is NOT a struct.
In C languages, enumerated values are always (signed) Integers.
In other words, PIN_DIRECTION represents a SDWORD whose value is one of those listed in the enumeration - use equ in asm to define the enumerated values, and just "know" that C-style enums are in fact possible values to be assigned to an int.

And just to make it absolutely clear,

PINDIR_INPUT equ 0
PINDIR_OUTPUT equ 1

PIN_DIRECTION typedef SDWORD

local ThisPinDir PIN_DIRECTION;



Hope that gets you on track :)



Posted on 2011-08-19 06:07:26 by Homer
thanks people for looking at my problem !

i have tried all the possible solutions
but the line; "coinvoke pPin,IPin,QueryDirection,addr ThisPinDir" still crashed
i was wondering if my IPin interface is 100% correct
i added it myself to the Directshow.inc, because it was not included in my version.

sIID_IPin 				TEXTEQU <{056a86891h,00ad4h,011ceh,{0b0h,03ah,000h,020h,0afh,00bh,0a7h,070h}}>

_vtIPin MACRO CastName:REQ
; IUnknown methods
_vtIUnknown CastName
; IPin methods 
&CastName&_Connect comethod3 ?
&CastName&_ReceiveConnection comethod3 ?
&CastName&_Disconnect comethod1 ?
&CastName&_ConnectedTo comethod2 ?
&CastName&_ConnectionMediaType comethod2 ?
&CastName&_QueryPinInfo comethod2 ?
&CastName&_QueryDirection comethod2 ?
&CastName&_QueryId comethod2 ?
&CastName&_QueryAccept comethod2 ?
&CastName&_EnumMediaTypes comethod2 ?
&CastName&_QueryInternalConnections comethod3 ?
&CastName&_EndOfStream comethod1 ?
&CastName&_BeginFlush comethod1 ?
&CastName&_EndFlush comethod1 ?
&CastName&_NewSegment comethod4 ?
ENDM

IPin STRUCT
_vtIPin IPin
IPin ENDS


i hope someone wants to verified my IPin struct
Posted on 2011-08-20 13:51:27 by jpam
Hi jpam
There is a problem in the interface definition. Check this link. It shows the correct order of the methods in the vtable.
I have not verified the arguments of the methods.

Regards, Biterider
Posted on 2011-08-20 23:42:22 by Biterider

Thanks Homer
Thanks biterider


i corrected the IPin interface, QueryDirection should be the last member
i also made a custom comethod for the NewSegment member
to correct the bytelenght of the interface
it uses 2 qwords and 1 dword

comethodCustomProto      typedef proto :QWORD, :QWORD, :DWORD
comethodCustom     typedef ptr comethodCustomProto


now the code does not crash anymore :)
but the result in ThisPinDir gives me (looks like) a pointer
shouldn't it be 0 or 1 ?
Posted on 2011-08-21 06:20:25 by jpam
Hi jpam
The result (eax) of the IPin::NewSegment method call is a HRESULT value, which may be on of the values listed here (S_OK .. E_Fail).

Biterider
Posted on 2011-08-21 12:10:20 by Biterider
hi biterider

i don't use IPin::NewSegment :)
i only corrected the member typedef
the HRESULT from IPin::QueryDirection is S_OK
Posted on 2011-08-21 13:29:36 by jpam
Hi jpam
I think you have to supply a pointer to a PIN_DIRECTION variable, which will be filled on return of the IPin:QueryDirection with PINDIR_INPUT or PINDIR_OUTPUT. eax should contain S_OK indicating that the operation succeeded.

Biterider
Posted on 2011-08-21 15:29:23 by Biterider
found other solution to grab all frames from video file
can't make that IPin interface working :(

here's a working proc
GrabVideoBitmap proc

LOCAL pBuffer,hBitmap,BitmapSize,hDC,tmpDC,hOLD:dword
LOCAL MediaType:AM_MEDIA_TYPE
LOCAL mt:AM_MEDIA_TYPE
LOCAL bmi:BITMAPINFO

    INVOKE CoCreateInstance,addr CLSID_FilterGraph,NULL,CLSCTX_INPROC,ADDR IID_IGraphBuilder,ADDR pGraphBuilder
INVOKE CoCreateInstance,addr CLSID_SampleGrabber,NULL,CLSCTX_INPROC,addr IID_IBaseFilter,addr pGrabberBaseFilter

coinvoke pGrabberBaseFilter,ISampleGrabber,QueryInterface,addr IID_ISampleGrabber,addr pSampleGrabber
coinvoke pGraphBuilder,IGraphBuilder,AddFilter,pGrabberBaseFilter,L("Sample Grabber")

invoke RtlZeroMemory,addr mt,sizeof AM_MEDIA_TYPE
invoke RtlMoveMemory,addr mt.majortype,addr MEDIATYPE_Video,sizeof MEDIATYPE_Video
invoke RtlMoveMemory,addr mt.subtype,addr MEDIASUBTYPE_RGB24,sizeof MEDIASUBTYPE_RGB24
invoke RtlMoveMemory,addr mt.formattype,addr FORMAT_VideoInfo,sizeof FORMAT_VideoInfo
coinvoke pSampleGrabber,ISampleGrabber,SetMediaType,addr mt

coinvoke pGraphBuilder,IGraphBuilder,RenderFile,L("C:\wg_gdo_1.mpeg"),0
coinvoke pSampleGrabber,ISampleGrabber,SetBufferSamples,TRUE

coinvoke pGraphBuilder,IGraphBuilder,QueryInterface,addr IID_IVideoWindow,addr pVideoWindow
coinvoke pVideoWindow,IVideoWindow,put_AutoShow,FALSE

coinvoke pGraphBuilder,IGraphBuilder,QueryInterface,addr IID_IMediaControl,addr pControl
coinvoke pGraphBuilder,IGraphBuilder,QueryInterface,addr IID_IMediaSeeking,addr pSeek
coinvoke pSeek,IMediaSeeking,GetDuration,addr pDuration

coinvoke pControl,IMediaControl,Run

invoke RtlZeroMemory,addr MediaType,sizeof AM_MEDIA_TYPE
coinvoke pSampleGrabber,ISampleGrabber,GetConnectedMediaType,addr MediaType

invoke RtlZeroMemory,addr bmi,sizeof BITMAPINFO

push esi
push edi
mov esi,MediaType.pbFormat
lea edi,bmi
mov eax,40 ;DWORD biSize
mov ,eax
mov eax, ;LONG  biWidth
mov ,eax
mov eax, ;LONG  biHeight
mov ,eax
mov ax,1
mov ,ax ;WORD  biPlanes
mov ax,24 ;WORD  biBitCount
mov ,ax
mov eax,BI_RGB  ;DWORD biCompression
mov ,eax
mov eax, ;DWORD biSizeImage
mov ,eax
pop edi
pop esi

@@:
invoke GetDC,hWnd
mov hDC,eax

invoke CreateCompatibleDC,hDC
mov tmpDC,eax

invoke CreateDIBSection,hDC,addr bmi,DIB_PAL_COLORS,addr pBuffer,NULL,NULL
mov hBitmap,eax

invoke SelectObject,tmpDC,hBitmap
mov hOLD,eax

coinvoke pSampleGrabber,ISampleGrabber,GetCurrentBuffer,addr BitmapSize,NULL
coinvoke pSampleGrabber,ISampleGrabber,GetCurrentBuffer,addr BitmapSize,pBuffer 

invoke BitBlt,hDC,0,0,bmi.bmiHeader.biWidth,bmi.bmiHeader.biHeight,tmpDC,0,0,SRCCOPY

invoke SelectObject,tmpDC,hOLD
invoke DeleteObject,hBitmap

invoke ReleaseDC,hWnd,tmpDC
invoke ReleaseDC,hWnd,hDC

coinvoke pSeek,IMediaSeeking,GetCurrentPosition,addr pCurrent

fld pCurrent
fcomp pDuration
fnstsw ax
sahf
jb @B

coinvoke pControl,IMediaControl,Stop
call CleanUp


GrabVideoBitmap endp
Posted on 2011-08-24 13:37:20 by jpam
I use the SampleGrabber as well in my code (the automatic texture stuff is nice, but lacks control, and is D3D9-only).
But still you'll want to get good pin control if you want to build more advanced capture or decode graphs.
Posted on 2011-08-24 16:40:39 by Scali
could you share some example code scali ?
i love to see it :)

here's a updated proc
the last one had some memory leak issues...

GrabVideoBitmap proc

LOCAL pBuffer,hBitmap,BitmapSize,hDC,tmpDC,hOLD:dword

    INVOKE CoCreateInstance,addr CLSID_FilterGraph,NULL,CLSCTX_INPROC,ADDR IID_IGraphBuilder,ADDR pGraphBuilder
INVOKE CoCreateInstance,addr CLSID_SampleGrabber,NULL,CLSCTX_INPROC,addr IID_IBaseFilter,addr pGrabberBaseFilter

coinvoke pGrabberBaseFilter,ISampleGrabber,QueryInterface,addr IID_ISampleGrabber,addr pSampleGrabber
coinvoke pGraphBuilder,IGraphBuilder,AddFilter,pGrabberBaseFilter,L("Sample Grabber")

invoke RtlZeroMemory,addr mt,sizeof AM_MEDIA_TYPE
invoke RtlMoveMemory,addr mt.majortype,addr MEDIATYPE_Video,sizeof MEDIATYPE_Video
invoke RtlMoveMemory,addr mt.subtype,addr MEDIASUBTYPE_RGB24,sizeof MEDIASUBTYPE_RGB24
invoke RtlMoveMemory,addr mt.formattype,addr FORMAT_VideoInfo,sizeof FORMAT_VideoInfo
mov mt.cbFormat,0
mov mt.pbFormat,NULL
coinvoke pSampleGrabber,ISampleGrabber,SetMediaType,addr mt

coinvoke pGraphBuilder,IGraphBuilder,RenderFile,L("C:\wg_gdo_1.mpeg"),0
coinvoke pSampleGrabber,ISampleGrabber,SetBufferSamples,TRUE

coinvoke pGraphBuilder,IGraphBuilder,QueryInterface,addr IID_IVideoWindow,addr pVideoWindow
coinvoke pVideoWindow,IVideoWindow,put_AutoShow,FALSE

coinvoke pGraphBuilder,IGraphBuilder,QueryInterface,addr IID_IMediaControl,addr pControl
coinvoke pGraphBuilder,IGraphBuilder,QueryInterface,addr IID_IMediaSeeking,addr pSeek
coinvoke pSeek,IMediaSeeking,GetDuration,addr pDuration

coinvoke pControl,IMediaControl,Run

invoke RtlZeroMemory,addr mt,sizeof AM_MEDIA_TYPE
coinvoke pSampleGrabber,ISampleGrabber,GetConnectedMediaType,addr mt

invoke RtlZeroMemory,addr bmi,sizeof BITMAPINFO

push esi
push edi
mov esi,mt.pbFormat
lea edi,bmi
mov eax,40 ;DWORD biSize
mov ,eax
mov eax, ;LONG  biWidth
mov ,eax
mov eax, ;LONG  biHeight
mov ,eax
mov ax,1
mov ,ax ;WORD  biPlanes
mov ax,24 ;WORD  biBitCount
mov ,ax
mov eax,BI_RGB  ;DWORD biCompression
mov ,eax
mov eax, ;DWORD biSizeImage
mov ,eax
pop edi
pop esi

invoke GetDC,hwnd
mov hDC,eax

invoke CreateCompatibleDC,hDC
mov tmpDC,eax

@@:

invoke CreateDIBSection,hDC,addr bmi,DIB_PAL_COLORS,addr pBuffer,NULL,NULL
mov hBitmap,eax

invoke SelectObject,tmpDC,hBitmap
mov hOLD,eax

coinvoke pSampleGrabber,ISampleGrabber,GetCurrentBuffer,addr BitmapSize,NULL
coinvoke pSampleGrabber,ISampleGrabber,GetCurrentBuffer,addr BitmapSize,pBuffer 

invoke BitBlt,hDC,0,0,bmi.bmiHeader.biWidth,bmi.bmiHeader.biHeight,tmpDC,0,0,SRCCOPY

invoke SelectObject,tmpDC,hOLD
invoke DeleteObject,hBitmap

coinvoke pSeek,IMediaSeeking,GetCurrentPosition,addr pCurrent

fld pCurrent
fcomp pDuration
fnstsw ax
sahf
jb @B

coinvoke pControl,IMediaControl,Stop

invoke CoTaskMemFree,mt.pbFormat

invoke ReleaseDC,hwnd,tmpDC
invoke ReleaseDC,hwnd,hDC

SAFE_RELEASE pSeek
SAFE_RELEASE pControl
SAFE_RELEASE pVideoWindow
    SAFE_RELEASE pGrabberBaseFilter
    SAFE_RELEASE pSampleGrabber
    SAFE_RELEASE pGraphBuilder

ret

GrabVideoBitmap endp
Posted on 2011-08-24 17:15:48 by jpam
Yeah I did some stuff years ago under coinvoke i will scratch around in the vaults.. searching here yields nothing, guess those posts were lost during one of the rare disasters we've had :( More reason to dig it up I guess.
Posted on 2011-08-25 04:16:23 by Homer
Well, I started out from an example I found with Ogre:
http://www.ogre3d.org/tikiwiki/DirectShow+video+in+ogre+texture&structure=Cookbook
(look a bit below for the CVDShowUtil.cpp file... It's from the old DirectShow SDK, and shows some pin connecting stuff... Very important... I guess you should try and compile this, then disassemble it, so you can fix your assembly version).

I just ripped out the Ogre code and replaced it with Direct3D stuff.
Then I refactored it all to make it fit nicely into the VJ software, but that all just overcomplicates things.
I have a separate DirectShow decoder which provides frames, and a DynamicTexture which consumes these frames... By keeping the same provider and consumer interfaces, I can easily use other frame providers, such as QuickTime. And I can also use different types of DynamicTexture... Apart from D3D9, 10, 11 I also support decoding to system memory for CPU processing... and I could also support decoding to a Cuda buffer for GPGPU processing etc.
Posted on 2011-08-25 08:51:49 by Scali