It is currently Wed Aug 22, 2018 6:42 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Help reqd with Media Foundation interfaces
PostPosted: Tue May 27, 2014 10:10 am 
Offline
Enthusiast
Enthusiast

Joined: Sun Apr 06, 2008 12:54 pm
Posts: 357
Location: Brisbane, Qld, Australia
I want to use Windows Media Foundation in my program, but my knowledge of C++ is very limited so I'm having difficulty working out how to use the IMFMediaSession interface. I have coded the following:
Code:
Interface IMFMediaSession
  ClearTopologies()
  Close()
  GetClock(*ppClock)
  GetFullTopology(dwGetFullTopologyFlags, TopoId, *ppFullTopo)
  GetSessionCapabilities(*pdwCaps)
  Pause()
  SetTopology(dwSetTopologyFlags.l, *pTopology)
  Shutdown()
  Start(*pguidTimeFormat.GUID, *pvarStartPosition)
  Stop()
EndInterface

Prototype.l PR_MFCreateMediaSession(*pConfiguration, *ppMediaSession)
Global MFCreateMediaSession.PR_MFCreateMediaSession
(plus OpenLibary(), GetFunction(), etc)

The documentation states "To obtain a pointer to this interface, call MFCreateMediaSession", so I have written:
Code:
hResult = MFCreateMediaSession(#Null, @ppMS)

where ppMS is a pointer.

My question is, assuming what I've done so far is correct (and it may not be!), how do I then use functions within this object? For example, using the PB Interface structure I should be able issue something like:
\Shutdown()
on the object, but having just a pointer (ppMS) to the object I'm not sure how to do this.

Can anyone advise me?

_________________
Mike
www.showcuesystems.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Help reqd with Media Foundation interfaces
PostPosted: Tue May 27, 2014 4:12 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Mar 21, 2006 12:31 am
Posts: 1773
Location: Canada
Code:
ppMS.IMFMediaSession

ppMS\Shutdown()

_________________
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley


Top
 Profile  
Reply with quote  
 Post subject: Re: Help reqd with Media Foundation interfaces
PostPosted: Wed May 28, 2014 8:15 am 
Offline
Enthusiast
Enthusiast

Joined: Sun Apr 06, 2008 12:54 pm
Posts: 357
Location: Brisbane, Qld, Australia
Thanks, Thunder93 - that looked promising but unfortunately I get 'invalid memory access' on the ppMS\Shutdown(). I'm wondering if I need to do something different as ppMS is a pointer-to-a-pointer, because the C++ definition of MFCreateMediaSession is:
Code:
HRESULT MFCreateMediaSession(
  IMFAttributes *pConfiguration,
  IMFMediaSession **ppMS
);

I've put together a basic trial program which just starts up MF (Media Foundation), creates a session, shuts down the session, and then shuts down MF. If I bypass the session creation and stop, the MF startup and shutdown are successful. If I include the session creation and stop, the session create is successful (but that doesn't use a PB interface function) but the session stop (which does use a PB interface function) crashes with an IMA. Here's the complete code of this trial program:
Code:
EnableExplicit

Interface IMFMediaSession
  ClearTopologies()
  Close()
  GetClock(*ppClock)
  GetFullTopology(dwGetFullTopologyFlags, TopoId, *ppFullTopo)
  GetSessionCapabilities(*pdwCaps)
  Pause()
  SetTopology(dwSetTopologyFlags.l, *pTopology)
  Shutdown()
  Start(*pguidTimeFormat.GUID, *pvarStartPosition)
  Stop()
EndInterface
Global ppMS.IMFMediaSession

Prototype.l PR_MFStartup(version.l, dwFlags.l)
Prototype.l PR_MFShutdown()
Prototype.l PR_MFCreateMediaSession(*pConfiguration, *ppMediaSession)

Global MFStartup.PR_MFStartup
Global MFShutdown.PR_MFShutdown
Global MFCreateMediaSession.PR_MFCreateMediaSession

If OSVersion() >= #PB_OS_Windows_7
  Global MF_SDK_VERSION = $0002
Else ; Vista
  Global MF_SDK_VERSION = $0001
EndIf

#MF_API_VERSION = $0070 ;  This value is unused in the Win7 release and left at its Vista release value
Global MF_VERSION = MF_SDK_VERSION << 16 | #MF_API_VERSION

#MFSTARTUP_NOSOCKET = $1
#MFSTARTUP_LITE = #MFSTARTUP_NOSOCKET
#MFSTARTUP_FULL = 0

Procedure MFControl()
  Protected hResult.l
   
  hResult = MFStartup(MF_VERSION, #MFSTARTUP_FULL)
  Debug "MFStartup returned " + hResult
 
  If 1=1
    hResult = MFCreateMediaSession(#Null, @ppMS)
    Debug "MFCreateMediaSession(#Null, @ppMS) returned " + hResult
    If hResult = #S_OK
      ppMS\Shutdown()
    EndIf
  EndIf

  hResult = MFShutdown()
  Debug "MFShutdown returned " + hResult
   
EndProcedure

Procedure LibraryControl()
  Protected iMFLibrary.i, iMFPlatLibrary.i
 
  iMFPlatLibrary = OpenLibrary(#PB_Any, "mfplat.dll")
  If iMFPlatLibrary
    MFStartup.PR_MFStartup = GetFunction(iMFPlatLibrary, "MFStartup")
    Debug "MFStartup=" + MFStartup
    MFShutdown.PR_MFShutdown = GetFunction(iMFPlatLibrary, "MFShutdown")
    Debug "MFShutdown=" + MFShutdown

    iMFLibrary = OpenLibrary(#PB_Any, "mf.dll")
    If iMFLibrary
      MFCreateMediaSession.PR_MFCreateMediaSession = GetFunction(iMFLibrary, "MFCreateMediaSession")
      Debug "MFCreateMediaSession=" + MFCreateMediaSession
     
      MFControl()
     
      CloseLibrary(iMFLibrary)
    EndIf
    CloseLibrary(iMFPlatLibrary)
  EndIf
 
EndProcedure

LibraryControl()

Debug "End of run"
End

As I mentioned earlier in this posting, I suspect the ** is the cause of the problem. Any ideas how to fix this?

_________________
Mike
www.showcuesystems.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Help reqd with Media Foundation interfaces
PostPosted: Wed May 28, 2014 9:22 am 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 2916
Location: Planet Earth
Change
Code:
Interface IMFMediaSession
to:
Code:
Interface IMFMediaSession Extends IUnknown

IUnknown is the base COM interface. Every Windows COM object has this base interface.

You also need to call ppMS\Release() after ppMS\Shutdown():
- MFCreateMediaSession function
Quote:
The caller must release the interface.
Before releasing the last reference to the IMFMediaSession pointer, the application must call the IMFMediaSession::Shutdown method.

AddRef() and Release() are from COM base interface 'IUnknown' and are used for reference counting
and releasing/freeing the object.


Top
 Profile  
Reply with quote  
 Post subject: Re: Help reqd with Media Foundation interfaces
PostPosted: Wed May 28, 2014 11:33 pm 
Offline
Enthusiast
Enthusiast

Joined: Sun Apr 06, 2008 12:54 pm
Posts: 357
Location: Brisbane, Qld, Australia
Thanks Danilo. I now have a clean run, and thanks for the explanation - I've never got my head around COM objects, but it looks like I'll need to!

I can now progress and start adding some useful code to this trial program.

_________________
Mike
www.showcuesystems.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Help reqd with Media Foundation interfaces
PostPosted: Wed May 16, 2018 7:30 pm 
Offline
New User
New User
User avatar

Joined: Fri Feb 02, 2018 10:33 pm
Posts: 7
Location: New Jersey
Hello Ozzie,

Did you ever get the Media Foundation working.

Some sample code would be greatly appreciated
examples for video and audio would be a great help.

Thanks

_________________
Mac OSX Sierra 10.12.6 & Windows 7, PB 4.62


Top
 Profile  
Reply with quote  
 Post subject: Re: Help reqd with Media Foundation interfaces
PostPosted: Thu May 17, 2018 6:01 am 
Offline
Enthusiast
Enthusiast

Joined: Sun Apr 06, 2008 12:54 pm
Posts: 357
Location: Brisbane, Qld, Australia
No, unfortunately I never got MF working. I've just revisited the test program I wrote and I get a memory error when I start it, so I must have something wrong in my code.

I ended up using TVideoGrabber (TVG) from Datastead Software. This works well, but I had to create an include file of PB structures, prototypes, etc, for the TVG functions, and have to update this where necessary when a new version of TVG is released. If anyone needs this include file then I'd be happy to share it. Although TVideoGrabber works well, it is not the ultimate video playback library - there are some things it doesn't do well, especially cross-fading, and it doesn't handle still images well. I use the PB 2D drawing library for still images. Regarding audio, I use the BASS audio library.

_________________
Mike
www.showcuesystems.com


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye