flat assembler
Message board for the users of flat assembler.

Index > Windows > problem with directshow ( How to play a file )

Author
Thread Post new topic Reply to topic
dancho



Joined: 06 Mar 2011
Posts: 74
dancho
hi all,
first post Cool but long time lurker Wink
so in PSDK there is a classical console application that demonstrates simple ( yet powerful ) use of directshow programming How to play a file,and this is my port to fasm :

Code:
format PE console
entry cmain
include 'win32ax.inc'
;----------------------------------------------------------------------------------------------------------------------------------------
struc GUID def 
 { 
   match d1-d2-d3-d4-d5, def 
    \{ 
      .Data1 dd 0x\#d1 
      .Data2 dw 0x\#d2 
      .Data3 dw 0x\#d3 
      .Data4 db 0x\#d4 shr 8,0x\#d4 and 0FFh 
      .Data5 db 0x\#d5 shr 40,0x\#d5 shr 32 and 0FFh,0x\#d5 shr 24 and 0FFh,0x\#d5 shr 16 and 0FFh,0x\#d5 shr 8 and 0FFh,0x\#d5 and 0FFh 
    \} 
 }
;----------------------------------------------------------------------------------------------------------------------------------------
interface IGraphBuilder,\                       
                  QueryInterface,\                      
                  AddRef,\                                      
                  Release,\                                     
                  AddFilter,\                                           
                  RemoveFilter,\                        
                  EnumFilters,\                         
                  FindFilterByName,\            
                  ConnectDirect,\                       
                  Reconnect,\                           
                  Disconnect,\                          
                  SetDefaultSyncSource,\                
                  Connect,\                                     
                  Render,\                                      
                  RenderFile,\                          
                  AddSourceFilter,\                     
                  SetLogFile,\                          
                  Abort,\                                       
                  ShouldOperationContinue       
;----------------------------------------------------------------------------------------------------------------------------------------
  interface IMediaControl,\
                  QueryInterface,\                      
                  AddRef,\                                      
                  Release,\                                     
                  GetTypeInfoCount,\            
                  GetTypeInfo,\                         
                  GetIDsOfNames,\                        
                  Invoke,\                                      
                  Run,\                                         
                  Pause,\                                       
                  Stop,\                                        
                  GetState,\
                  RenderFile,\
                  AddSourceFilter,\
                  get_FilterCollection,\
                  get_RegFilterCollection,\
                  StopWhenReady            
;----------------------------------------------------------------------------------------------------------------------------------------
 interface IMediaEvent,\
                  QueryInterface,\                      
                  AddRef,\                                      
                  Release,\                                     
                  GetTypeInfoCount,\            
                  GetTypeInfo,\                         
                  GetIDsOfNames,\                        
                  Invoke,\                                      
                  GetEventHandle,\
                  GetEvent,\
                  WaitForCompletion,\
                  CancelDefaultHandling,\
                  RestoreDefaultHandling,\
                  FreeEventParams        
;----------------------------------------------------------------------------------------------------------------------------------------                 
CLSCTX_INPROC_SERVER    = 0x1
MB_PRECOMPOSED = 1h
INFINITE = 0FFFFFFFFh
;----------------------------------------------------------------------------------------------------------------------------------------

section '.data' data readable writeable
        CLSID_FilterGraph       GUID    E436EBB3-524F-11CE-9F53-0020AF0BA770
        IID_IGraphBuilder       GUID    56A868A9-0AD4-11CE-B03A-0020AF0BA770
        IID_IMediaControl       GUID    56A868B1-0AD4-11CE-B03A-0020AF0BA770
        IID_IMediaEvent         GUID    56A868B6-0AD4-11CE-B03A-0020AF0BA770
        ;
        pGraphBuilder   IGraphBuilder
        pMediaControl   IMediaControl
        pMediaEvent     IMediaEvent
        ;
        evCode  dd      0
        ;
        movie   db      'path to avi',0
        buff    rb      256

section '.code' code readable executable
cmain:
                
                ; initialize the COM library
                invoke CoInitialize,NULL
                ; create the Filter Graph Manager
                invoke CoCreateInstance,CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,IID_IGraphBuilder,pGraphBuilder
                ; query IMediaControl and IMediaEvent
                cominvk pGraphBuilder,QueryInterface,IID_IMediaControl,pMediaControl
                cominvk pGraphBuilder,QueryInterface,IID_IMediaEvent,pMediaEvent        
                ; name of the movie must be wide character (2-byte) string
                invoke MultiByteToWideChar,CP_ACP,MB_PRECOMPOSED,movie,-1,buff,128
                ; build a filter graph that renders the specified file
                cominvk pGraphBuilder,RenderFile,buff,NULL ;                   <---- HERE IS OLLY2 STALLING !!!
                ; run the graph
                cominvk pMediaControl,Run
                ; Wait for completion
                cominvk pMediaEvent,WaitForCompletion,INFINITE,evCode
                ; release the interface pointers and close the COM library 
                cominvk pMediaControl,Release
                cominvk pMediaEvent,Release
                cominvk pGraphBuilder,Release
        
                invoke CoUninitialize
                
                invoke ExitProcess,0
        
section '.idata' data import readable
        library kernel32,'kernel32.dll',\
                        ole32,'ole32.dll'
        
        import kernel32,\
                   MultiByteToWideChar,'MultiByteToWideChar',\
                   ExitProcess,'ExitProcess'
        
        import ole32,\
                   CoInitialize,'CoInitialize',\
                   CoCreateInstance,'CoCreateInstance',\
                   CoUninitialize,'CoUninitialize'

    


This little snipet compiles ok but crashes at run,you'll notice one comment in code 'Here is Olly2 stalling' , at that code line Olly2 just stall , simple cant go over but if you hit F9 ( run debugged app ) it runs ok ,
but no movie is rendered in active window,
fasm is 1.69.31 ,os is winxp(sp2) ,latest directx and drivers...
so any help with this is appreciated,
thx for your time

Dancho


Last edited by dancho on 08 Mar 2011, 09:29; edited 1 time in total
Post 06 Mar 2011, 09:33
View user's profile Send private message Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 204
Location: Brazil
ctl3d32
Well, it works for me. It creates a window and shows what seems to be the very first frame of the .avi file and than this window close. All heappens very fast. It does not play the file. Below is the proof. The active window is fading out.

P.S.: I can only see the very first frame of the .avi when i'm in ollydbg, since the .exe runs slower. Outside olly, it closes before showing the first frame. It is too fast.

My OS: win7 pro x64

Image
Post 06 Mar 2011, 13:09
View user's profile Send private message Reply with quote
dancho



Joined: 06 Mar 2011
Posts: 74
dancho
@ctl3d32
thx for trying,
well I put extra effort and installed clean xp in virtualbox,
avi playing fine in media player but not in program nor in Olly2...
This is original code from PSDK if anyone interested :

Code:
#include <dshow.h>
void main(void)
{
    IGraphBuilder *pGraph = NULL;
    IMediaControl *pControl = NULL;
    IMediaEvent   *pEvent = NULL;

    // Initialize the COM library.
    HRESULT hr = CoInitialize(NULL);
    if (FAILED(hr))
    {
        printf("ERROR - Could not initialize COM library");
        return;
    }

    // Create the filter graph manager and query for interfaces.
    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, 
                        IID_IGraphBuilder, (void **)&pGraph);
    if (FAILED(hr))
    {
        printf("ERROR - Could not create the Filter Graph Manager.");
        return;
    }

    hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
    hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

    // Build the graph. IMPORTANT: Change this string to a file on your system.
    hr = pGraph->RenderFile(L"C:\\Example.avi", NULL);
    if (SUCCEEDED(hr))
    {
        // Run the graph.
        hr = pControl->Run();
        if (SUCCEEDED(hr))
        {
            // Wait for completion.
            long evCode;
            pEvent->WaitForCompletion(INFINITE, &evCode);

            // Note: Do not use INFINITE in a real application, because it
            // can block indefinitely.
        }
    }
    pControl->Release();
    pEvent->Release();
    pGraph->Release();
    CoUninitialize();
}

    


thx...
Post 06 Mar 2011, 17:31
View user's profile Send private message Reply with quote
SFeLi



Joined: 03 Nov 2004
Posts: 140
SFeLi
The order of methods in at least IMediaEvent is wrong. Probably you should check other interfaces too.
Post 06 Mar 2011, 19:29
View user's profile Send private message Reply with quote
dancho



Joined: 06 Mar 2011
Posts: 74
dancho
@SFeLi
yup,true...thx for notice...
this is valid IMediaControl and IMediaEvent interface :

Code:
interface IMediaControl,\
                  QueryInterface,\                      
                  AddRef,\                                      
                  Release,\                                     
                  GetTypeInfoCount,\            
                  GetTypeInfo,\                         
                  GetIDsOfNames,\                        
                  Invoke,\                                      
                  Run,\                                         
                  Pause,\                                       
                  Stop,\                                        
                  GetState,\
                  RenderFile,\
                  AddSourceFilter,\
                  get_FilterCollection,\
                  get_RegFilterCollection,\
                  StopWhenReady

interface IMediaEvent,\
                  QueryInterface,\                      
                  AddRef,\                                      
                  Release,\                                     
                  GetTypeInfoCount,\            
                  GetTypeInfo,\                         
                  GetIDsOfNames,\                        
                  Invoke,\                                      
                  GetEventHandle,\
                  GetEvent,\
                  WaitForCompletion,\
                  CancelDefaultHandling,\
                  RestoreDefaultHandling,\
                  FreeEventParams

    


but the problem still remains...
thx...
Post 07 Mar 2011, 08:19
View user's profile Send private message Reply with quote
dancho



Joined: 06 Mar 2011
Posts: 74
dancho
so after reinstalling directx_Jun2010_redist package program is still crashing but Very Happy it is working in Olly2 only with F9 , active window is started and clip is playing ok and exit normaly...
but still stalling at :
cominvk pGraphBuilder,RenderFile,buff,NULL ;
when debugged step by step...
any suggestion for trying something else is appreciated...
Post 08 Mar 2011, 09:41
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.