I need to create a Transform filter and I need that the sample size that is delivered in the following method to be a power of 2.
HRESULT CMyFilter::Transform(IMediaSample *pIn, IMediaSample *pOut){
BYTE *pSampleBuffer; int iSize = pIn->GetActualDataLength(); // the size to be a power of 2pIn->GetPointer(&pSampleBuffer);
BYTE *pSampleBufferO;
int iSizeO = pOut->GetActualDataLength();pOut->GetPointer(&pSampleBufferO);
...
I need that the data length on the InputPin contained in the variable iSize to be a power of 2. For the Output Pin I have no problem setting it to a length to be a multiple of a power of 2 by redefining the method "DecideBufferSize".
When I debug my filter, the value contained in iSize is about a size corresponding 250ms at the sampling rate.
If you have any suggestion, I would appreciate.
Cheers
sva

How to change input sample size in Direct Show ?
den2005
The way DirectShow filter work is by agreeing on a format
Exemple:
The Filter One can send RGB8, RGB16 and RGB32
The Second Filter can Accept RGB32 only
When the filter One try to connect it ask
''can you do RGB8''
the second filter return False
So the Filter one ask
''can you do RGB16''
same answer
When the Filter One ask
''Can you accept RGB32''
the Second Filter answer Yes
Since they both agree Filter one provide RGB32 and Filter 2 accept RGB32
This process is done by enumeration one filter call the other filter function
and the function look if it is a format it can deal with
CheckInputPin
You should check this process in the DirectShow help
Basicaly you don't change the format the Filter one send you
Because you cannot acces Filter one function...
The only way you can control the process is to accept only
the format you required and refuse the format if you can't process it
So in the CheckInputPin you check the format the Previous filter try to send you
If it's not a power of 2 you refuse the connection...basicaly the filter will not connect to your filter input pin
scepticus
Normally in a Synchronised filter stream the data Sample size would vary
Depending on how fast the filter work on the data to process
The next sample can big small or big...
This synchronised flow will use Time Stamp, a Start and an End time
(To keep the speed the Sample size will vary...)
What you seems to want to do is a Asyncro flow of data
Basically you want a Packet of 4096 each time
Imagine for a reason that your treatment of a 4096 vary in time
If you allways receive a fix size packet you cannot by synchronised...
Maybe it will take 1.5 sec for one packet and 1.7 sec for another
even if they have a fix size of 4096
So you will have a flow that will not be in sync with the clock...
Since the sound cannot skip a beat, normally the clock is on the Sound filter
Your Fix sized filter will not flow in real time...
Here is a way to force the filter to run without synchro but with fix packet:
(Your IN pin will request the OUT pin of the previous filter to send a fix packet)
In an IAsyncReader connection, allocator negotiation works as follows:
The input pin calls IAsyncReader::RequestAllocator on the output pin. The input pin specifies its buffer requirements and, optionally, provides an allocator.
The output pin selects an allocator. It can use the one provided by the input pin, if any, or create its own.
The output pin returns the allocator as an outgoing parameter in the RequestAllocator method. The input pin should check the allocator properties.
The input pin is responsible for committing and decommitting the allocator.
At any time during the allocator negoriation process, either pin can fail the connection.
If the output pin uses the input pin's allocator, it can use that allocator only to deliver samples to that input pin. The owning filter must not use the allocator to deliver samples to other pins.
http://msdn.microsoft.com/library/default.asp url=/library/en-us/directshow/htm/negotiatingmediatypes.asp
http://msdn.microsoft.com/library/default.asp url=/library/en-us/directshow/htm/dataflowinthefiltergraph.asp
You never really control the IN format unless you want to call the OUT pin
of the filter that is sending the data to your filter...and this IAsync interface do this...let's hope the Previous filter you use will be able to provide the fix packet you want
Normally you should not set the IN sample size if you want to be in sync
with a video or the real time output...
GlennZarb
I did not find any "CheckInputPin" so I guess you thought "CheckInputType" method.
That's right that you can decide of your format in that method but I don't think you can select the input buffer packet size.
Exemple :
HRESULT CSIGtoneFXRestor2::CheckInputType(
const CMediaType *pmt){CheckPointer(pmt,E_POINTER);
WAVEFORMATEX *pwfx = (WAVEFORMATEX *) pmt->pbFormat;
if (pmt->majortype != MEDIATYPE_Audio) { return VFW_E_TYPE_NOT_ACCEPTED;}
// Reject invalid format blocks if (pmt->formattype != FORMAT_WaveFormatEx) return VFW_E_TYPE_NOT_ACCEPTED; // Reject compressed audio // if (pwfx->wFormatTag != WAVE_FORMAT_PCM) { return VFW_E_TYPE_NOT_ACCEPTED;}
I did not find how I can select the input buffer size. The "lSampleSize" attribut of the CMediaType class contains values of 1 or 4. I want that the return value of the call}
pIn->GetActualDataLength();
in the Transform method is for example equal to 4096.Where did I go wrong