title: Decoding audio from non-file source with Microsoft Media Foundation
body: <p>My question is basically that I am new to this framework and <em>I am looking at pointers to how to work with non-file sources in media foundation</em> since the documentation in this front seems lacking in my mind. Below is some info on what I am doing and what approach I am working with right now but I have no idea if it is the correct way to use the framework.</p>
  
  <p>I am currently trying to use Microsoft Media Foundation to decode audio that I'm getting over Bluetooth and then send it along as PCM audio. When looking at the documentation for ms media foundation it seems that almost all examples assume the source is a file.</p>
  
  <p>Looking at the <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd757929(v=vs.85).aspx" rel="nofollow noreferrer">tutorial for decoding audio</a> for example they use <code>MFCreateSourceReaderFromURL</code>, which I cannot use since my source is not a file.</p>
  
  <p>As I wanted to follow the tutorial and change as little as possible Im thinking that I need only change how I create the source reader and the rest of the process would be the same. I looked at the other SourceReaders <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd389281(v=vs.85).aspx" rel="nofollow noreferrer">available</a> and <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd388106(v=vs.85).aspx" rel="nofollow noreferrer"><code>MFCreateSourceReaderFromByteStream</code></a> sounds about right for my purposes. </p>
  
  <p>Is there a chance that I only need to create a bytestream and continuously fill it with data that I get over the air as we go and the media source created by <code>MFCreateSourceReaderFromByteStream</code> handle this well? Or do I need to create a custom media source and do more manual work at the lower parts of the API to get something like this to work?</p>
  
  <p>Or maybe a source reader is the wrong approach altogether when the source is not a file? In the main page about Source Reader <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd940436(v=vs.85).aspx" rel="nofollow noreferrer">here</a> they have the following picture:</p>
  
  <p><a href="https://i.stack.imgur.com/lol3Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lol3Q.png" alt="Image describing what a Source Reader is"></a></p>
  
  <p>And this picture shows the media source within the source reader pointing to a source file only, is this a real limitation or simply and example?</p>
  
  <p>Im writing this in plain c, but pointing to c++ documentation or examples is fine as its usually pretty straightforward to translate c++ to c and there seems to be no documentation for c anyways.</p>
  
  <p><strong>Edit:</strong>
  Im adding a image on what kind of data Im getting, the red area being the chunks of data I refer to in comments below <a href="https://developer.apple.com/hardwaredrivers/BluetoothDesignGuidelines.pdf" rel="nofollow noreferrer">Source</a>.
  <a href="https://i.stack.imgur.com/nJ0Va.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nJ0Va.png" alt="enter image description here"></a></p>