1

我试图让我的 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();
    }
}
4

1 回答 1

1

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

通常,最大分辨率和支持的视频编解码器取决于手机内部的 SoC 芯片,并在 MSDN 上针对 Windows Phone 7.x 和 8.0 进行了记录。

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

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

于 2012-12-03T18:33:28.037 回答