Page 1 of 1
Help reqd with Media Foundation interfaces
Posted: Tue May 27, 2014 10:10 am
by ozzie
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: Select all
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: Select all
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?
Re: Help reqd with Media Foundation interfaces
Posted: Tue May 27, 2014 4:12 pm
by Thunder93
Code: Select all
ppMS.IMFMediaSession
ppMS\Shutdown()
Re: Help reqd with Media Foundation interfaces
Posted: Wed May 28, 2014 8:15 am
by ozzie
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: Select all
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: Select all
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?
Re: Help reqd with Media Foundation interfaces
Posted: Wed May 28, 2014 9:22 am
by Danilo
Change
to:
Code: Select all
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
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.
Re: Help reqd with Media Foundation interfaces
Posted: Wed May 28, 2014 11:33 pm
by ozzie
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.
Re: Help reqd with Media Foundation interfaces
Posted: Wed May 16, 2018 7:30 pm
by robertfern
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
Re: Help reqd with Media Foundation interfaces
Posted: Thu May 17, 2018 6:01 am
by ozzie
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.