WP7 RGBA MediaStreamSource立即关闭 - 高分辨率

时间:2012-12-03 15:46:19

标签: c# silverlight windows-phone-7

我正在尝试让我的MediaStreamSource在Windows Phone 7.1上运行。 对于较小的分辨率,如256 * 256或512 * 512,它可以工作,但在某种程度上,它在我调用ReportOpenMediaCompleted后立即关闭。 我没有任何例外等等。

这是我的代码:

public class BitmapStreamSource : MediaStreamSource
{
    MediaStreamDescription bitmapMediaStream;
    const int width = 1024;
    const int height = 1024;


    protected override void OpenMediaAsync()
    {
        Dictionary<MediaSourceAttributesKeys, string> mediaStreamAttributes;

        List<MediaStreamDescription> availableMediaStreams;
        Dictionary<MediaStreamAttributeKeys, string> bitmapStreamAttributes;


        mediaStreamAttributes = new Dictionary<MediaSourceAttributesKeys, string>(2);
        mediaStreamAttributes[MediaSourceAttributesKeys.CanSeek] = false.ToString();
        mediaStreamAttributes[MediaSourceAttributesKeys.Duration] = "-1";


        bitmapStreamAttributes = new Dictionary<MediaStreamAttributeKeys,string>(3);
        bitmapStreamAttributes[MediaStreamAttributeKeys.VideoFourCC]= "RGBA";
        bitmapStreamAttributes[MediaStreamAttributeKeys.Width]= width.ToString();
        bitmapStreamAttributes[MediaStreamAttributeKeys.Height] = height.ToString();

        bitmapMediaStream = new MediaStreamDescription(MediaStreamType.Video, bitmapStreamAttributes);
        availableMediaStreams = new List<MediaStreamDescription>(1);
        availableMediaStreams.Add(bitmapMediaStream);


        ReportOpenMediaCompleted(mediaStreamAttributes, availableMediaStreams);
    }

    protected override void SeekAsync(long seekToTime)
    {
        ReportSeekCompleted(seekToTime);
    }

    int sampleCount = 0;
    protected override void GetSampleAsync(MediaStreamType mediaStreamType)
    {
            int pixel = width * height;
            var buffer = new byte[pixel * 4];

            for (int i = 0; i < pixel; i++)
            {
                byte value = (byte)((i + sampleCount) % 256);

                var k = i * 4;
                //buffer[k] = 255; // B
                buffer[k + 1] = value; // G
                buffer[k + 2] = 255; // R
                //buffer[k + 3] = value; // A
            }


            var stream = new MemoryStream(buffer);

            var keys = new Dictionary<MediaSampleAttributeKeys, string>();
            var sample = new MediaStreamSample(bitmapMediaStream, stream, 0, buffer.Length, 0, keys);

            sampleCount++;
            ReportGetSampleCompleted(sample);
    }

    protected override void CloseMedia()
    {
        Debug.WriteLine("CloseMedia()");
    }

    protected override void GetDiagnosticAsync(MediaStreamSourceDiagnosticKind diagnosticKind)
    {
        throw new NotImplementedException();
    }

    protected override void SwitchMediaStreamAsync(MediaStreamDescription mediaStreamDescription)
    {
        throw new NotImplementedException();
    }
}

1 个答案:

答案 0 :(得分:1)

您将超越Windows Phone 7.x设备(或模拟器)的媒体功能。

通常,支持的最大分辨率和视频编解码器取决于手机内部的SoC芯片,并且对于Windows Phone 7.x和8.0都记录为here on MSDN

特别是Windows Phone 7.x手机内的芯片通常将分辨率限制在1280x720或800x480分辨率。 Windows Phone 8手机可能支持更高的分辨率。

如果您使用仿真器,这会变得更复杂 - 它通常会模拟典型的设备功能,但您需要测试媒体在真实设备上的行为以确定。