Infognition forum
May 18, 2012, 09:36:37 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Last GraphEditPlus version: 1.4.0   Last Video Enhancer version: 1.9.7
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: DV Splitter: Generated code cannot connect filters  (Read 612 times)
netresults
Newbie
*

Karma: +0/-0
Posts: 7


View Profile
« on: May 08, 2011, 04:41:38 PM »

Hi to all  Cheesy

I'm new to grapheditplus (GEP) and I just started using it trying to create a Firewire A/V splitter.

So in GEP all work fine:
1) Created a "Microsoft DV Camera and VCR"
2) Created the "DV Splitter"
3) Connected Splitter video output to DV Decoder and this last to a Video Renderer
4) Connecte Splitter audio output to speakers.

All work fine in GEP, but when I try to write a program in  C++ using the exported code I obtain a failure in getting Pins. In paricular:
//connect Microsoft DV Camera and VCR and DV Splitter
    hr = pGraph->ConnectDirect(GetPin(pMicrosoftDVCameraandVCR, L"DV A/V Out"), GetPin(pDVSplitter, L"Input"), NULL);
    CHECK_HR(hr, "Can't connect Microsoft DV Camera and VCR and DV Splitter");

fails because the first GetPin() fails with E_POINTER.
Same for the  other (audio) connections with the splitter.

I tried to do some stuff I found in the forum such as:
1) Performing all the audio stuff before video...nothing
2) Sleep some time between operations...nothing
3) Looking for some "wrapper" class but found nothing.

Any more hints?

Thank you very much

Francesco
Logged
Dee Mon
Administrator
Hero Member
*****

Karma: +8/-0
Posts: 530



View Profile WWW
« Reply #1 on: May 09, 2011, 09:43:40 AM »

If GetPin() fails with E_POINTER it means pMicrosoftDVCameraandVCR is null, it wasn't created properly. Can you post whole BuildGraph code?
Logged
netresults
Newbie
*

Karma: +0/-0
Posts: 7


View Profile
« Reply #2 on: May 09, 2011, 11:44:17 AM »

Yes of course  Grin

Debbuging the code I can see that the

 HRESULT hr = pFilter->EnumPins(&pEnum);

in GetPin() is ok (pFilter is NOT null).

But the following

while(pEnum->Next(1, &pPin, 0) == S_OK)

fails immediately.

Here is the generated code... Thank you very much.

//Don't forget to change project settings:
//1. C++: add include path to DirectShow include folder (such as c:\dxsdk\include)
//2. Link: add link path to DirectShow lib folder (such as c:\dxsdk\lib).
//3. Link: add strmiids.lib and quartz.lib

#include "stdafx.h"
#include <DShow.h>
#include <atlbase.h>
#include <initguid.h>
#include <dvdmedia.h>

BOOL hrcheck(HRESULT hr, TCHAR* errtext)
{
    if (hr >= S_OK)
        return FALSE;
    TCHAR szErr[MAX_ERROR_TEXT_LEN];
    DWORD res = AMGetErrorText(hr, szErr, MAX_ERROR_TEXT_LEN);
    if (res)
        printf("Error %x: %s\n%s\n",hr, errtext,szErr);
    else
        printf("Error %x: %s\n", hr, errtext);
    return TRUE;
}

//change this macro to fit your style of error handling
#define CHECK_HR(hr, msg) if (hrcheck(hr, msg)) return hr;

CComPtr<IPin> GetPin(IBaseFilter *pFilter, LPCOLESTR pinname)
{
    CComPtr<IEnumPins>  pEnum;
    CComPtr<IPin>       pPin;

    HRESULT hr = pFilter->EnumPins(&pEnum);
    if (hrcheck(hr, "Can't enumerate pins."))
        return NULL;

    while(pEnum->Next(1, &pPin, 0) == S_OK)
    {
        PIN_INFO pinfo;
        pPin->QueryPinInfo(&pinfo);
        BOOL found = !wcsicmp(pinname, pinfo.achName);
        if (pinfo.pFilter) pinfo.pFilter->Release();
        if (found)
            return pPin;
        pPin.Release();
    }
    printf("Pin not found!\n");
    return NULL; 
}

// {17CCA71B-ECD7-11D0-B908-00A0C9223196}
DEFINE_GUID(CLSID_MicrosoftDVCameraandVCR,
0x17CCA71B, 0xECD7, 0x11D0, 0xB9, 0x08, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96); //ksproxy.ax


// {B87BEB7B-8D29-423F-AE4D-6582C10175AC}
DEFINE_GUID(CLSID_VideoRenderer,
0xB87BEB7B, 0x8D29, 0x423F, 0xAE, 0x4D, 0x65, 0x82, 0xC1, 0x01, 0x75, 0xAC); //quartz.dll




HRESULT BuildGraph(IGraphBuilder *pGraph)
{
    HRESULT hr = S_OK;

    //graph builder
    CComPtr<ICaptureGraphBuilder2> pBuilder;
    hr = pBuilder.CoCreateInstance(CLSID_CaptureGraphBuilder2);
    CHECK_HR(hr, "Can't create Capture Graph Builder");
    hr = pBuilder->SetFiltergraph(pGraph);
    CHECK_HR(hr, "Can't SetFiltergraph");

    //add Microsoft DV Camera and VCR
    CComPtr<IBaseFilter> pMicrosoftDVCameraandVCR;
    hr = pMicrosoftDVCameraandVCR.CoCreateInstance(CLSID_MicrosoftDVCameraandVCR);
    CHECK_HR(hr, "Can't create Microsoft DV Camera and VCR");
    hr = pGraph->AddFilter(pMicrosoftDVCameraandVCR, L"Microsoft DV Camera and VCR");
    CHECK_HR(hr, "Can't add Microsoft DV Camera and VCR to graph");


    //add DV Splitter
    CComPtr<IBaseFilter> pDVSplitter;
    hr = pDVSplitter.CoCreateInstance(CLSID_DVSplitter);
    CHECK_HR(hr, "Can't create DV Splitter");
    hr = pGraph->AddFilter(pDVSplitter, L"DV Splitter");
    CHECK_HR(hr, "Can't add DV Splitter to graph");


    //connect Microsoft DV Camera and VCR and DV Splitter
    hr = pGraph->ConnectDirect(GetPin(pMicrosoftDVCameraandVCR, L"DV A/V Out"), GetPin(pDVSplitter, L"Input"), NULL);
    CHECK_HR(hr, "Can't connect Microsoft DV Camera and VCR and DV Splitter");


    //add DirectSound: Altoparlanti (Realtek High Definition Audio)
    CComPtr<IBaseFilter> pDirectSoundAltoparlantiRealtekHighDefinitionAudio;
    hr = pDirectSoundAltoparlantiRealtekHighDefinitionAudio.CoCreateInstance(CLSID_DSoundRender);
    CHECK_HR(hr, "Can't create DirectSound: Altoparlanti (Realtek High Definition Audio)");
    hr = pGraph->AddFilter(pDirectSoundAltoparlantiRealtekHighDefinitionAudio, L"DirectSound: Altoparlanti (Realtek High Definition Audio)");
    CHECK_HR(hr, "Can't add DirectSound: Altoparlanti (Realtek High Definition Audio) to graph");


    //add DV Video Decoder
    CComPtr<IBaseFilter> pDVVideoDecoder;
    hr = pDVVideoDecoder.CoCreateInstance(CLSID_DVVideoCodec);
    CHECK_HR(hr, "Can't create DV Video Decoder");
    hr = pGraph->AddFilter(pDVVideoDecoder, L"DV Video Decoder");
    CHECK_HR(hr, "Can't add DV Video Decoder to graph");


    //connect DV Splitter and DV Video Decoder
    hr = pGraph->ConnectDirect(GetPin(pDVSplitter, L"DVVidOut0"), GetPin(pDVVideoDecoder, L"XForm In"), NULL);
    CHECK_HR(hr, "Can't connect DV Splitter and DV Video Decoder");


    //connect DV Splitter and DirectSound: Altoparlanti (Realtek High Definition Audio)
    hr = pGraph->ConnectDirect(GetPin(pDVSplitter, L"AudOut00"), GetPin(pDirectSoundAltoparlantiRealtekHighDefinitionAudio, L"Audio Input pin (rendered)"), NULL);
    CHECK_HR(hr, "Can't connect DV Splitter and DirectSound: Altoparlanti (Realtek High Definition Audio)");


    //add Video Renderer
    CComPtr<IBaseFilter> pVideoRenderer;
    hr = pVideoRenderer.CoCreateInstance(CLSID_VideoRenderer);
    CHECK_HR(hr, "Can't create Video Renderer");
    hr = pGraph->AddFilter(pVideoRenderer, L"Video Renderer");
    CHECK_HR(hr, "Can't add Video Renderer to graph");


    //connect DV Video Decoder and Video Renderer
    hr = pGraph->ConnectDirect(GetPin(pDVVideoDecoder, L"XForm Out"), GetPin(pVideoRenderer, L"VMR Input0"), NULL);
    CHECK_HR(hr, "Can't connect DV Video Decoder and Video Renderer");


    return S_OK;
}

//int _tmain(int argc, _TCHAR* argv[]) //use this line in VS2008
int main(int argc, char* argv[])
{
    CoInitialize(NULL);
    CComPtr<IGraphBuilder> graph;
    graph.CoCreateInstance(CLSID_FilterGraph);

    printf("Building graph...\n");
    HRESULT hr = BuildGraph(graph);
    if (hr==S_OK) {
        printf("Running");
        CComQIPtr<IMediaControl, &IID_IMediaControl> mediaControl(graph);
        hr = mediaControl->Run();
        CHECK_HR(hr, "Can't run the graph");
        CComQIPtr<IMediaEvent, &IID_IMediaEvent> mediaEvent(graph);
        BOOL stop = FALSE;
        MSG msg;
        while(!stop)
        {
            long ev=0, p1=0, p2=0;
            Sleep(500);
            printf(".");
            while(PeekMessage(&msg, NULL, 0,0, PM_REMOVE))
                DispatchMessage(&msg);
            while (mediaEvent->GetEvent(&ev, &p1, &p2, 0)==S_OK)
            {
                if (ev == EC_COMPLETE || ev == EC_USERABORT)
                {
                    printf("Done!\n");
                    stop = TRUE;
                }
                else
                if (ev == EC_ERRORABORT)
                {
                    printf("An error occured: HRESULT=%x\n", p1);
                    mediaControl->Stop();
                    stop = TRUE;
                }
                mediaEvent->FreeEventParams(ev, p1, p2);
            }
        }
    }
    CoUninitialize();
    return 0;
}


Logged
Dee Mon
Administrator
Hero Member
*****

Karma: +8/-0
Posts: 530



View Profile WWW
« Reply #3 on: May 09, 2011, 03:10:52 PM »

"Microsoft DV Camera and VCR" should be created differently, not as plain DS filter but by enumerating video capture sources:
http://msdn.microsoft.com/en-us/library/dd407292%28v=vs.85%29.aspx
Logged
netresults
Newbie
*

Karma: +0/-0
Posts: 7


View Profile
« Reply #4 on: May 09, 2011, 06:05:19 PM »

In GEP all works fine and I have not changet any bit of the code generated.
This means that GEP produces wrong C++ code? We purchased it exactly for the code export feature :-(

Can you give me a correct version of the code? I'm new to directshow and probably it will take to me some time to get it working and i'm in a hurry....

Thank you very much

Francesco
Logged
netresults
Newbie
*

Karma: +0/-0
Posts: 7


View Profile
« Reply #5 on: May 09, 2011, 08:03:43 PM »

Solved!
Your MSDN link was sufficient.

Thank you very much.

Francesco
Logged
Dee Mon
Administrator
Hero Member
*****

Karma: +8/-0
Posts: 530



View Profile WWW
« Reply #6 on: May 10, 2011, 11:03:09 AM »

GEP tries to generate correct code, but in some cases can make mistakes about some filters. It will improve in next versions.
Logged
netresults
Newbie
*

Karma: +0/-0
Posts: 7


View Profile
« Reply #7 on: May 10, 2011, 05:00:21 PM »

Yes of course  Smiley

Most of the code was right... GEP was very useful...

Thank you again

Francesco
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!