locked
custom directshow filter, not sure if I use FillBuffer in the correct way RRS feed

  • Question

  • I'm trying to build a Source Filter for Images. I based the filter on the PushSource sample provided with the sdk.

    The raw pixel values are stored in an Image class. To get a pixel value you can just call:
    Image<uint8> img;
    // returns the value for xPos,yPos in the image
    // Band specifies the R,G or B value of the pixel
    int iValue = img(xPos,yPos,Band);
    At the moment I'm not sure if I build a correct sample, the code I'm using is:
    HRESULT CMocaImagesPin::FillBuffer(IMediaSample *pSample)
    {
        BYTE *pData;
        long cbData;
    
        CheckPointer(pSample, E_POINTER);
    
        CAutoLock cAutoLockShared(&m_cSharedState);
    
        // Access the sample's data buffer
        pSample->GetPointer(&pData);
        cbData = pSample->GetSize();
    
        // Check that we're still using video
        ASSERT(m_mt.formattype == FORMAT_VideoInfo);
    
        VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)m_mt.pbFormat;
        
    	long count = 0;
    	Image<uint8> img = *pImage;
    	ImageSize size = img.getSize(); 
    		for(int x=0; x<=[DIM_X]; x++) {
    			for(int y=size[DIM_Y]; y>=0; y--) {
    				for(int z=2; z>=0; z--) {
    					pData[count]= img(x,y,z);
    					count++;
    				}
    			}
    		}
    
        // Set the timestamps that will govern playback frame rate.
        // If this file is getting written out as an AVI,
        // then you'll also need to configure the AVI Mux filter to 
        // set the Average Time Per Frame for the AVI Header.
        // The current time is the sample's start
        REFERENCE_TIME rtStart = m_iFrameNumber * m_rtFrameLength;
        REFERENCE_TIME rtStop  = rtStart + m_rtFrameLength;
    
        pSample->SetTime(&rtStart, &rtStop);
        m_iFrameNumber++;
    
        // Set TRUE on every sample for uncompressed frames
        pSample->SetSyncPoint(TRUE);
    
        return S_OK;
    }
    The media subtype should be RGB_24 and I don't known if i have to care about the stride at this point.

    Maybe someone could have a look at this code.

    Tuesday, September 29, 2009 9:20 AM

Answers

  • Looks OK, except likely to be very, very slow.... (accessing bytes one by one by index)
    Michel Roujansky, http://www.roujansky.com
    • Marked as answer by JimHTP Tuesday, September 29, 2009 8:56 PM
    Tuesday, September 29, 2009 5:53 PM

All replies

  • Looks OK, except likely to be very, very slow.... (accessing bytes one by one by index)
    Michel Roujansky, http://www.roujansky.com
    • Marked as answer by JimHTP Tuesday, September 29, 2009 8:56 PM
    Tuesday, September 29, 2009 5:53 PM
  • first of all thank you for looking at it.
    But I have to use the image class, so i'll have to accept that it will go slow.

    But now I'm faceing another Problem.
    I successfully registered my filter.
    But if I try to call CoCreateInstance with the CLSID of my filter I'm getting an error that the CLSID is unkown.
    error C2065: 'CLSID_MocaImages': nichtdeklarierter Bezeichner
    then i tried to add the filter in graphedt. And there it works perfect.
    so what am I doing wrong?
    Tuesday, September 29, 2009 9:07 PM
  • I'm translating that as "Undeclared identifier".  That would mean that the CLSID of your filter isn't properly defined in your application.

    If you are using the old DEFINE_GUID() macro or similar then you must #include <initguid.h> to define an instance of the guid.

    The better solution is to use something like the following to prevent errors and conflicts.

    class __declspec(uuid("01010101-dadc-41d1-a450-5c8c2a933800")) idMocaImages;
    #define CLSID_MocaImages __uuidof(idMocaImages)
    


    www.chrisnet.net
    • Proposed as answer by Chris P_ Wednesday, September 30, 2009 2:53 PM
    Tuesday, September 29, 2009 10:29 PM
  • Thank you Chris, works perfectly.

    For the next time i'll switch VS2008 to the english language.

    But its the first time that I read about the old makro because I'm very new to DirectShow.
    Wednesday, September 30, 2009 6:08 AM