Hi all, i have writen a custom audio renderer filter which inherits CBaseRenderer,
the renderer works well most time, but causing audio glitch sometimes. the
samples arrived renderer usually early hundreds of ms , but the time wasted
in CBaseRender::WaitForRenderTime -- the sample wait its presentation time. if the sample arrive late exceptionally, this causing the audio glitch.
i once made a test: i put a null in-place filter upstream microsoft's default directsound
renderer, i find that the renderer buffered about 1800ms data, if i pause the
graph, the render remain receiveing samples. so i want to add a queue like COutputQueue in my filter or in custom input
pin, but i have no clues to implemented that, i want to buffer more data
avoiding audio glitch, and alter existing code less.
can you give me some hints? where is the best place to put a queue, in input pin class or in renderer
filter? how to control the filter's state and stream?
thank you in advance , any help would be greatly appreciated -- please excuse me if my writing isn''t professional, technical and courteous. i try to improve my poor english .
On Tue, 2 Dec 2008 05:16:04 -0800, jgma wrote: > i have writen a custom audio renderer filter which inherits CBaseRenderer,
> the renderer works well most time, but causing audio glitch sometimes. the
> samples arrived renderer usually early hundreds of ms , but the time wasted
> in CBaseRender::WaitForRenderTime -- the sample wait its presentation time. > if the sample arrive late exceptionally, this causing the audio glitch.
> i once made a test: i put a null in-place filter upstream microsoft's > default directsound
> renderer, i find that the renderer buffered about 1800ms data, if i pause the
> graph, the render remain receiveing samples. > so i want to add a queue like COutputQueue in my filter or in custom input
> pin, but i have no clues to implemented that, i want to buffer more data
> avoiding audio glitch, and alter existing code less.
> can you give me some hints? > where is the best place to put a queue, in input pin class or in renderer
> filter? > how to control the filter's state and stream?
Contrary to what might seem obvious, audio renderers should not be derived from CBaseRender. You should instead derive from CBaseFilter adding in the appropriate code.
The Microsoft renderers use the audio buffers (DirectSound/waveOut) to buffer about 1 second of audio data. The sample received at the input pin is copied immediately to the audio buffer and released. If there is no room in the audio buffer then the sample is held (blocking) until there is room. There is no need to wait for presentation time as the audio device itself dictates the rate of presentation. In the simplest case you can ignore all time stamps and not have a reference clock if you are playing just audio with no video to sync. If you need video sync then you need to add a reference clock to the filter with the reference clock time derived from the actual audio render position.
"Chris P." wrote: > Contrary to what might seem obvious, audio renderers should not be derived > from CBaseRender. You should instead derive from CBaseFilter adding in the > appropriate code.
are there any disadvantages dereived from CBaseRender? the microsoft doc says :The CBaseRenderer class is a base class for implementing renderer filters. ms-help://MS.MSSDK.1033/MS.WinSDK.1033/directshow/htm/cbaserendererclass.ht m what is CBaseRender used for?
> The Microsoft renderers use the audio buffers (DirectSound/waveOut) to > buffer about 1 second of audio data. The sample received at the input pin > is copied immediately to the audio buffer and released.
if i create a 1 second buffer(DirectSoundBuffer8), run the graph, the first sample arrived at audio render early 300 ms, put it immediately in the buffer, when to play the buffer? ignore the sample's time stampe?
>If there is no > room in the audio buffer then the sample is held (blocking) until there is > room. There is no need to wait for presentation time as the audio device > itself dictates the rate of presentation. In the simplest case you can > ignore all time stamps and not have a reference clock if you are playing > just audio with no video to sync. If you need video sync then you need to > add a reference clock to the filter with the reference clock time derived > from the actual audio render position.
yes i need video sync, i have add a reference clock to the costom renderer, when the buffer is
playing , use buffer position to retrieve time, otherwise, use system clock increase the time.
i once made some tests in graph, put a null in place filter upstream microst's diectsound renderer,
alter sample's time stamp , the render works exceptionly, if " The sample received at the input pin is copied immediately to the audio buffer and released. "
the render should work the same as not altering timestamp. -- please excuse me if my writing isn''t professional, technical and courteous. i try to improve my poor english .
On Tue, 2 Dec 2008 17:27:01 -0800, jgma wrote: > are there any disadvantages dereived from CBaseRender? > the microsoft doc says :The CBaseRenderer class is a base class for > implementing renderer filters. > ms-help://MS.MSSDK.1033/MS.WinSDK.1033/directshow/htm/cbaserendererclass.ht m > what is CBaseRender used for?
CBaseRenderer was primarily intended for video rendering. It contains presentation scheduling code that is completely irrelevant for audio. It actually has the potential for deadlock when used with certain players.
> if i create a 1 second buffer(DirectSoundBuffer8), run the graph, the first > sample arrived at > audio render early 300 ms, put it immediately in the buffer, when to play > the buffer? > ignore the sample's time stampe?
You don't have to ignore the time stamps, but in the simplest cases the time stamps will always be linear and derived from the samplerate/sample count. If you decide to use time stamps then you have to decide what exactly do these time stamps mean to you? Audio samples are almost never sent with gaps, if there are gaps you would be responsible for filling in the gap with something (silence/noise etc). You should stay in the paused state until you have enough data buffered to maintain smooth playback, then allow the transition to running.
> yes i need video sync, i have add a reference clock to the costom renderer, > when the buffer is
> playing , use buffer position to retrieve time, otherwise, use system clock > increase the time.
> i once made some tests in graph, put a null in place filter upstream > microst's diectsound renderer,
> alter sample's time stamp , the render works exceptionly, if " > The sample received at the input pin is copied immediately to the audio > buffer and released. "
> the render should work the same as not altering timestamp.
I don't understand what you are trying to say here.
>CBaseRenderer was primarily intended for video rendering. It contains >presentation scheduling code that is completely irrelevant for audio. It >actually has the potential for deadlock when used with certain players.
public blog site? do you write technical artical blog?
>Audio samples are almost never sent with gaps, if there are gaps you would >be responsible for filling in the gap with something (silence/noise etc). >You should stay in the paused state until you have enough data buffered to >maintain smooth playback, then allow the transition to running.
i once made a test, the scenario is following:
in my graph,put a null in-place filter upstream microsoft default directsound
renderer, implement CTransInPlaceFilter::Transform as following:
> there are not enough docs for implementing a audio render, so i have to
> search the internet again and again, and ask many questions in forums. by now
> , the custom audio render implemented by me works well, the only fault is
> occuring glitch sometimes. when i encounter a new problem, it's difficult for
> me to resolve it, there are no directions .
> why does mirsoft directshow group not write some docs for implementing a > audio render or
> write a base class for audio render,there are base class and samples for
> video renderer.
A base class for audio renderers wouldn't really be needed, it would be a fairly empty class. If you are writing an audio renderer then it is usually going to be a fair bit different from the standard Microsoft implementation. I think more useful would be if Microsoft published the source code for the DirectSound and waveOut renderers so that people can how to handle timing, syncing etc.