在Silverlight上播放AAC原始数据的问题(Windows Phone)

时间:2013-06-20 13:13:37

标签: c# silverlight windows-phone mediastreamsource

我需要播放来自直播的AAC LC音频。 为了实现我已经实现了MediaStreamSource。

当我收到第一个流包时,我将MediaElement的源设置为我的MediaStreamSource。 似乎一切正常:OpenMediaAsync被称为 - >使用ReportOpenMediaCompleted报告,然后调用GetSampleAsync - >使用ReportGetSampleCompleted报告,但是,在第10次调用GetSampleAsync时,ReportGetSampleCompleted会抛出NullReferenceException。

这是我的CodecPrivateData:

var waveFormat = new AACWaveFormat();
waveFormat.FormatTag = 0xFF;
waveFormat.Channels = 2; // For my stream is always stereo
waveFormat.Frequency = 44100; //For my stream is always 44Khz
waveFormat.BitsPerSample = 16;  //For my stream is always 16bit
waveFormat.BlockAlign = waveFormat.Channels * waveFormat.BitsPerSample / 8; //is this true formula?
waveFormat.AverageBytesPerSecond = waveFormat.Frequency * waveFormat.BlockAlign; //is this true formula?  because usually this value is 176400 or 1411Kbps is this real value for sound?
waveFormat.ExtraDataSize = 2; //usually, but i read these values from first packet of stream
waveFormat.ExtraData = AudioSpecificConfig; //AudioSpecificConfig usually 2 bytes length, readed from stream.

流的第一个数据包始终是AACSequenceHeader - 我在那里读取了我的CodecPrivateData和AudioSpecificConfig。其余的都是AACRaw。

我的CodecPrivateData看起来像 FF00020044AC000010B102000400100002001210

我的GetSampleAsync

protected override void GetSampleAsync(MediaStreamType mediaStreamType)
{
    var audioStreamDescription = new MediaStreamDescription(MediaStreamType.Audio, AudioStreamAttibutes);  //AudioStreamAttibutes is field that contains data filled on OpenMediaAsync step.
    //using (var memoryStream = new MemoryStream(AudioPackets[0].Data))
    var memoryStream = new MemoryStream(AudioPackets[0].Data);
    ReportGetSampleCompleted(new MediaStreamSample(audioStreamDescription, memoryStream, 0, AudioPackets[0].Data.Length, TimeSpan.FromMilliseconds(GetAudioSampleCalls++ * 32).Ticks, new Dictionary<MediaSampleAttributeKeys, String>()));  //throws NullReferenceException, when debugger stops i can be see that all passed params is not null!
}

这里的问题是我不知道任何时间戳,我不知道这是否是一个问题。

最后什么是Data字段? Data字段包含我从AudioTag中提取的所有收到的RawAAC音频Byte[]。 (请参阅http://download.macromedia.com/f4v/video_file_format_spec_v10_1.pdf上的E.4.2.2 AACAUDIODATA

0 个答案:

没有答案