locked
Custom media foundation source dll is unloaded and crushed.

    Question

  • Hello,

    I am developing a media playback application in Metro style.
    The application uses custom media foundation source that implements IMFMediaSource to play encrypted media sources.
    Every time I start playback with my custom media source, the application crushes 2 minutes after start.
    I noticed that the dll that contains the media source is unloaded during playback, this causes crush in the application.
    The issue is reproducible in Windows8 RP, was not reproduced in Windows8 CP (build 8250).

    I can reproduce the issue with MediaExtensionsCPP sample.
    To reproduce the issue, run MediaExtensionsCpp, select "2) Install a local scheme handler", click one of shapes to start playback, and wait about 2 minutes.
    I got the call stack when DllMain is called with DLL_PROCESS_DETACH during playback.
    The call stack is as follows.

    > GeometricSource.dll!DllMain(HINSTANCE__ * hInstance, unsigned long dwReason, void * lpReserved) Line 36 C++
      GeometricSource.dll!__DllMainCRTStartup(void * hDllHandle, unsigned long dwReason, void * lpreserved) Line 508 C
      GeometricSource.dll!_DllMainCRTStartup(void * hDllHandle, unsigned long dwReason, void * lpreserved) Line 472 C
      ntdll.dll!_LdrxCallInitRoutine@16_() Unknown
      ntdll.dll!_LdrpCallInitRoutine@16_() Unknown
      ntdll.dll!_LdrpProcessDetachNode@4_() Unknown
      ntdll.dll!_LdrpUnloadNode@4_() Unknown
      ntdll.dll!_LdrpDecrementNodeLoadCount@4_() Unknown
      ntdll.dll!_LdrUnloadDll@4_() Unknown
      KernelBase.dll!_FreeLibrary@4_() Unknown
      combase.dll!76ef1345() Unknown
      [Frames below may be incorrect and/or missing, no symbols loaded for combase.dll] 
      combase.dll!76ef138b() Unknown
      combase.dll!76eb8125() Unknown
      combase.dll!76eb82af() Unknown
      combase.dll!76eb820d() Unknown
      twinapi.dll!Event::WaitWithFreeUnusedLibraries() C++
      twinapi.dll!Windows::ApplicationModel::Core::CoreApplicationFactory::RunInternal(Windows::ApplicationModel::Core::IFrameworkViewSource * viewFactory, Windows::ApplicationModel::Background::IBackgroundTaskFactory * backgroundTaskFactory, unsigned char useAstaForBackgroundThreads, Windows::Foundation::IGetActivationFactory * getActivationFactory) Line 525 C++
      twinapi.dll!Windows::ApplicationModel::Core::CoreApplicationFactory::Run(Windows::ApplicationModel::Core::IFrameworkViewSource * viewFactory) Line 472 C++
      Windows.UI.Xaml.dll!5dd0aada() Unknown
      KernelBase.dll!_GlobalFree@4_() Unknown
      Windows.UI.Xaml.dll!5dc980cb() Unknown
      MediaExtensionsCPP.exe!Windows::UI::Xaml::IApplicationStatics::Start(Windows::UI::Xaml::ApplicationInitializationCallback ^ __param0) C++
      MediaExtensionsCPP.exe!Windows::UI::Xaml::Application::Start(Windows::UI::Xaml::ApplicationInitializationCallback ^ __param0) C++
      MediaExtensionsCPP.exe!main(Platform::Array<Platform::String ^,1> ^ args) Line 92 C++
      MediaExtensionsCPP.exe!_main() Line 28 C++
      MediaExtensionsCPP.exe!WinMain(HINSTANCE__ * __formal, HINSTANCE__ * __formal, char * __formal, int __formal) Line 13 C++
      MediaExtensionsCPP.exe!__tmainCRTStartup() Line 528 C
      MediaExtensionsCPP.exe!WinMainCRTStartup() Line 377 C
      kernel32.dll!@BaseThreadInitThunk@12_() Unknown
      ntdll.dll!___RtlUserThreadStart@8_() Unknown
      ntdll.dll!__RtlUserThreadStart@8_() Unknown

    From "Event::WaitWithFreeUnusedLibraries" in the call stack, I guess that the dll is regarded not working so the dll is unloaded, but I cannot find how to avoid this.
    Why media source dlls are unloaded, and how to avoid unloading media source dlls?

    Thanks in advance.

     


    kohei sakamoto



    Wednesday, June 13, 2012 10:20 AM

Answers

  • The Media team has a fix that will be in the next release of the samples to address this issue. To address the scenario reported in the original post, the changes need implemented in

    CGeometricSchemeHandler::CGeometricSchemeHandler(void)

    and

    CGeometricSchemeHandler::~CGeometricSchemeHandler(void)

    These are the instructions to fix the current samples:

    We found a bug in the Media samples which cause DLLs to get unloaded too early. This fix will be in the next update to the samples. In the meantime you can add these lines to constructors/destructors of the source/stream classes in the MSDN samples:
    Note: This is not needed for classes which derive from RuntimeClass<> (ex: the scheme handler).

    Constructor:

        auto module = ::Microsoft::WRL::GetModuleBase();
        if (module != nullptr)
        {
            module->IncrementObjectCount();
        }


    Destructor:

        auto module = ::Microsoft::WRL::GetModuleBase();
        if (module != nullptr)
        {
            module->DecrementObjectCount();
        }


    David Lamb



    Thursday, June 28, 2012 5:35 PM
    Moderator

All replies

  • You can test this on RP, maybe fixed in RP.

    NEU_ShieldEdge

    Thursday, June 14, 2012 11:23 AM
  • You can test this on RP, maybe fixed in RP.

    NEU_ShieldEdge

     

    Hello Luke,

    Thanks, but the issue occurs in RP. Before RP, I used CP (build 8250) and the issue never occurred.

     


    kohei sakamoto

    Friday, June 15, 2012 2:01 AM
  • Hello,

    Do you fix this problem?

    I have the same problem


    haha

    Monday, June 25, 2012 2:04 AM
  • Hello wuyueduzun,

    I could not fix this problem.

    I noticed that the dll is never unloaded before my scheme handler completes creating media source and IMFSchemeHandler::EndCreateObject is called.
    But I don't have any other updates.


    kohei sakamoto

    Monday, June 25, 2012 9:58 AM
  • Thanks for your reply!

    haha

    Tuesday, June 26, 2012 2:16 AM
  • We are investigating this issue now. Thanks for reporting this!

    David Lamb

    Tuesday, June 26, 2012 5:38 PM
    Moderator
  • Hello All,

    I have been tasked with investigating this issue. Unfortunately due to my current schedule it might not be until early next week before I get a chance to really look at it.

    Thanks for your patience,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, June 27, 2012 8:30 PM
    Moderator
  • The Media team has a fix that will be in the next release of the samples to address this issue. To address the scenario reported in the original post, the changes need implemented in

    CGeometricSchemeHandler::CGeometricSchemeHandler(void)

    and

    CGeometricSchemeHandler::~CGeometricSchemeHandler(void)

    These are the instructions to fix the current samples:

    We found a bug in the Media samples which cause DLLs to get unloaded too early. This fix will be in the next update to the samples. In the meantime you can add these lines to constructors/destructors of the source/stream classes in the MSDN samples:
    Note: This is not needed for classes which derive from RuntimeClass<> (ex: the scheme handler).

    Constructor:

        auto module = ::Microsoft::WRL::GetModuleBase();
        if (module != nullptr)
        {
            module->IncrementObjectCount();
        }


    Destructor:

        auto module = ::Microsoft::WRL::GetModuleBase();
        if (module != nullptr)
        {
            module->DecrementObjectCount();
        }


    David Lamb



    Thursday, June 28, 2012 5:35 PM
    Moderator
  • Thank you David.

    I fixed the issue by incrementing object count.


    kohei sakamoto

    Tuesday, July 3, 2012 9:36 AM