How do I detect whether the sample supplied by VideoSink.OnSample() is right-side up?

Posted by Ken Smith on Stack Overflow See other posts from Stack Overflow or by Ken Smith
Published on 2010-03-29T19:15:08Z Indexed on 2010/03/29 20:03 UTC
Read the original article Hit count: 444

We're currently using the Silverlight VideoSink to capture video from users' local webcams, kinda like so:

    protected override void OnSample(long sampleTime, long frameDuration, byte[] sampleData)
    {
        if (FrameShouldBeSubmitted())
        {
            byte[] resampledData = ResizeFrame(sampleData);
            mediaController.SetVideoFrame(resampledData);
        }
    }

Now, on most of the machines that we've tested, the video sample provided in the byte[] sampleData parameter is upside-down, i.e., if you try to take the RGBA data and turn it into, say, a WriteableBitmap, the bitmap will be upside-down. That's odd, but fairly easy to correct, of course -- you just have to reverse the array as you encode it.

The problem is that at least on some machines (e.g., the single Macintosh in our test environment), the video sample provided is no longer upside-down, but right-side up, and hence, flipping the image actually results in an image that's received upside-down on the far side.

I reported this to MS as a bug, but their (terse) response was that it was "As Designed". Further attempts at clarification have so far been ignored.

Now, I'll grant that it's kinda entertaining to imagine the discussions behind this design decision: "OK, just to make it interesting, let's play the video rightside up on a Mac, but let's turn it upside down for Windows!" "Great idea!" "Yeah, that'll keep those developers guessing!" But beyond that, I can't find this, umm, "feature" documented anywhere, nor can I find any documentation on how one is supposed to be able to tell that a given video sample is upside down or rightside up. Any thoughts on how to tell this?

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about silverlight-4.0