Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] Re: RE : Re: Nothing good for me... [Was]-> ( Implementingnew device, but video is choppy)



Philippe Gaultier wrote:
Hi,

Thnak you all for your answers.

If understand everything :

1) my SCR isn't correctly set
2) When viewing live TV, I have to get the correct value to set the SCR

So :
There are 4 different Timestamps :
PCR, SCR, PTS, DTS

PCR is the program stream clock
Program Clock Reference. It's the clock value of the transmitting playout center and can/should be used to adjust the local clocks in small steps (or a hard step at initialisation time) and avoid that the local decoder clock drifts away.

SCR is the decoder clock
More generally you can call the MPEG system clock STC. SCR clock reference in MPEG1 system streams and MPEG2 program streams (DVDs and so on).

PTS / DTS are timestamps to present frames to the user
PTS is the presentation time stamp (the time when the data should get exposed, "presented" to the user). DTS is the Decoding time stamp that can be used to minimize buffer usage by optimally scheduling the data to decode. Hardware MPEG decoders have only pretty limited buffer sizes.

All clocks are 33bit counters running at 90kHz, some of them have a 9bit extension (42bits) and are running at 300*90kHz = 27MHz.


If a frame is played when SCR == PTS

If SCR > PTS
{
The decoder skips frames until PTS == SCR In this case, my decoder seems to discard everything except IFRAMEs. }
Else if SCR < PTS
{
The decoder should wait until SCR == PTS In this case it plays the frames according to the speed set in the decoder
}
Else if SCR == PTS
{
In this case, the decoder should play every frame
}
No, whenever you receive a PCR you should adjust the STC smoothly in small steps to avoid jumping images and sound. If I remember correctly the MPEG2 spec allows corrections at a change rate of up to 0.075Hz/second.

Since the PCR is heavily jittered in DVB PCI card environments due to the DMA buffering you need to use an average PCR error value and an average PCR error deviation to estimate a correct required STC-PCR difference that ensures continous data flow without buffer over- or underruns.

For Sound you can either drop or insert dummy samples or you resample the sound buffer at a frequency. All common sound libraries provide you functions doing this, SDL as well as FusionSound (part of the DirectFB project).

[...codelets skipped...]
If this is right, I have to do :
If(isFirstFrame() && (SCR!=PTS))
    SCR = PTS;
That's the hard initialisation. I'd rather write:

/**
 * Situation: you received a TS packet either containing a PCR
 * (PCR_seen is set true) or a PES start (PUSI set) (PTS_seen is
 * set true).
 * initialized and received_a_PCR are boolean values initially set
 * to zero.
 */

if ((initialized || received_a_PCR) && PCR_seen) {
	int64_t PCR_error = diff33bit(PCR, STC);
	adjust_STC_smoothly(PCR_error);
}

if (!received_a_PCR && PCR_seen) {
	received_a_PCR = 1;
	initialized = 1;
	STC = PCR + buffer_safety_margin;
}

if (!initialized && PTS_seen) {
	initialized = 1;
	STC = PTS + buffer_safety_margin;
}

diff33bit() is a function that subtracts two 33bit numbers.
hope that helps to make things clearer - just ask if I can help further,

Holger



--
Info:
To unsubscribe send a mail to ecartis@linuxtv.org with "unsubscribe vdr" as subject.



Home | Main Index | Thread Index