[matroska-devel] Matroska DS filter

Christophe PARIS christophe.paris at free.fr
Mon Apr 14 00:32:11 CEST 2003


Hi myFUN,

Here is what we discovered today working on the DSF :

// ---------------------------

In CKaxDemuxFilter::CStreamer::ThreadProc() too much data were copied to 
the sample buffer, so there was garbage after mp3 frames and it's why 
audio file only didn't played

Original code :
memcpy(pSampData, pBlock->GetBuffer(n).Buffer(), 
pBlock->GetBuffer(n).Size());
pSample->SetActualDataLength(pBlock->GetSize());

New code :
memcpy(pSampData, pBlock->GetBuffer(n).Buffer(), 
pBlock->GetBuffer(n).Size());
pSample->SetActualDataLength(pBlock->GetBuffer(n).Size()); // 
pBlock->GetSize() include the block header in the size

// ---------------------------

There was a problem with mka file created by mpa2mka or matroskadub, one 
of the both was wrong !!
The track index was set to 1 in mpa2mka and to 0 in matroskadub.
Changing this to 0 is more compatible with the DSF filter.
So we changed mpa2mka.

// ---------------------------

In CKaxDemuxFilter::DeliverSample we discovered that it's better to not 
set timestamps than to set wrong timestamps.
So here is some code that allow to play video + audio files, it's far 
from perfect but it show that we really have a problem with timestamps, 
and at least we can see video playing (this is not the real solution) :

HRESULT CKaxDemuxFilter::DeliverSample(int nTrack, IMediaSample 
*pSample, uint32 timecode, int nSample) {
    CAutoLock        StreamLock(&m_StreamLock);
    REFERENCE_TIME    tStart, tEnd;
    uint32            tTrack = nTrack;

    POSITION pos = m_OutPins.GetHeadPosition();
    CKaxOutPin *pPin;
    while (nTrack--) pPin = m_OutPins.GetNext(pos);
    if (pPin == NULL) return E_FAIL;
    if (!pPin->IsConnected()) return E_FAIL;

    /* code removed here */

    // set the stream- and mediatimes
    tTrack = timecode - pPin->GetTrackTime();
    pPin->SetTrackTime(timecode);

    // 1. stream time
    pPin->GetStrTime(&tStart);
    tStart += tTrack * m_TimeScale;
    pPin->SetStrTime(&tStart);
    tStart += nSample << 1;
    if (tTrack == 2) tStart = 0;
    tEnd = tStart;
    pSample->SetTime(&tStart, &tEnd);
  
    // 2. media time
    pPin->GetMediaTime(&tStart);
    tStart += tTrack * m_TimeScale;
    pPin->SetMediaTime(&tStart);
    tStart += nSample << 1;
    if (tTrack == 2) tStart = 0;
    tEnd = tStart;
    pSample->SetMediaTime(&tStart, &tEnd);

    return pPin->Deliver(pSample);
}

Audio timestamps are set to 0, cause it's the audio renderer that is 
used as a clock, so timestamps are not mandatory for it, playing at a 
defined frequency is a good way for him to calculate the timestamps he need.
I think that this is only working if video and audio are originaly synched.
Btw this is only a hack, DS seems to prefer to have no timestamps at all 
that wrong timestamps ;-)

// ---------------------------

So what we get ?
hmm, audio only file (with mp3) are playing well until you reach the end.
audio+video is still jerky but you can nearly watch the movie ;-)

Best regards Toff

http://www.matroska.org



More information about the Matroska-devel mailing list