Setting of WMP buffer size or buffer length in C# code

Setting of WMP buffer size or buffer length in C# code

Post by QW5kaSBIZX » Tue, 03 Oct 2006 11:28:01


Hi,

I'm writing a C# application where I'm using the Window Media Player ActiveX
plugin to play back a media stream I receive via HTTP. Everything is working
nicely except that the WMP seems to buffer arbitrarily long and too long for
my taste. For some streams it buffers up to 40 seconds before it starts
playing.

I was trying to find a way to reduce the length that WMP would buffer before
it starts playing a stream. I could not find any method calls or properties
in the API that would let me change the buffer size or time. In the WMP GUI,
there are options to modify the buffer and therefore I assumed that this
should be available programmatically as well.

Is there a way to modify the buffer in any way and if so, how can I do that?
Where is that documented?

Any help would be greatly appreciated as the buffer length currently is just
not feasible.

Thanks.
Andi
 
 
 

Setting of WMP buffer size or buffer length in C# code

Post by Alessandro » Tue, 03 Oct 2006 17:51:54


It is not documented.

Internally WMP builds a DirectShow playback graph and
buffering is performed by the source or parser filter.

Since you are referring to the beffering settings in WMP's
UI, I suppose you are trying to play a WM stream read via
HTTP (MMS-over-HTTP or plain HTTP?).

The old WMP6.4 provided a way to get a reference to its
internal graph and used the WMSourceFilter, which supports
IAMNetShowConfig. Since WMP7.x+, there is no way to get to
the graph (but for IWMPGraphCreation in WMP10, but I don't
think it works with WM streams) and the source filter used
with WM streams is totally undocumented.

If the stream is not a WM stream, then the stock URLReader
is used (unless you have some third-party HTTP reader
installed that overrode the default association), which may
even download the whole file before playing (depending on
the parser filter).

Depending on your requirements, you can try to
programmatically change the buffering settings via WMP's own
UI (in a hidden fashion, see
http://www.yqcomputer.com/
for a sample that uses a filter's property page instead of
WMP's config dialog) or you can drop WMP and go to the
source, that is DirectShow.

--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// a dot angeli at psynet dot net
// http://www.yqcomputer.com/

 
 
 

Setting of WMP buffer size or buffer length in C# code

Post by QW5kaSBIZX » Wed, 04 Oct 2006 12:41:02

Thanks a lot for your detailed reply. I really appreciate your time and input.

Basically I want to stream an ASF stream over HTTP. The ASF stream contains
some MPEG4 audio/video stream (e.g. from a *** ). I have a 'server'
component that produces the stream, then streams it over a custom p2p
protocol and on the receiver side where I have the WMP, I setup an HTTP
listener that will receive the packets from the custom p2p protocol and
provide them in the form of an HTTP stream to WMP.

All this is working fine except for the buffering issue. Based on your info,
I think I'll have to start looking into DirectShow (was planning on doing
that anyway at some point) as the other option doesn't seem like the nicest
one.

I've programmed everything in C# 2.0 so far. I have no experience with
DirectX or DirectShow at all. Also whenever I tried to find documenation on
DirectShow I couldn't dig up much. Is DirectShow still part of DirectX or did
that move into a different package?

Could you please direct me to the right places? Is there an SDK I can
download? Will I even be able to do streaming through DirectShow? Does it
support something like that?

Any other input you could give me on that are would be great.

Thanks very much.
- Andi
 
 
 

Setting of WMP buffer size or buffer length in C# code

Post by Alessandro » Wed, 04 Oct 2006 20:51:58


Are you using the WMWriter to set up your HTTPd (which would
be implement MMS-over-HTTP) or just an HTTP listener (which
would implement plain HTTP)?


DirectShow is not included in the Platform/Windows SDK.


DirectShow is a pluggable framework, so you can add your own
components to it to achieve any goal you have, but it may be
hard. However, writing DS filters in C# is not easy and may
not be feasible performance-wise.

Since you wrote your P2P receiver to receive the data, you
could just re-package it as a DirectShow push source filter
and register you under a custom protocol, so that you would
be able to directly open a custom URL in WMP, without the
P2P-to-HTTP proxy or any ASF reader/parser problem.

Writing such a filter really takes little effort if you
write it in C++ and use the CSource base class in the SDK.
CSource and CSourceStream are well documented in the SDK
docs both off-line and on-line:
http://www.yqcomputer.com/
And the PushSource sample in SDK shows how they are used.

Of course, it is only easy in C++. In C#, you will have to
write the filter from scratch instead of just using the base
class and you will have to write a COM InterOp wrapper or
use LGS's DirectShowNet (on sf.net).

--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// a dot angeli at psynet dot net
// http://www.yqcomputer.com/
 
 
 

Setting of WMP buffer size or buffer length in C# code

Post by The March » Wed, 04 Oct 2006 22:17:40


Should be: ... is *now* included... :)

--
Please read this before replying:
1. Dshow & posting help: http://www.yqcomputer.com/
2. Trim & respond inline (please don't top post or snip everything)
3. Benefit others: follow up if you are helped or you found a solution
 
 
 

Setting of WMP buffer size or buffer length in C# code

Post by Alessandro » Wed, 04 Oct 2006 23:11:15


You're right, thanks :-)

--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// a dot angeli at psynet dot net
// http://www.yqcomputer.com/
 
 
 

Setting of WMP buffer size or buffer length in C# code

Post by QW5kaSBIZX » Thu, 05 Oct 2006 13:35:01

No I'm not using WMWriter. I'm just using a simple .NET TcpListener that
understands WMP's HTTP request and serves it the HTTP repsonse and then the
stream.

I think I'm either gonna use one of the DirectShow C# .Net libraries you
mentioned and I found ( http://www.yqcomputer.com/ )
or I'm gonna implement it in C++.

Thanks a lot for all you help and tips.
 
 
 

Setting of WMP buffer size or buffer length in C# code

Post by QW5kaSBIZX » Mon, 30 Oct 2006 08:09:01

A few weeks ago, I actually found a way to set the buffer size in the WMP
(ActiveX) object in C#.

The AxWMPLib.AxWindowsMediaPlayer has a property called 'network' and
network has a few streaming and buffering related properties like
bufferingTime, bufferingProgress and dowloadProgress.
So there are ways to modify that but I'm gonna use DirectShow anyways.