News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Using DirectShow

Started by donkey, January 17, 2012, 05:26:34 AM

Previous topic - Next topic

donkey

In another thread I noticed that many people are still using the MCI interface to play media, the MCI has been replaced by the DirectShow group of interfaces. DirectShow offers a rich set of functions using COM interfaces that allow almost complete control over a media stream. I have attached a test bed that shows how to play media files using DirectShow, it should allow you to play any movie or audio file. I have included several wrapper calls that allow you to expand on the player. This is only a test bed so most of the functionality has not been implemented, it will only load and play a file and allow you to set the position and volume.

As usual you will require my header files in order to build the project, since the executable is only 5 KB I have left it in the attachment.

To Do:
- Full set of playback controls
- Window resizing
- Best video size
- Aspect ratios
- Display audio file information when an audio file is played
- Lots of other things

I've been using this as my test movie

http://www.bigbuckbunny.org/

Have fun with it...

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

donkey

Here's a quick hack to give a better response from the volume control, it spreads the change in volume more evenly over the control. Replace the VolumeBarSubClass function with the following (I've updated the zip above)

VolumeBarSubClass FRAME hwnd,uMsg, wParam, lParam, uIdSubclass, dwRefData
LOCAL pt:POINT
LOCAL rct:RECT
LOCAL newvol:D

// Set the volume
// Based on 10*log2(x)

cmp D[uMsg],WM_LBUTTONDOWN
jne >>.DEFPROC
// Calculate the position inside the volume bar
// First we need a hit test
invoke GetCursorPos,offset pt
invoke ScreenToClient,[hwnd],offset pt
invoke GetClientRect,[hwnd],offset rct
// Calculate the postion
mov eax,[pt.x]
mov ecx,10000
mul ecx
xor edx,edx
div D[rct.right]

// EAX contains the hit test result, the value is between 0 and 10000 (the range of the progress bar)
push eax

// A quick hack to give us a logarithmic scale
// Calculate the inverse volume
mov [newvol],eax
fld Q[Multiplier]
fild D[newvol]
FYL2X
fistp D[newvol]

// invert the result
mov edx,10000
sub [newvol],edx

// Set the volume
invoke SetVolume,[newvol]
// Reposition the volume bar
pop eax
invoke SendMessage,[hwnd],PBM_SETPOS,eax,0

.DEFPROC
invoke DefSubclassProc, [hwnd], [uMsg], [wParam], [lParam]
ret

Multiplier: DOUBLE 752.57500515316827920992790535456
endf
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

jj2007

Quote from: donkey on January 17, 2012, 05:26:34 AM
In another thread I noticed that many people are still using the MCI interface to play media, the MCI has been replaced by the DirectShow group of interfaces. DirectShow offers a rich set of functions using COM interfaces...

Edgar,
My quick impression is that it works fine, and that COM is not as scary as many people think... if I had more time... ::)

:U

oex

I had a quick look but I could not see how to get access to the wave data.... I do not like COM, i am not very good at it.... What would I use to access the converted wav data? ie mp3->wav.... What with data loss, little benefit to compressing wave data on todays systems andthe complexities of COM I have avoided this changeover to date.... I appreciate there are some benefits, notably importing data from other formats I think but this all just seems too hard (not necessarily to do but to find out how to do :bg)....

Am I missing the obvious or is this pretty complex? Interfaces I think should make things easier but generally they just tend to be badly documented formats for complex custom written programs rather than simplified models.... COM seems a simple enough object interface so where is the ASM generator for the COM interface? Maybe I misunderstand it
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

donkey

Thanks Jochen

Yeah, I am beginning to find COM is sometimes easier to use than the flat API, DirectShow is an example of this, the MCI stuff is a rats nest of function calls and strings etc... that require the search engine from hell just to get even the simplest thing done. With COM you only have to remember the name of a couple of interfaces and the rest is a cakewalk.

Hi oex,

The SDK has a sample called WavDest that is supposed to allow you to access the WAV data from an audio stream, I haven't played with it (or even looked at it much) but MSDN says that's what its for.

Not sure what you mean by "ASM generator for the COM interface"

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

oex

Quote from: donkey on January 17, 2012, 03:09:11 PM
Not sure what you mean by "ASM generator for the COM interface"

Simply if it's all OO I'm surprised there are no automation tools for generating the ASM code.... I think it was Japeth who created a tool which read the COM interfaces from the registry or something.... I would think that it was quite easy to create a tool around this....

Unfortunately I think japeths tool no longer exists.... I have not yet got far enough with COM to do this tool.

(and thanks I'll check the sample  :U)
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

donkey

Biterider wrote ObjAsm32 which gives you a full set of tools for OOP programming using MASM. It is available here:

32 bit ObjAsm

It was written with the help of some of the best ML programmers around, NaN, Homer, Obvian and UKV.

However, for simply calling an existing interface there is rarely anything quite so complex as needing OOP tools. Even writing a COM server is also fairly easy except if you get into custom marshalling etc...

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

oex

OK I know of ObjASM (though dont use it).... I was considering this when posting.... I'll dig more into COM, I dont know enough to further my question....
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

satpro

Well, I like it.  Works well, and works FAST.  Not to mention small enough to get lost in a molar.  This is just what I (and suspect others) need to get a better grip on the DirectX/COM programming.  I've translated enough Russian websites (with old DX code, but code nonetheless) to last a lifetime--this stuff is hard to find here.  Next project for me is to tear this apart and learn some more.  Thank you.

As Ebert would say,  " :U :U"

donkey

Microsoft recommends the use of the new windowless VMR interfaces for video playback, the overall quality is much better. Its a bit more complicated to set up since for backward compatibility reasons they do not expose the IVMRWindowlessControl directly from IGraphBuilder. So you have to add the filter and set it up before using it to render a video file. Attached is the example above modified to use windowless playback.

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

donkey

By the way, if you want to force the aspect ratio (which I don't do in the example) you have to tell the filter to do so:

CoInvoke(pivnw,IVMRWindowlessControl.SetAspectRatioMode,VMR_ARMODE_LETTER_BOX)

Once this is set the filter will show a border above and below and maintain the aspect ratio of the video.

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable