Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Fri, 15 Aug 2008 10:11:32 -0700 (PDT),    group: microsoft.public.win32.programmer.directx.video        back       


Rendering the output of an exotic decoder   
Dear All,

Output of my decoder filter is somewhat exotic because it:

1) Introduces a very long delay (up to one second or even more). This
means that the very first output sample whose presentation time is,
let's say, 0...40ms in fact becomes ready much, much later when the
current time is, for example, 700ms.

The actual delay is not known beforehand and may change for each run.
However, it is equal for all consequent samples.

2) Samples are produced in packs. That is, after the initial delay
almost instantly several samples (up to 16) become available, then a
long pause follows (which is shorter than the time, necessary to show
all previous samples), and then the next pack is ready at the output
etc.

Needless to say, Video Renderers are not overly happy with my samples
and sometimes the playback is jerky.

Unfortunately, I can't do much with these issues in the decoder itself
so currently I'm working on an additional temporal smoothing filter
(it is based on CTransformFilter and uses COutputQueue internally)
which will be inserted between the decoder and video renderer and
hopefully will be able to improve the situation.

As far as I understand, the first problem - delay - is easy to solve.
Everything I have to do is to measure the delay of the very first
sample and correct start and stop times of each sample by adding this
delay. I do it this way (obviously, actual code includes error
checking and other boring stuff):

class CMyFilter : public CTransformFilter
{
private:
    bool IsFirstFrame;
    REFERENCE_TIME FirstFrameStartTime;
    ...
};

HRESULT CMyFilter::StartStreaming()
{
    IsFirstFrame = true;
    ...
}

HRESULT CMyFilter::Transform(IMediaSample *pIn, IMediaSamle *pOut)
{
    if(IsFirstFrame)
    {
        /* this is the very first sample so we must determine how much
it is delayed */
        CRefTime Rt;
        StreamTime(Rt);
        FirstFrameStartTime = Rt.operator REFERENCE_TIME();
        /* we don't need to measure the delay any more */
        IsFirstFrame = false;
    }
    /* get original sample times */
    REFERENCE_TIME FrameStart, FrameStop;
    pIn->GetTime(&FrameStart, &FrameStop);

    /* correct the times */
    FrameStart += FirstFrameStartTime;
    FrameStop += FirstFrameStopTime;

    pOut->SetTime(&FrameStart, &FrameStart);
    ...
}

This works pretty well. However, being a perfectionis, I believe there
should be a less ugly and more elegant solution. Any ideas?

The second problem - irregular (however, properly timestamped) samples
- seems to be more difficult to solve.

After brief debugging the SampVid SDK sample and investigating the
CBaseRenderer class source I came to the (probably wrong) conclusion
that CBaseRenderer works this way: it waits for the sample's
StartTime, displays the sample and then immediately returns from the
input pin's Receive() method thus completely ignoring its StopTime. In
my case this leads to a real tragedy: the next sample from the pack is
immediately available and arrives to the renderer at the moment when
it is definitely too early to display this new sample. When the whole
pack is processed, then the next sample reaches the renderer after a
long delay.

As the net result, Video Renderer reports terrible jitter. Also, seems
like due to some internal statistics (this part of the code is totally
incomprehensible to me) the renderer decides to drop some of my
samples (however, it never reports any dropped samples) and the
playback becomes jerky. Funny thing, sometimes it works OK and
sometimes not.

I am highly temped to measure time spent in the renderer and sleep
until the current sample's StopTime before going to the next sample...
If anyone could hold me back from this exceptionally funny (and, most
probably, terribly wrong) solution by suggesting something at least a
bit more appropriate, I am going to be extremely grateful.

Thanks in advance for any suggestions!

PS. Perhaps it's proper time to state that neither DirectShow nor
English are my native languages and beg your pardon for any idiocity
found in the text above.
date: Fri, 15 Aug 2008 10:11:32 -0700 (PDT)   author:   Rbr

Re: Rendering the output of an exotic decoder   
On Fri, 15 Aug 2008 10:11:32 -0700 (PDT), Rbr wrote:

> As far as I understand, the first problem - delay - is easy to solve.
> Everything I have to do is to measure the delay of the very first
> sample and correct start and stop times of each sample by adding this
> delay. I do it this way (obviously, actual code includes error
> checking and other boring stuff):

You actually can do it in the decoder if you have access to the decoder
source or if the DirectShow wrapper is yours.  As long as the presentation
times for the sample are set into the future and not in the past they will
be rendered smoothly.  When you have a decoder that generates samples in
blocks you have to make sure that there are at least that many samples
allocated for that pin connection.  If you do those 2 things then it should
just work without the need of an intermediate filter.  I had a similar
issue with an MPEG-4 codec that had a long output delay.

-- 
http://www.chrisnet.net/code.htm
[MS MVP for DirectShow / MediaFoundation]
date: Fri, 15 Aug 2008 17:05:58 -0400   author:   Chris P.

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us