title: How does the byte stream from VideoSink.OnSample look?
body: <p>In Silverlight, the <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.videosink.onsample%28v=vs.95%29.aspx" rel="nofollow"><code>VideoSink.OnSample</code></a> method is used to get raw webcam data. The function signature is as follows:</p>
  
  <pre><code>protected abstract void OnSample(
      long sampleTimeInHundredNanoseconds,
      long frameDurationInHundredNanoseconds,
      byte[] sampleData
  )
  </code></pre>
  
  <p>Documentation for <code>sampleData</code> says </p>
  
  <blockquote>
    <p>A byte stream that contains video data. The byte stream should be processed into samples according to the relevant video format information.</p>
  </blockquote>
  
  <p>Going to the documentation of the <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.videoformat%28v=vs.95%29.aspx" rel="nofollow"><code>VideoFormat</code></a> class, one gets to the <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.videoformat.pixelformat%28v=vs.95%29.aspx" rel="nofollow"><code>VideoFormat.PixelFormat</code></a> property which can only have two possible values according to the <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.pixelformattype%28v=vs.95%29.aspx" rel="nofollow">documentation</a>:</p>
  
  <blockquote>
    <ul>
    <li><strong>Unknown</strong> - The format is unknown.</li>
    <li><strong>Format32bppArgb</strong> - The format uses 32 bits of color information per pixel and reports color information by using alpha, red, blue, and green channels.</li>
    </ul>
  </blockquote>
  
  <p>I want to understand how the <code>sampleData</code> parameter for the <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.videosink.onsample%28v=vs.95%29.aspx" rel="nofollow"><code>VideoSink.OnSample</code></a> method looks like. Is it simply an array of pixels like the following?</p>
  
  <pre><code>sampleData[0] = image[x = 0, y = 0].R;
  sampleData[1] = image[x = 0, y = 0].G;
  sampleData[2] = image[x = 0, y = 0].B;
  sampleData[3] = image[x = 0, y = 0].A;
  sampleData[4 to 7] = image[x = 0, y = 1];
  sampleData[8 to 11] = image[x = 0, y = 2];
  sampleData[4*Height-4 to 4*Height-1] = image[x = 0, y = Height];
  sampleData[4*Height to 4*Height+3] = image[x = 1, y = 0];
  // ...
  </code></pre>
  
  <p>If it is that easy: Is the ordering correct?</p>
  
  <ul>
  <li>R before G before B before A for each pixel</li>
  <li>All pixels of first column before all pixels of second column and so on</li>
  </ul>