Exemplo n.º 1
0
        public MSF.AudioBlock ParseAudioBlock(int offset, Stream _stream)
        {
            _stream.Seek(offset, SeekOrigin.Begin);
            byte[]         tmp = new byte[4];
            MSF.AudioBlock ab  = new MSF.AudioBlock();
            _stream.Read(tmp, 0, 1);
            ab.AudioFrameNum          = (uint)BitTools.MaskBits(tmp, 0, 8);
            ab.AudioBlockHeaderLength = ab.AudioFrameNum * 5 + 1;

            uint addr = (uint)offset + ab.AudioBlockHeaderLength + CRC_Size;

            for (int i = 0; i < ab.AudioFrameNum; i++)
            {
                //读音频参数集
                MSF.AudioBlock.AudioFrame f = new MSF.AudioBlock.AudioFrame();
                _stream.Read(tmp, 0, 2);
                f.RelativeStartAddr = addr;
                f.Length            = (uint)BitTools.MaskBits(tmp, 0, 16);
                // skip 音频流编号 和 保留
                _stream.Seek(1, SeekOrigin.Current);

                // 读相对时间
                _stream.Read(tmp, 0, 2);
                f.RelativeTime = BitTools.MaskBits(tmp, 0, 16) * timeUint;

                // copy 音频流
                //f._as = BitTools.CopyToNewStream(_stream, (long)f.RelativeStartAddr, (int)f.Length);
                BitTools.CopyFromStreamToBytesArray(_stream, (long)f.RelativeStartAddr, (int)f.Length, ref f._data);

                ab.aFrames.Add(f);
                //下一段音频地址
                addr += f.Length;
            }
            return(ab);
        }
Exemplo n.º 2
0
        private MediaStreamSample GetAudioSample2()
        {
            MediaStreamSample sample = new MediaStreamSample(this.audioStreamDescription, null, 0, 0, 0, emptyDict);

            if (m_AmediaStreamEnd)
            {
                return(sample);
            }

            if (aIdx > (aNum - 1))
            {
                // free current video block
                m_curAudioBlk = null;
                m_abuffer.WaitForWorkItem();

                m_curAudioBlk = (MSF.AudioBlock)m_abuffer.Dequeue().CommandParameter;
                if (m_curAudioBlk != null)
                {
                    if (m_abuffer.Count() == 0)
                    {
                        m_aBufferFullEvent.Reset();
                    }

                    aIdx = 0;
                    aNum = (int)m_curAudioBlk.AudioFrameNum;
                }
                else
                {
                    m_AmediaStreamEnd = true;
                    return(sample);
                }
            }

            MemoryStream aStream = new MemoryStream();
            //LATM 封装,第一个字节是length, 跳过第一个字节, 相应的长度应该减1
            int len = (int)m_curAudioBlk.aFrames[aIdx].Length - 1;

            aStream.Write(m_curAudioBlk.aFrames[aIdx]._data, 1, len);

            MediaStreamSample mediaStreamSample = new MediaStreamSample
                                                  (
                this.audioStreamDescription,
                aStream,
                0,
                len,
                m_curAudioBlk.aFrames[aIdx].RelativeTime,   //// 以100 纳秒为单位
                emptyDict
                                                  );

            aIdx++;

            return(mediaStreamSample);
        }
Exemplo n.º 3
0
        private MediaStreamSample GetAudioSample2()
        {
            MediaStreamSample sample = new MediaStreamSample(this.audioStreamDescription, null, 0, 0, 0, emptyDict);

            if (m_AmediaStreamEnd)
                return sample;

            if (aIdx > (aNum - 1))
            {
                // free current video block
                m_curAudioBlk = null;
                m_abuffer.WaitForWorkItem();

                m_curAudioBlk = (MSF.AudioBlock)m_abuffer.Dequeue().CommandParameter ;
                if (m_curAudioBlk != null)
                {
                    if (m_abuffer.Count() == 0)
                        m_aBufferFullEvent.Reset();

                    aIdx = 0;
                    aNum = (int)m_curAudioBlk.AudioFrameNum;
                }
                else
                {
                    m_AmediaStreamEnd = true;
                    return sample;
                }
            }

            MemoryStream aStream = new MemoryStream();
            //LATM 封装,第一个字节是length, 跳过第一个字节, 相应的长度应该减1
            int len = (int)m_curAudioBlk.aFrames[aIdx].Length - 1;
            aStream.Write(m_curAudioBlk.aFrames[aIdx]._data, 1, len);

            MediaStreamSample mediaStreamSample = new MediaStreamSample
                (
                this.audioStreamDescription,
                aStream,
                0,
                len,
                m_curAudioBlk.aFrames[aIdx].RelativeTime,   //// 以100 纳秒为单位
                emptyDict
                );
            aIdx++;

            return mediaStreamSample;
        }
Exemplo n.º 4
0
        public MSF.AudioBlock ParseAudioBlock(int offset, Stream _stream)
        {
            _stream.Seek(offset, SeekOrigin.Begin);
            byte[] tmp = new byte[4];
            MSF.AudioBlock ab = new MSF.AudioBlock();
            _stream.Read(tmp, 0, 1);
            ab.AudioFrameNum = (uint)BitTools.MaskBits(tmp, 0, 8);
            ab.AudioBlockHeaderLength = ab.AudioFrameNum * 5 +1;

            uint addr = (uint)offset + ab.AudioBlockHeaderLength + CRC_Size;
            for (int i = 0; i < ab.AudioFrameNum; i++)
            {
                //读音频参数集
                MSF.AudioBlock.AudioFrame f = new MSF.AudioBlock.AudioFrame();
                _stream.Read(tmp, 0, 2);
                f.RelativeStartAddr = addr;
                f.Length = (uint)BitTools.MaskBits(tmp, 0, 16);
                // skip 音频流编号 和 保留
                _stream.Seek(1, SeekOrigin.Current);

                // 读相对时间
                _stream.Read(tmp, 0, 2);
                f.RelativeTime = BitTools.MaskBits(tmp, 0, 16) * timeUint;

                // copy 音频流
                //f._as = BitTools.CopyToNewStream(_stream, (long)f.RelativeStartAddr, (int)f.Length);
                BitTools.CopyFromStreamToBytesArray(_stream, (long)f.RelativeStartAddr, (int)f.Length, ref f._data);

                ab.aFrames.Add(f);
                //下一段音频地址
                addr += f.Length;
            }
            return ab;
        }