DirectShow Win10
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: DirectShow Win10

  1. #1
    Join Date
    Jan 2018
    Posts
    2

    DirectShow Win10

    Hello to all i need to convert the code bellow to a more modern aproach to DirectShow to make a old app work in Win 10 , the ancient code used DirectDraw in the video surface, can this be done in another renderer or DX texture? the app is working in DX8 and the video surface used to be displayed inside DirectX8 in a DirectDraw surface but it stopped working. Can someone help. Thanks a lot.
    Code:
    #include <stdio.h>
    #include "ddraw.h" // DirectDraw interfaces
    #include "mmstream.h" // multimedia stream interfaces
    #include "amstream.h" // DirectShow multimedia stream interfaces
    #include "ddstream.h" // DirectDraw multimedia stream interfaces
    
    HRESULT RenderStreamToSurface(IDirectDrawSurface *pSurface, IMultiMediaStream *pMMStream)
    { 
    
    IMediaStream *pPrimaryVidStream; IDirectDrawMediaStream *pDDStream; IDirectDrawStreamSample *pSample; RECT rect; DDSURFACEDESC ddsd; HRESULT hr; hr = pMMStream->GetMediaStream(MSPID_PrimaryVideo, &pPrimaryVidStream); if (FAILED(hr)) { return hr; } pPrimaryVidStream->QueryInterface(IID_IDirectDrawMediaStream, (void **)&pDDStream); ddsd.dwSize = sizeof(ddsd); hr = pDDStream->GetFormat(&ddsd, NULL, NULL, NULL); if (SUCCEEDED(hr)) { rect.top = rect.left = 0; rect.bottom = ddsd.dwHeight; rect.right = ddsd.dwWidth; hr = pDDStream->CreateSample(pSurface, &rect, 0, &pSample); if (SUCCEEDED(hr)) { pMMStream->SetState(STREAMSTATE_RUN); while (pSample->Update(0, NULL, NULL, NULL) == S_OK) { // Empty loop. } pMMStream->SetState(STREAMSTATE_STOP); pSample->Release(); } } pDDStream->Release(); pPrimaryVidStream->Release(); return hr;
    } HRESULT RenderFileToMMStream(const char * szFileName, IMultiMediaStream **ppMMStream, IDirectDraw *pDD) {
    if (strlen(szFileName) > MAX_PATH) { return E_INVALIDARG; } IAMMultiMediaStream *pAMStream; HRESULT hr = CoCreateInstance(CLSID_AMMultiMediaStream, NULL, CLSCTX_INPROC_SERVER, IID_IAMMultiMediaStream, (void **)&pAMStream); if (FAILED(hr)) { return hr; } WCHAR wPath[MAX_PATH + 1]; MultiByteToWideChar(CP_ACP, 0, szFileName, -1, wPath, MAX_PATH + 1); pAMStream->Initialize(STREAMTYPE_READ, AMMSF_NOGRAPHTHREAD, NULL); pAMStream->AddMediaStream(pDD, &MSPID_PrimaryVideo, 0, NULL); pAMStream->AddMediaStream(NULL, &MSPID_PrimaryAudio, AMMSF_ADDDEFAULTRENDERER, NULL); hr = pAMStream->OpenFile(wPath, 0); if (SUCCEEDED(hr)) { hr = pAMStream->QueryInterface(IID_IMultiMediaStream, (void**)ppMMStream); } pAMStream->Release(); return hr; } int __cdecl main(int argc, char *argv[]) { if (argc < 2) { printf("Usage : showstrm movie.ext\n"); exit(0); } DDSURFACEDESC ddsd; IDirectDraw *pDD; IDirectDrawSurface *pPrimarySurface; IMultiMediaStream *pMMStream; CoInitialize(NULL); DirectDrawCreate(NULL, &pDD, NULL); pDD->SetCooperativeLevel(GetDesktopWindow(), DDSCL_NORMAL); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; pDD->CreateSurface(&ddsd, &pPrimarySurface, NULL); HRESULT hr = RenderFileToMMStream(argv[1], &pMMStream, pDD); if (SUCCEEDED(hr)) { RenderStreamToSurface(pPrimarySurface, pMMStream); pMMStream->Release(); } pPrimarySurface->Release(); pDD->Release(); CoUninitialize(); return 0;
    }
    Last edited by Vic666; January 7th, 2018 at 08:51 PM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,063

    Re: DirectShow Win10

    Your code is very hard to read/understand. It's because you missed using the CODE tags.
    Please, read the Announcement: Before you post....
    Victor Nijegorodov

  3. #3
    Join Date
    Jan 2018
    Posts
    2

    Re: DirectShow Win10

    Sorry about that, i think this is better.
    Code:
    #include <stdio.h>
    #include "ddraw.h" // DirectDraw interfaces
    #include "mmstream.h" // multimedia stream interfaces
    #include "amstream.h" // DirectShow multimedia stream interfaces
    #include "ddstream.h" // DirectDraw multimedia stream interfaces
    
    HRESULT RenderStreamToSurface(IDirectDrawSurface *pSurface, IMultiMediaStream *pMMStream)
    { 
        IMediaStream *pPrimaryVidStream; 
        IDirectDrawMediaStream *pDDStream;
        IDirectDrawStreamSample *pSample;
        RECT rect;
        DDSURFACEDESC ddsd;
    
        HRESULT hr;
        hr = pMMStream->GetMediaStream(MSPID_PrimaryVideo, &pPrimaryVidStream);
        if (FAILED(hr))
        {
            return hr;
        }
    
        pPrimaryVidStream->QueryInterface(IID_IDirectDrawMediaStream, (void **)&pDDStream);
    
        ddsd.dwSize = sizeof(ddsd);
        hr = pDDStream->GetFormat(&ddsd, NULL, NULL, NULL);
        if (SUCCEEDED(hr))
        {
            rect.top = rect.left = 0;
            rect.bottom = ddsd.dwHeight;
            rect.right = ddsd.dwWidth;
            hr = pDDStream->CreateSample(pSurface, &rect, 0, &pSample);
            if (SUCCEEDED(hr))
            {
                pMMStream->SetState(STREAMSTATE_RUN);
                while (pSample->Update(0, NULL, NULL, NULL) == S_OK)
                {
                    // Empty loop.
                }
    
                pMMStream->SetState(STREAMSTATE_STOP);
                pSample->Release(); 
            }
        }
    
        pDDStream->Release();
        pPrimaryVidStream->Release();
        return hr;
    }
    
    HRESULT RenderFileToMMStream(const char * szFileName, IMultiMediaStream **ppMMStream, IDirectDraw *pDD)
    {
        if (strlen(szFileName) > MAX_PATH)
        {
            return E_INVALIDARG;
        }
    
        IAMMultiMediaStream *pAMStream;
        HRESULT hr = CoCreateInstance(CLSID_AMMultiMediaStream, NULL, CLSCTX_INPROC_SERVER, IID_IAMMultiMediaStream, (void **)&pAMStream);
    
        if (FAILED(hr))
        {
            return hr;
        }
    
        WCHAR wPath[MAX_PATH + 1];
        MultiByteToWideChar(CP_ACP, 0, szFileName, -1, wPath, MAX_PATH + 1);
    
        pAMStream->Initialize(STREAMTYPE_READ, AMMSF_NOGRAPHTHREAD, NULL);
        pAMStream->AddMediaStream(pDD, &MSPID_PrimaryVideo, 0, NULL);
        pAMStream->AddMediaStream(NULL, &MSPID_PrimaryAudio, AMMSF_ADDDEFAULTRENDERER, NULL);
        hr = pAMStream->OpenFile(wPath, 0);
        if (SUCCEEDED(hr))
        {
            hr = pAMStream->QueryInterface(IID_IMultiMediaStream, (void**)ppMMStream);
        }
    
        pAMStream->Release();
        return hr;
    }
    
    int __cdecl main(int argc, char *argv[]) 
    { 
        if (argc < 2) 
        {
            printf("Usage : showstrm movie.ext\n");
            exit(0);
        } 
    
        DDSURFACEDESC ddsd;
        IDirectDraw *pDD; 
        IDirectDrawSurface *pPrimarySurface;
        IMultiMediaStream *pMMStream;
    
        CoInitialize(NULL);
    
        DirectDrawCreate(NULL, &pDD, NULL);
        pDD->SetCooperativeLevel(GetDesktopWindow(), DDSCL_NORMAL);
    
        ddsd.dwSize = sizeof(ddsd);
        ddsd.dwFlags = DDSD_CAPS;
        ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
        pDD->CreateSurface(&ddsd, &pPrimarySurface, NULL);
    
        HRESULT hr = RenderFileToMMStream(argv[1], &pMMStream, pDD);
        if (SUCCEEDED(hr))
        {
            RenderStreamToSurface(pPrimarySurface, pMMStream); 
            pMMStream->Release();
        }
    
        pPrimarySurface->Release(); 
        pDD->Release(); 
    
        CoUninitialize();
        return 0;
    }
    Last edited by 2kaud; January 8th, 2018 at 03:38 AM. Reason: Added indentations

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,063

    Re: DirectShow Win10

    No! Don't you see it is almost the same!?
    Code snippet has to be formatted to have the proper indentations, what is not in your post!
    Victor Nijegorodov

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,974

    Re: DirectShow Win10

    [Code should be properly indented (using spaces or tabs) and formatted before being inserted. I've indented the code in post #3]

    Cheers!
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.5.4)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)