none
MediaStreamSource 执行的疑问 RRS feed

  • 问题

  • 当我的H264视频码流只有一帧时

    OpenMediaAsync()方法里调用ReportOpenMediaCompleted事件

    1.只是我不明白,为什么一帧数据会调用N次GetSampleAsync方法

    GetSampleAsync方法里的MediaStreamSample是如何确定的?

    2.API说:调用 ReportGetSampleCompleted( null ) 将通知 MediaElement 流已结束。在通知流已结束后,MediaElement 将开始转换到 PausedStopped 状态。

    可我ReportGetSampleCompleted( null ) 这样用时,报NullReferenceException。这是为什么

     

    谁明白求一个答案?

     

    2011年9月2日 6:37

全部回复

  • 你好,

    能否显示相关代码以便我们可以测试一下。

    谢谢!


    Daoping Liu - MSFT
    2011年9月6日 11:49
    版主
  • 解码类:

    Stream _mediaStream;

            Dictionary<MediaStreamAttributeKeys, string> _mediaStreamAttributes = new Dictionary<MediaStreamAttributeKeys, string>();
            Dictionary<MediaSampleAttributeKeys, string> _mediaSampleAttributes = new Dictionary<MediaSampleAttributeKeys, string>();
            List<MediaStreamDescription> _mediaStreamDescriptions = new List<MediaStreamDescription>();

            public H264(Stream stream)
            {
                this._mediaStream = stream;
            }

            protected override void OpenMediaAsync()
            {

                //Video  
                _mediaStreamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = "";
                _mediaStreamAttributes[MediaStreamAttributeKeys.VideoFourCC] = "H264";
                _mediaStreamDescriptions.Add(new MediaStreamDescription(MediaStreamType.Video, _mediaStreamAttributes));

                //Media
                Dictionary<MediaSourceAttributesKeys, string> mediaSourceAttributes = new Dictionary<MediaSourceAttributesKeys, string>();
                mediaSourceAttributes[MediaSourceAttributesKeys.Duration] = TimeSpan.FromMilliseconds(1).Ticks.ToString(CultureInfo.InvariantCulture);
                mediaSourceAttributes[MediaSourceAttributesKeys.CanSeek] = false.ToString();

     

                this.ReportOpenMediaCompleted(mediaSourceAttributes, _mediaStreamDescriptions);
            }


            protected override void GetSampleAsync(MediaStreamType mediaStreamType)
            {
               System.Diagnostics.Debug.WriteLine(_mediaStream.Length);
                MediaStreamSample mediaStreamSample = null;
                if (mediaStreamType == MediaStreamType.Video)
                    mediaStreamSample = this.GetVideoSample();
               
                ReportGetSampleCompleted(mediaStreamSample);
                return;

            }

            private MediaStreamSample GetVideoSample()
            {
                MediaStreamDescription msd = new MediaStreamDescription(MediaStreamType.Video, _mediaStreamAttributes);
                MediaStreamSample mediaStreamSample = new MediaStreamSample(msd, _mediaStream, 0, _mediaStream.Length, TimeSpan.FromMilliseconds(0).Ticks, _mediaSampleAttributes);
                return mediaStreamSample;
            }

    2011年9月7日 1:03