2

The question

Which tools or code constructs (like defines) are the ones that should be used in this area and how to get them to work? Is there something I as a new person to media foundation should do before asking my question here to avoid simple mistakes?

The question is not "what is your favorite tool, lets fight over who is right" but simply, in regards to this media foundation framework, which options are according your expertise in the area worth considering for debugging and how do I use them?

Background to why I am asking this

Looking around on stackoverflow it seems that some questions are asked without knowledge of how to properly debug Media Foundation applications. I some cases a specific question gets an answer that states that OP should use MFTrace 1, 2. I also belive that my earlier questions here would have been helped out by using proper debugging tools or traces specific to media foundation.

Things I as someone new to this framework have encountered

I myself have not even been able to get MFTrace or Event Viewer to work, both tools that are mentioned in the official media foundation blog.

The documentation for how to get the MFTrace is lacking, is it only available in the old win 7 SDK on .NET 4.0 which is referred to here? Or can one use a newer SDK? Installing the older win 7 SDK involves some pain points on windows 10 (first change regedit values, how to do that, new error -> SO suggest to look at the log and maybe uninstall any existing Visual C++ 2010 redistrubutable.) It would be nice to know if this is something you have to go through, in which case I will, or if MFTrace can be found elsewhere.

I did not get any logs from the Event Viewer. But maybe one should skip that tool altogether and only use MFTrace since the official blog says the following?

However, MFTrace is much more powerful, and collects way more information, than Event viewer. source

Besides tools, is there no?

#define MF_TRACE_LEVEL 15

In this ms blog post they mention EventWriteString and a few TRACE_LEVEL defines. Is this something that is useful outside MFTrace?

Community
  • 1
  • 1
Alex Telon
  • 867
  • 10
  • 27
  • 1
    Wow Alex, it seems you did a pretty fair job of providing an answer for your own question. Seriously though, I get what you are asking, and I hope that someone can provide a comprehensive response, but I wouldn't expect it. – Jeff Feb 04 '17 at 13:25

1 Answers1

3

Usually I use the following:

  1. VS Debugger, with debug logging via OutputDebugString for most work. It works quite well, even with the asynchronous nature of media foundation.
  2. MFTrace for detailed analysis in hard to analyze cases. This often involves looking up obscure GUIDS in MFAPI.h
  3. Occasionally TOPOEDIT is helpful in testing things out. It's not nearly as capable as GraphEdit though.
  4. Running the Microsoft Media Foundation SDK Samples, or have a look at MFNode. The samples from the Developing Microsoft Media Foundation book are also downloadable from the web. Be aware that some SDK samples have been obsoleted, if you need to look at those you may need to download older SDKs until you find them. There are more samples floating around. Find them.
  5. Look on Stack Overflow, or on the MSDN Media Foundation Forum. Pay close attention to any answers from Roman Ryltsov ;)
  6. If you are new to COM development, be sure to read The N habits of Highly Defective DirectShow Applications. Although it's direct Show specific, a lot of it still applies. In particular: Use and understand CCOMPtr and when you need to use mutexes.

Running MFTRACE:

MFTrace is not pretty, but it does not end up being hard after it gets figured out. The MS Blog entries referenced at the end helped a lot, as does the Text Analysis Tool.

  1. Start an ADMIN command prompt.
  2. run MFTRACEPATH.bat to add the MFTRACE.EXE location to the path
  3. cd {YourExecutableLoc}
  4. run MFTRACECALLER.BAT {YOUREXECUTABLENAME} (Without any Extension)
  5. load YOUREXECTUABLENAME.TXT into the Text Analysis tool to help filter the output.
  6. Occasionally MFTRACEParseTopologies.bat, mentioned in the MSDN blogs is useful.

I use these .bat scripts to run MFTRACE (Remember: Use ADMIN command prompt!)

MFTRACEPATH.BAT:

@echo off
Echo MFTracePath.bat adds MFTrace to path
SET _NT_SYMBOL_PATH=C:\Users\sschi\AppData\Local\Temp\SymbolCache;%QTDIR%\bin
SET PATH=%PATH%;%PROGRAMFILES(x86)%\Windows Kits\10\bin\x86
cd {your Binary Folder}
echo run MFTraceCaller CapstoneDebug next

MFTRACECALLER.BAT

@echo off
SET exFile=MYEXECUTABLEFILENAME
if '%%1' == '' goto start

set exFile=%1
:START

echo Starting MFTRACE using %exFile%, saving output to %exFile%.txt
@echo on
mftrace -es -k all -l 4 -o %exFile%.txt %exFile%.exe %2 %3 %4 %5
@echo off
echo.
echo Trace completed - output is in %exFile.Txt%
echo.
echo Post Processing is available using
echo MFTraceParseTimeStamps.bat
echo MFTraceParseTopologies.bat
echo a) Open %exfile%.txt in TextAnalysisTool
echo b) Load TextAnalysisToolDebugFilters.tat

The text analysis tool helps a lot to filter the mountain of output. Use "File", "Load Filters" to load the filters as needed You can turn individual filters on and off to help zero in on what you are doing. Also, higher filters override lower ones, so for example, the text "Error" in a line overrides everything below it. Also, turn on any "OutputDebugString" logging in your file, it will appear in the traced output.

Below is my 'kitchen sink' filters file. Turn off everything but the red error traces to start.

FILTERS.TAT:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<TextAnalysisTool.NET version="2016-06-16" showOnlyFilteredLines="False">
  <filters>
    <filter enabled="y" excluding="n" description="" foreColor="ff0000" type="matches_text" case_sensitive="n" regex="n" text="Error" />
    <filter enabled="y" excluding="n" description="" foreColor="000000" backColor="ffa500" type="matches_text" case_sensitive="n" regex="n" text="Warning" />
    <filter enabled="n" excluding="n" description="" backColor="ffa500" type="matches_text" case_sensitive="n" regex="n" text="Process Frame" />
    <filter enabled="y" excluding="n" description="" backColor="90ee90" type="matches_text" case_sensitive="n" regex="n" text="MESessionStart" />
    <filter enabled="y" excluding="n" description="" backColor="90ee90" type="matches_text" case_sensitive="n" regex="n" text="MESessionStopped" />
    <filter enabled="y" excluding="n" description="" backColor="90ee90" type="matches_text" case_sensitive="n" regex="n" text="MESessionPaused" />
    <filter enabled="y" excluding="n" description="" backColor="90ee90" type="matches_text" case_sensitive="n" regex="n" text="UpdatePendingCommands" />
    <filter enabled="y" excluding="n" description="" backColor="90ee90" type="matches_text" case_sensitive="n" regex="n" text="SetPositionInternal" />
    <filter enabled="n" excluding="n" description="" foreColor="008000" backColor="add8e6" type="matches_text" case_sensitive="n" regex="n" text="Scrub" />
    <filter enabled="y" excluding="n" description="" foreColor="008000" backColor="d3d3d3" type="matches_text" case_sensitive="n" regex="n" text="&lt;&lt;&lt;&lt;&lt;&lt; " />
    <filter enabled="y" excluding="n" description="" foreColor="008080" backColor="f0e68c" type="matches_text" case_sensitive="n" regex="n" text="RequestSample" />
    <filter enabled="y" excluding="n" description="" foreColor="006400" type="matches_text" case_sensitive="n" regex="n" text="MESession" />
    <filter enabled="y" excluding="n" description="" foreColor="008000" type="matches_text" case_sensitive="n" regex="n" text="MFStartup" />
    <filter enabled="y" excluding="n" description="" foreColor="008000" type="matches_text" case_sensitive="n" regex="n" text="MFShutdown" />
    <filter enabled="y" excluding="n" description="" foreColor="800080" type="matches_text" case_sensitive="n" regex="n" text="Grabber" />
    <filter enabled="y" excluding="n" description="" foreColor="800080" type="matches_text" case_sensitive="n" regex="n" text="Seek" />
    <filter enabled="y" excluding="n" description="" foreColor="d2691e" type="matches_text" case_sensitive="n" regex="n" text="GraphBuilder" />
    <filter enabled="y" excluding="n" description="" foreColor="2e8b57" type="matches_text" case_sensitive="n" regex="n" text="MF_TOPOLOGY" />
    <filter enabled="y" excluding="n" description="" foreColor="2e8b57" type="matches_text" case_sensitive="n" regex="n" text="MF_TOPONODE" />
    <filter enabled="y" excluding="n" description="" foreColor="2e8b57" type="matches_text" case_sensitive="n" regex="n" text="MF_TRANSFORM" />
    <filter enabled="y" excluding="n" description="" foreColor="5f9ea0" type="matches_text" case_sensitive="n" regex="n" text="CurrentPosition" />
    <filter enabled="y" excluding="n" description="" foreColor="5f9ea0" type="matches_text" case_sensitive="n" regex="n" text="CMFMediaSession" />
    <filter enabled="y" excluding="n" description="" foreColor="0000ff" type="matches_text" case_sensitive="n" regex="n" text="OutputDebugString" />
    <filter enabled="n" excluding="n" description="" foreColor="b22222" type="matches_text" case_sensitive="n" regex="n" text="MF_SOURCE_READER" />
    <filter enabled="n" excluding="n" description="" foreColor="008080" type="matches_text" case_sensitive="n" regex="n" text="CoCreateInstance" />
    <filter enabled="y" excluding="n" description="" foreColor="008b8b" type="matches_text" case_sensitive="n" regex="n" text="MeStream" />
    <filter enabled="y" excluding="n" description="" foreColor="008b8b" type="matches_text" case_sensitive="n" regex="n" text="MESource" />
    <filter enabled="y" excluding="n" description="" foreColor="008b8b" type="matches_text" case_sensitive="n" regex="n" text="MFT_MESSAGE" />
    <filter enabled="y" excluding="n" description="" foreColor="008080" type="matches_text" case_sensitive="n" regex="n" text="MF_MT_SUBTYPE" />
    <filter enabled="y" excluding="n" description="" foreColor="008b8b" type="matches_text" case_sensitive="n" regex="n" text="Sample" />
    <filter enabled="y" excluding="n" description="" foreColor="008b8b" type="matches_text" case_sensitive="n" regex="n" text="ProcessInput" />
    <filter enabled="y" excluding="n" description="" foreColor="008b8b" type="matches_text" case_sensitive="n" regex="n" text="ProcessOutput" />
    <filter enabled="y" excluding="n" description="" foreColor="008000" type="matches_text" case_sensitive="n" regex="n" text="OnClock" />
    <filter enabled="y" excluding="n" description="" foreColor="b22222" type="matches_text" case_sensitive="n" regex="n" text="Met=" />
  </filters>
</TextAnalysisTool.NET>

Additional References

  1. Introduction to Text Analysis Tool

  2. textanalysistool.github.io

  3. Microsoft Media Foundation Blog Entries

SteveS
  • 444
  • 3
  • 15
  • While I am no longer working on this problem and haven't tried your suggestions it seems like exactly what I was asking for! Thank you! – Alex Telon Jul 14 '17 at 21:10