Asf profile configurations fails.-Collection of common programming errors


  • msdn Hello,I am trying to set profile on asfwriter , my code below. it fails what is wrong?

    IWMProfile *currentProfile;  
    
            hr = profileManager->LoadProfileByID(WMProfile_V80_28856VideoMBR, &currentProfile);
            if (FAILED(hr))
            {
                    Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid !  hr=0x%x"), hr);
                    return hr;
            }
            // Apply the configuration  
    
    
            hr = mpWriterConfig->ConfigureFilterUsingProfile(currentProfile);  
            if (FAILED(hr))  // Fails.
            {
                    Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid !  hr=0x%x"), hr);
                    return hr;
            }

  • msdn1

    • did you check this “You must add the WM ASF Writer filter to the filter graph before configuring the filter, and configure the filter before connecting it to any other filters.”
    • you still have uninitialized fields, just break with the debugger on SetMediaType and check them in Watch debug window

  • msdn2

    it is E_FAIL.


  • msdn3 If you don’t find the reason why this exactly profile does not load, you might wish to try using version 9 profiles. You are obviously loading profile version 8 here and I am not sure it you explicitly initializing profile manager to certain version and if you at all added filter to your graph prior to your attempt to set it up. For version WM Format version 9 you don’t have predefined profiles accessible by ID. Instead you can generate a profile using WMF SDK utility (Profile Editor?) and load it as XML into your IWMProfile object, then use it to configure WM ASF Writer. The problem may also be that the profile you are trying to load is in some way incompatible with WM ASF Writer. Also make sure you are OK with this:

    It is recommended to create a custom profile that uses the Windows Media 9 Series codecs, and configure the WM ASF Writer with the custom profile, as described in Configuring Profiles and Other ASF File Properties . You must add the WM ASF Writer filter to the filter graph before configuring the filter, and configure the filter before connecting it to any other filters.

    http://alax.info/blog/tag/directshow


  • msdn4

    Possibly you are rightt. How do I load prx file, generated by WMGenProfile into my IWMProfile  object? Do you have a code sample for this? it is realy helps. I googled but found nothing the way to do it.


  • msdn6

    I try to capture and send webcam view, Can’t I load profile directly from code, for only test purposes. i mean,creating prx content from code and loadprofile, i see some code snippets around but i can’t figure it out.


  • msdn8 Hello Roman, With the your help and msdn , I came up with a code sequence below, i am still having E_FAIL from ConfigureFilterUsingProfile.

     IWMProfileManager *profileManager;  
            IWMStreamConfig * pWMStreamConfig; 
    
            hr = WMCreateProfileManager(&profileManager);  
            if (FAILED(hr))
            {
                    Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid !  hr=0x%x"), hr);
                    return hr;
            }
    
            IWMProfile *pProfile;  
            
            hr = profileManager->CreateEmptyProfile(WMT_VER_9_0,  &pProfile);
            if (FAILED(hr))
            {
                    Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid !  hr=0x%x"), hr);
                    return hr;
            }
            hr = pProfile->CreateNewStream(WMMEDIATYPE_Video, &pWMStreamConfig);
            if (FAILED(hr))
            {
                    Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid !  hr=0x%x"), hr);
                    return hr;
            }
            IWMVideoMediaProps *pProps;
            hr = pWMStreamConfig->QueryInterface(IID_IWMVideoMediaProps,(void**)&pProps);
            if (FAILED(hr))
            {
                    Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid !  hr=0x%x"), hr);
                    return hr;
            }
            WM_MEDIA_TYPE wmt;
            wmt.subtype = WMMEDIASUBTYPE_WMV3;
            pProps->SetMediaType(&wmt);
            if (FAILED(hr))
            {
                    Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid !  hr=0x%x"), hr);
                    return hr;
            }
    
            hr = mpWriterConfig->ConfigureFilterUsingProfile(pProfile); // Fails 
            if (FAILED(hr))
            {
                    Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid !  hr=0x%x"), hr);
                    return hr;
            }

  • msdn9

    Hello Roman, With the your help and msdn , I came up with a code sequence below, i am still having E_FAIL from ConfigureFilterUsingProfile.

       WM_MEDIA_TYPE wmt; wmt.subtype = WMMEDIASUBTYPE_WMV3; pProps->SetMediaType(&wmt);
    

    Well I doubt this is going to work, you need to fully initialize this. It has a number of fields and you are coming up with a stack junk and one member only initialized (subtype).


  • msdn10 Hello Roman, according to your answer, i reviewed and  initialized fields like in code snippet. But I can’t imagine how some fields should be initialized. I have commented them in code. Still having the error. I have borrowed some values from Profile Generator ( from SDK) with Windows Media Codec 9 Selected.

       pProps->SetQuality(100);
    
            WMVIDEOINFOHEADER vi;
            vi.dwBitRate =100000;
            //vi.rcSource =  what should it to be,  it comes from webcam?   
            //vi.rcTarget  ?
            vi.AvgTimePerFrame = 30;
            //vi.bmiHeader  ?  where to find which field what to be
            
            WM_MEDIA_TYPE wmt;
            
            wmt.subtype = WMMEDIASUBTYPE_WMV3;
            wmt.majortype = WMMEDIATYPE_Video;
            wmt.bFixedSizeSamples = false;
            wmt.bTemporalCompression = true;
            wmt.lSampleSize = 100; // no need actaully when  bFixedSizeSamples is false from msdn
            wmt.pbFormat = (BYTE *)&vi;
            wmt.formattype = WMFORMAT_VideoInfo;
            wmt.cbFormat = sizeof(vi);
            wmt.pUnk = NULL;

  • msdn12 No chance , i am stil having same error at the same point. My new configuration is :

       pProps->SetQuality(100);
    
             VIDEOINFOHEADER VideoInfoHeader;
            VideoInfoHeader.dwBitRate = 1000000000000000;
            VideoInfoHeader.dwBitErrorRate =1;
            VideoInfoHeader.AvgTimePerFrame = (REFERENCE_TIME) (1 * 1000 * 10000 /10000000000000); 
                RECT rcDst2;
                SetRect(&rcDst2, 0, 0, 240, 200);
            VideoInfoHeader.bmiHeader.biWidth = rcDst2.right; 
            VideoInfoHeader.bmiHeader.biHeight = rcDst2.bottom; 
            VideoInfoHeader.bmiHeader.biSizeImage = 0; 
                    VideoInfoHeader.bmiHeader.biSize = sizeof(VideoInfoHeader.bmiHeader);
            
                    VideoInfoHeader.bmiHeader.biPlanes = 1;
                    
        WM_MEDIA_TYPE *pType = new WM_MEDIA_TYPE();
                
            pType->majortype =WMMEDIATYPE_Video;
            pType->subtype  = WMMEDIASUBTYPE_WMV3;
            pType->bFixedSizeSamples = FALSE;
            pType->bTemporalCompression = TRUE;
            pType->lSampleSize = 0;
            pType->formattype = WMFORMAT_VideoInfo;
            pType->pUnk = NULL;
            pType->cbFormat = sizeof(VIDEOINFOHEADER);
            pType->pbFormat = (BYTE*) &VideoInfoHeader; 
    
            
            pProps->SetMediaType(pType);
            if (FAILED(hr))
            {
                    Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid !  hr=0x%x"), hr);
                    return hr;
            }
            
            hr = mpWriterConfig->ConfigureFilterUsingProfile(pProfile); // At this point E_FAIL error. 
            if (FAILED(hr))
            {
                    Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid !  hr=0x%x"), hr);
                    return hr;
            }

    Can be cause of error something else? My computer running Windows 7 64 bit, can it be a problem for directshow? I have installed all the sdks required for WM and DShow.


  • msdn13

    • did you check this “You must add the WM ASF Writer filter to the filter graph before configuring the filter, and configure the filter before connecting it to any other filters.”
    • you still have uninitialized fields, just break with the debugger on SetMediaType and check them in Watch debug window

  • msdn14 Hello and Tahnk you Roman,I applied your first check , it is give error but with a -1072886842 result. I think,  it is an advance. My all capture code sequence and my watch window like below now with latest inits of variables.  My Code sequence:


    HRESULT hr; IBaseFilter *pSrcFilter=NULL; IBaseFilter *pASFWriter = NULL; // WM ASF File filter IFileSinkFilter2 *pSink = NULL; // File sink object IWMWriterAdvanced2 *pWMWA2 = NULL; IServiceProvider *pProvider; IConfigAsfWriter *mpWriterConfig = NULL; // Get DirectShow interfaces hr = GetInterfaces(); if (FAILED(hr)) { Msg(TEXT("Failed to get video interfaces! hr=0x%x"), hr); return hr; } hr = CoCreateInstance (CLSID_WMAsfWriter, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **) &pASFWriter); hr = g_pGraph->AddFilter (pASFWriter, L"ASF Writer"); if (FAILED(hr)) { Msg(TEXT("Failed to CLSID_WMAsfWriter AddFilter! hr=0x%x"), hr); return hr; } if (FAILED(hr)) { Msg(TEXT("Failed to CLSID_WMAsfWriter! hr=0x%x"), hr); return hr; } hr = pASFWriter->QueryInterface(IID_IConfigAsfWriter, (void**)&mpWriterConfig); if (FAILED(hr)) { Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid ! hr=0x%x"), hr); return hr; } IWMProfileManager *profileManager; IWMStreamConfig * pWMStreamConfig; hr = WMCreateProfileManager(&profileManager); if (FAILED(hr)) { Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid ! hr=0x%x"), hr); return hr; } IWMProfile *pProfile; hr = profileManager->CreateEmptyProfile(WMT_VER_9_0, &pProfile); if (FAILED(hr)) { Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid ! hr=0x%x"), hr); return hr; } hr = pProfile->CreateNewStream(WMMEDIATYPE_Video, &pWMStreamConfig); if (FAILED(hr)) { Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid ! hr=0x%x"), hr); return hr; } IWMVideoMediaProps *pProps; hr = pWMStreamConfig->QueryInterface(IID_IWMVideoMediaProps,(void**)&pProps); if (FAILED(hr)) { Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid ! hr=0x%x"), hr); return hr; } pProps->SetQuality(100); VIDEOINFOHEADER VideoInfoHeader; VideoInfoHeader.dwBitRate = 1000000000000000; VideoInfoHeader.dwBitErrorRate =1; VideoInfoHeader.AvgTimePerFrame = (REFERENCE_TIME) (1 * 1000 * 10000 /10000000000000); RECT rcDst2; SetRect(&rcDst2, 0, 0, 240, 200); SetRect(&VideoInfoHeader.rcSource, 0, 0,640,480); VideoInfoHeader.rcTarget = rcDst2; VideoInfoHeader.bmiHeader.biWidth = rcDst2.right; VideoInfoHeader.bmiHeader.biHeight = rcDst2.bottom; VideoInfoHeader.bmiHeader.biSizeImage = 0; VideoInfoHeader.bmiHeader.biSize = sizeof(VideoInfoHeader.bmiHeader); VideoInfoHeader.bmiHeader.biXPelsPerMeter = 0; VideoInfoHeader.bmiHeader.biYPelsPerMeter = 0; VideoInfoHeader.bmiHeader.biClrImportant = 0; VideoInfoHeader.bmiHeader.biClrUsed = 0; VideoInfoHeader.bmiHeader.biPlanes = 1; VideoInfoHeader.bmiHeader.biCompression = 0x56595559; WM_MEDIA_TYPE *pType = new WM_MEDIA_TYPE(); pType->majortype =WMMEDIATYPE_Video; pType->subtype = WMMEDIASUBTYPE_WMV3; pType->bFixedSizeSamples = FALSE; pType->bTemporalCompression = TRUE; pType->lSampleSize = 0; pType->formattype = WMFORMAT_VideoInfo; pType->pUnk = NULL; pType->cbFormat = sizeof(VIDEOINFOHEADER); pType->pbFormat = (BYTE*) &VideoInfoHeader; pProps->SetMediaType(pType); if (FAILED(hr)) { Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid ! hr=0x%x"), hr); return hr; } hr = mpWriterConfig->ConfigureFilterUsingProfile(pProfile); if (FAILED(hr)) { Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid ! hr=0x%x"), hr); return hr; } //hr = mpWriterConfig->ConfigureFilterUsingProfileGuid(WMProfile_V40_250Video); if (FAILED(hr)) { Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid ! hr=0x%x"), hr); return hr; } hr = pASFWriter->QueryInterface(IID_IServiceProvider, (void**)&pProvider); if (SUCCEEDED(hr)) { hr = pProvider->QueryService(IID_IWMWriterAdvanced2, IID_IWMWriterAdvanced2, (void**)&pWMWA2); } if (FAILED(hr = pWMWA2->SetLiveSource(TRUE))) { printf ("mpWriter2->SetLiveSource FAILED\n"); return hr; } IWMWriterFileSink* m_pFileSink; hr = WMCreateWriterFileSink( &m_pFileSink ); if ( FAILED( hr ) ) { _tprintf( _T( "Could not create Writer File Sink (hr=0x%08x).\n" ), hr ); return hr; } m_pFileSink->Open (L"test.asf"); if ( FAILED( hr ) ) { _tprintf( _T( "Could not create Writer File Sink (hr=0x%08x).\n" ), hr ); return hr; } pWMWA2->AddSink(m_pFileSink); if ( FAILED( hr ) ) { _tprintf( _T( "Could not create Writer File Sink (hr=0x%08x).\n" ), hr ); return hr; } // remove default sink... added back later dynamically if (FAILED(hr = pWMWA2->RemoveSink(0))) { printf (" mpWriter2->RemoveSink FAILED\n"); return hr; } pProvider->Release(); IWMWriterNetworkSink *mpNetSink = NULL; if (FAILED(hr = WMCreateWriterNetworkSink(&mpNetSink))) { printf ("WMCreateWriterNetworkSink FAILED\n"); return hr; } DWORD dwPort = 1234; if (FAILED(hr = mpNetSink->Open(&dwPort))) { printf ("Port open FAILED\n"); return hr; } WCHAR url[256]; DWORD url_len = 256; hr = mpNetSink->GetHostURL(url, &url_len); if (FAILED(pWMWA2->AddSink(mpNetSink))) { printf ("mpWriter2->AddSink FAILED\n"); return hr; } // Attach the filter graph to the capture graph hr = g_pCapture->SetFiltergraph(g_pGraph); if (FAILED(hr)) { Msg(TEXT("Failed to set capture filter graph! hr=0x%x"), hr); return hr; } // Use the system device enumerator and class enumerator to find // a video capture/preview device, such as a desktop USB video camera. hr = FindCaptureDevice(&pSrcFilter); if (FAILED(hr)) { // Don't display a message because FindCaptureDevice will handle it return hr; } // Add Capture filter to our graph. hr = g_pGraph->AddFilter(pSrcFilter, L"Video Capture"); if (FAILED(hr)) { Msg(TEXT("Couldn't add the capture filter to the graph! hr=0x%x\r\n\r\n") TEXT("If you have a working video capture device, please make sure\r\n") TEXT("that it is connected and is not being used by another application.\r\n\r\n") TEXT("The sample will now close."), hr); pSrcFilter->Release(); return hr; } // Render the preview pin on the video capture filter // Use this instead of g_pGraph->RenderFile hr = g_pCapture->RenderStream (&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, pSrcFilter, NULL, NULL); hr = g_pCapture->RenderStream (&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, pSrcFilter, NULL, pASFWriter); if (FAILED(hr)) { Msg(TEXT("Couldn't render the video capture stream. hr=0x%x\r\n") TEXT("The capture device may already be in use by another application.\r\n\r\n") TEXT("The sample will now close."), hr); pSrcFilter->Release(); return hr; } // Now that the filter has been added to the graph and we have // rendered its stream, we can release this reference to the filter. pSrcFilter->Release(); // Set video window style and position hr = SetupVideoWindow(); if (FAILED(hr)) { Msg(TEXT("Couldn't initialize video window! hr=0x%x"), hr); return hr; } #ifdef REGISTER_FILTERGRAPH // Add our graph to the running object table, which will allow // the GraphEdit application to "spy" on our graph hr = AddGraphToRot(g_pGraph, &g_dwGraphRegister); if (FAILED(hr)) { Msg(TEXT("Failed to register filter graph with ROT! hr=0x%x"), hr); g_dwGraphRegister = 0; } #endif // Start previewing video data hr = g_pMC->Run(); if (FAILED(hr)) { Msg(TEXT("Couldn't run the graph! hr=0x%x"), hr); return hr; } // Remember current state g_psCurrent = Running; return S_OK;

    My watch:

              hr      -1072886842     HRESULT
    -               pType   0x00908160 {majortype={...} subtype={...} bFixedSizeSamples=0 ...}      _WMMediaType *
    -               majortype       {73646976-0000-0010-8000-00AA00389B71}  _GUID
                    Data1   1935960438      unsigned long
                    Data2   0       unsigned short
                    Data3   16      unsigned short
    +               Data4   0x00908168 "€" unsigned char [8]
    -               subtype {33564D57-0000-0010-8000-00AA00389B71}  _GUID
                    Data1   861293911       unsigned long
                    Data2   0       unsigned short
                    Data3   16      unsigned short
    +               Data4   0x00908178 "€" unsigned char [8]
                    bFixedSizeSamples       0       int
                    bTemporalCompression    1       int
                    lSampleSize     0       unsigned long
    -               formattype      {CLSID_KsDataTypeHandlerVideo}  _GUID
                    Data1   89694080        unsigned long
                    Data2   50006   unsigned short
                    Data3   4558    unsigned short
    +               Data4   0x00908194 "¿"   unsigned char [8]
    +               pUnk    0x00000000      IUnknown *
                    cbFormat        88      unsigned long
    +               pbFormat        0x0034f058 "" unsigned char *
    -               VideoInfoHeader {rcSource={...} rcTarget={...} dwBitRate=2764472320 ...}        tagVIDEOINFOHEADER
    -               rcSource        {top=0 bottom=480 left=0 right=640}     tagRECT
                    left    0       long
                    top     0       long
                    right   640     long
                    bottom  480     long
    -               rcTarget        {top=0 bottom=200 left=0 right=240}     tagRECT
                    left    0       long
                    top     0       long
                    right   240     long
                    bottom  200     long
                    dwBitRate       2764472320      unsigned long
                    dwBitErrorRate  1       unsigned long
                    AvgTimePerFrame 0       __int64
    -               bmiHeader       {biSize=40 biWidth=240 biHeight=200 ...}        tagBITMAPINFOHEADER
                    biSize  40      unsigned long
                    biWidth 240     long
                    biHeight        200     long
                    biPlanes        1       unsigned short
                    biBitCount      52428   unsigned short
                    biCompression   1448695129      unsigned long
                    biSizeImage     0       unsigned long
                    biXPelsPerMeter 0       long
                    biYPelsPerMeter 0       long
                    biClrUsed       0       unsigned long
                    biClrImportant  0       unsigned long
    

  • msdn15

    Hello and Tahnk you Roman, I applied your first check , it is give error but with a -1072886842 result. I think,  it is an advance. My all capture code sequence and my watch window like below now with latest inits of variables.  tagVIDEOINFOHEADER – rcSource {top=0 bottom=480 left=0 right=640} tagRECT left 0 long top 0 long right 640 long bottom 480 long – rcTarget {top=0 bottom=200 left=0 right=240} tagRECT left 0 long top 0 long right 240 long bottom 200 {biSize=40 biWidth=240 biHeight=200 …}

    Error code is 0xC00D0BC6 “The Profile is invalid.”, so you passed previous problem and stumbled on a new one. This time you have something wrong in the profile. I am not sure what exactly causes this, but you have a mismatch in mentioned resolutions, this may be the problem.


  • msdn16 Hello Roman,I bypassed all my custom profile and used a system stock profile , now it gives me 0xc00d1b5e error,

    hr = mpWriterConfig->ConfigureFilterUsingProfileGuid(WMProfile_V40_250Video);

    i googled this error and i found NS_E_NOMATCHING_ELEMENT description. What does it mean? 

    also with matched resolutions ,my custom profile gave the same error : 0xC00D0BC6.


  • msdn17 hello Roman,

    With WMProfile_V70_56VideoWebServer profile , passed config problem, but my graph didn’t run giving 0x8007007b error.


  • msdn18

    hello Roman,

    With WMProfile_V70_56VideoWebServer profile , passed config problem, but my graph didn’t run giving 0x8007007b error.

    It is ERROR_INVALID_NAME “The filename, directory name, or volume label syntax is incorrect.” did you provide file name to the filter so that it knows where it is expected to write to?


  • msdn19 I used this code to define filename:

     m_pFileSink->Open (L"test.asf");
            if ( FAILED( hr ) )
            {
                    _tprintf( _T( "Could not create Writer File Sink (hr=0x%08x).\n" ), hr );
                    return hr;
            }

  • msdn20 Don’t add an extra file sink explicitly, that will make a mess.

    Instead, set the initial filename with IFileSinkFilter::SetFileName().  Once the name is set then you can remove the default sink and add a network sink.


  • msdn21 With your lights, my final code, and it gives E_FAIL error with code 0x80004005 at the media control run. I returned to first error , but with a more accurate code I think.

    At this line hr = g_pMC->Run(); // E_FAIL 0x80004005

    it fails.

          HRESULT hr; IBaseFilter *pSrcFilter=NULL; IBaseFilter *pASFWriter = NULL; // WM ASF File filter IFileSinkFilter2 *pSink = NULL; // File sink object IWMWriterAdvanced2 *pWMWA2 = NULL; IServiceProvider *pProvider; IConfigAsfWriter *mpWriterConfig = NULL; // Get DirectShow interfaces hr = GetInterfaces(); if (FAILED(hr)) { Msg(TEXT("Failed to get video interfaces! hr=0x%x"), hr); return hr; } hr = CoCreateInstance (CLSID_WMAsfWriter, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **) &pASFWriter); hr = g_pGraph->AddFilter (pASFWriter, L"ASF Writer"); if (FAILED(hr)) { Msg(TEXT("Failed to CLSID_WMAsfWriter AddFilter! hr=0x%x"), hr); return hr; } hr = pASFWriter->QueryInterface(IID_IConfigAsfWriter, (void**)&mpWriterConfig); if (FAILED(hr)) { Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid ! hr=0x%x"), hr); return hr; } hr = mpWriterConfig->ConfigureFilterUsingProfileGuid(WMProfile_V70_56VideoWebServer); if (FAILED(hr)) { Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid ! hr=0x%x"), hr); return hr; } hr = pASFWriter->QueryInterface(IID_IServiceProvider, (void**)&pProvider); if (SUCCEEDED(hr)) { hr = pProvider->QueryService(IID_IWMWriterAdvanced2, IID_IWMWriterAdvanced2, (void**)&pWMWA2); } if (FAILED(hr = pWMWA2->SetLiveSource(TRUE))) { printf ("mpWriter2->SetLiveSource FAILED\n"); return hr; } IFileSinkFilter *pFileSink; hr = pASFWriter->QueryInterface(IID_IFileSinkFilter , (void**)&pFileSink); if (FAILED(hr)) { Msg(TEXT("Failed to ConfigureFilterUsingProfileGuid ! hr=0x%x"), hr); return hr; } AM_MEDIA_TYPE am_media_type; ZeroMemory(&am_media_type, sizeof(am_media_type)); am_media_type.majortype = MEDIATYPE_Video; am_media_type.subtype = MEDIASUBTYPE_RGB24; am_media_type.formattype = FORMAT_VideoInfo; hr = pFileSink->SetFileName(L"test.asf", &am_media_type); if (FAILED(hr)) { Msg(TEXT("Failed to SetFileName ! hr=0x%x"), hr); return hr; } // remove default sink... added back later dynamically if (FAILED(hr = pWMWA2->RemoveSink(0))) { printf (" mpWriter2->RemoveSink FAILED\n"); return hr; } pProvider->Release(); IWMWriterNetworkSink *mpNetSink = NULL; if (FAILED(hr = WMCreateWriterNetworkSink(&mpNetSink))) { printf ("WMCreateWriterNetworkSink FAILED\n"); return hr; } DWORD dwPort = 1234; if (FAILED(hr = mpNetSink->Open(&dwPort))) { printf ("Port open FAILED\n"); return hr; } WCHAR url[256]; DWORD url_len = 256; hr = mpNetSink->GetHostURL(url, &url_len); if (FAILED(pWMWA2->AddSink(mpNetSink))) { printf ("mpWriter2->AddSink FAILED\n"); return hr; } // Attach the filter graph to the capture graph hr = g_pCapture->SetFiltergraph(g_pGraph); if (FAILED(hr)) { Msg(TEXT("Failed to set capture filter graph! hr=0x%x"), hr); return hr; } // Use the system device enumerator and class enumerator to find // a video capture/preview device, such as a desktop USB video camera. hr = FindCaptureDevice(&pSrcFilter); if (FAILED(hr)) { // Don't display a message because FindCaptureDevice will handle it return hr; } // Add Capture filter to our graph. hr = g_pGraph->AddFilter(pSrcFilter, L"Video Capture"); if (FAILED(hr)) { Msg(TEXT("Couldn't add the capture filter to the graph! hr=0x%x\r\n\r\n") TEXT("If you have a working video capture device, please make sure\r\n") TEXT("that it is connected and is not being used by another application.\r\n\r\n") TEXT("The sample will now close."), hr); pSrcFilter->Release(); return hr; } // Render the preview pin on the video capture filter // Use this instead of g_pGraph->RenderFile hr = g_pCapture->RenderStream (&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, pSrcFilter, NULL, NULL); hr = g_pCapture->RenderStream (&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, pSrcFilter, NULL, pASFWriter); if (FAILED(hr)) { Msg(TEXT("Couldn't render the video capture stream. hr=0x%x\r\n") TEXT("The capture device may already be in use by another application.\r\n\r\n") TEXT("The sample will now close."), hr); pSrcFilter->Release(); return hr; } // Now that the filter has been added to the graph and we have // rendered its stream, we can release this reference to the filter. pSrcFilter->Release(); // Set video window style and position hr = SetupVideoWindow(); if (FAILED(hr)) { Msg(TEXT("Couldn't initialize video window! hr=0x%x"), hr); return hr; } #ifdef REGISTER_FILTERGRAPH // Add our graph to the running object table, which will allow // the GraphEdit application to "spy" on our graph hr = AddGraphToRot(g_pGraph, &g_dwGraphRegister); if (FAILED(hr)) { Msg(TEXT("Failed to register filter graph with ROT! hr=0x%x"), hr); g_dwGraphRegister = 0; } #endif 
    // Start previewing video data hr = g_pMC->Run(); // E_FAIL 0x80004005 if (FAILED(hr)) { Msg(TEXT("Couldn't run the graph! hr=0x%x"), hr); return hr; } // Remember current state g_psCurrent = Running; return S_OK;