How to fix audio time duration for AVStream driver

Hi all,
I am writing a AVStream base PCI driver. I use avshws and avssamp as my sample.
There is an audio pin in my driver. The audio out format is ADPCM.
I use graphedit to test my driver. If the connection is as in following:
audio pin –> ADPCM decoder –> AVI Mux –> File writer (a.avi)
(ouotput adpcm) (output PCM)
Then the total audio duration time is correct. That is, if I save the non compressed audio format of AVI, it works fine.
My problem is that if I connect as in following:
audio pin –> AVI Mux –> File writer (a.avi)
(ouotput adpcm)
Then the total audio duration time is very short though the audio data sounds OK.
I have set duration of each frame as below:
pHeader->Duration = -liTimeout.QuadPart;
However, it seems no effect.
Does anyone know how to fix audio time duration of AVI file? Should I modify audio frame size or should I modify audio process routine?
Any suggestion would be greatly appreciated!
Thanks a lot!
Gordon

The following are my audio process routine:
NTSTATUS
CAudioCapturePin::
Process(
IN LARGE_INTEGER &liTimeout
)
{

pStreamPointer = KsPinGetLeadingEdgeStreamPointer( m_Pin,
KSSTREAM_POINTER_STATE_LOCKED );

PKSSTREAM_HEADER pHeader = pStreamPointer->StreamHeader;
PBYTE pData = static_cast< PBYTE >( pHeader->Data );
RtlCopyMemory( pData, pAudio, dwAudioLen);
pHeader->DataUsed = dwAudioLen;

// If a clock has been assigned, timestamp the packets with the
// time shown on the clock.
if( m_Clock != NULL )
{
PKS_FRAME_INFO FrameInfo = reinterpret_cast
<pks_frame_info>(pHeader + 1);
LONGLONG llClockTime = m_Clock->GetTime();
llClockTime = m_Clock->GetCorrelatedTime(&llClockTime);
pHeader -> PresentationTime.Numerator =
pHeader -> PresentationTime.Denominator = 1;
pHeader->PresentationTime.Time = llClockTime;
pHeader->Duration = -liTimeout.QuadPart;
pHeader -> OptionsFlags =
KSSTREAM_HEADER_OPTIONSF_TIMEVALID |
KSSTREAM_HEADER_OPTIONSF_DURATIONVALID;
if( pHeader->Size >= sizeof(KSSTREAM_HEADER) + sizeof(KS_FRAME_INFO))
{
FrameInfo->ExtendedHeaderSize = sizeof (KS_FRAME_INFO);
FrameInfo->PictureNumber = m_nAudioFrameNum;
FrameInfo->DropCount = 0;
}
}
else
{
// If there is no clock, don’t time stamp the packets.
pHeader->PresentationTime.Time = 0;
pHeader->Duration = 0;
pHeader->OptionsFlags = 0;
}
KsStreamPointerUnlock( pStreamPointer, TRUE );
}
return STATUS_SUCCESS;
}</pks_frame_info>

xxxxx@sunplusct.com wrote:

I am writing a AVStream base PCI driver. I use avshws and avssamp as my sample.
There is an audio pin in my driver. The audio out format is ADPCM.

Does anyone know how to fix audio time duration of AVI file? Should I modify audio frame size or should I modify audio process routine?
Any suggestion would be greatly appreciated!
Thanks a lot!
Gordon

The following are my audio process routine:
NTSTATUS
CAudioCapturePin::
Process(
IN LARGE_INTEGER &liTimeout
)

Where does liTimeout come from? The DispatchProcess callback doesn’t
get any parameters.

For an uncompressed audio stream, the “duration” of a packet can be
directly computed from the length of the packet. The avssamp sample,
for example, never sets a duration in the audio packets – just a
presentation time.

You will never get a KS_FRAME_INFO for an audio frame. No need to check
that. Also, if there is no clock, I don’t believe you are required to
clear the StreamHeader fields.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

>>Where does liTimeout come from? The DispatchProcess callback doesn’t

>get any parameters.
I set KSPIN_FLAG_DO_NOT_INITIATE_PROCESSING on KSPIN_DESCRIPTOR_EX, and call process routine by my own driver. So, I can set parameter to it.

>For an uncompressed audio stream, the “duration” of a packet can be
>directly computed from the length of the packet.
I modify audio sample rate as 8000 * 3/16
where 3/16 is compression ratio and 8000 is the original sample rate.
Then the AVI file works fine.
Thanks for your help!
Gordon