我正在使用格式:
通过Barix InStreamer 100传输RTP音频流PCM 16Bit 8kHz Mono(Little endian)
我正在尝试播放"实时"通过使用自定义MediaStreamSource的MediaElement。问题是我在播放该流时会得到2秒的延迟。在我的电脑上有VLC,有#34;没有"延迟。
我发现,MediaStreamSource有一个属性" AudioBufferLength"女巫可以设置为15毫秒到1000毫秒之间的值。但是当值太小时,我在GetSampleAsync-> ReportGetSampleCompleted中有一个例外
这是我的代码:
protected override void GetSampleAsync(MediaStreamType mediaStreamType)
{
Debug.WriteLine("GetSampleAsync called.");
// Start with one second of data, rounded up to the nearest block.
var blocksize = (uint)AlignUp(_wavParser.WaveFormatEx.AvgBytesPerSec, _wavParser.WaveFormatEx.BlockAlign);
var chunkSize = Math.Min(blocksize, (uint)_stream.Length - _currentPosition);
var chunkDuration = _currentPosition * 10000000L / 8000; //// _wavParser.WaveFormatEx.AudioDurationFromBufferSize((uint)chunkSize);
// Send out the next sample
var chunkSample = new MediaStreamSample(_mediaStreamDescription, _stream, _currentPosition, chunkSize, _currentTimeStamp, chunkDuration, _emptySampleDict);
// Move our timestamp and position forward
_currentPosition += chunkSize;
_currentTimeStamp += chunkDuration;
ReportGetSampleCompleted(chunkSample); // <-- There i got a NullRef Ex, when the chunk is too small
}
这是我如何最初打开媒体:
protected override void OpenMediaAsync()
{
try
{
// Create a parser
_wavParser = new WavParser(_stream);
// Parse the header
_wavParser.ParseWaveHeader();
_wavParser.WaveFormatEx.ValidateWaveFormat();
_startPosition = _currentPosition = _wavParser.DataPosition;
// Init
_streamAttributes = new Dictionary<MediaStreamAttributeKeys, string>();
_sourceAttributes = new Dictionary<MediaSourceAttributesKeys, string>();
var availableStreams = new List<MediaStreamDescription>();
// Stream Description
_streamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = _wavParser.WaveFormatEx.ToHexString();
_mediaStreamDescription = new MediaStreamDescription(MediaStreamType.Audio, _streamAttributes);
availableStreams.Add(_mediaStreamDescription);
_sourceAttributes[MediaSourceAttributesKeys.Duration] = _wavParser.Duration.ToString();
ReportOpenMediaCompleted(_sourceAttributes, availableStreams);
}
catch (Exception exception)
{
Debug.WriteLine("Error while opening media source." + exception.Message);
}
}
有人可以给我一个提示吗?或者有更好的方法在WindowsPhone上实时播放RTP / PCM流(8)?请保存我的屁股:)