예제 #1
0
 public byte[] capture(AudioBuffer input)
 {
     if (IsSupported)
     {
         return(AcousticEchoCanceller.Capture(input.Data, input.Index, input.Length));
     }
     else
     {
         return(BitAssistant.SubArray(input.Data, input.Index, input.Length));
     }
 }
예제 #2
0
        private int ReadNextFrameLength()
        {
            while (true)
            {
                if (_StreamPosition == _BlockGroupEndPosition)
                {
                    _InBlockGroup          = false;
                    _BlockGroupEndPosition = -1;
                }

                if (_StreamPosition == _ClusterEndPosition)
                {
                    _InCluster          = false;
                    _ClusterEndPosition = -1;
                }

                if (_StreamPosition == _SegmentEndPosition)
                {
                    _InSegment          = false;
                    _SegmentEndPosition = -1;
                }

                var id = ReadId(_Stream);
                if (id.Length == 1 && id[0] == 0xFF)
                {
                    // end of stream
                    return(0);
                }
                if (!_HasEbml)
                {
                    if (Element.Compare(id, Ebml.EbmlId))
                    {
                        // read this in one block
                        _ = ReadValue(id);

                        _HasEbml = true;
                    }
                    else if (Element.Compare(id, EbmlCrc32Id))
                    {
                        // verify
                        ReadValue(id);
                    }
                    else if (Element.Compare(id, EbmlVoidId))
                    {
                        // ignore
                        ReadValue(id);
                    }
                    else
                    {
                        throw new NotImplementedException($"Unexpected ID '{BitAssistant.GetHexString(id)}' at stream offset '{_StreamPosition}'.");
                    }
                }
                else if (!_InSegment)
                {
                    if (Element.Compare(id, Segment.EbmlId))
                    {
                        // don't read the value
                        var segmentLength = ReadValueLength(id);
                        if (segmentLength != -1)
                        {
                            _SegmentEndPosition = _StreamPosition + segmentLength;
                        }

                        _InSegment = true;
                    }
                    else if (Element.Compare(id, EbmlCrc32Id))
                    {
                        // verify
                        ReadValue(id);
                    }
                    else if (Element.Compare(id, EbmlVoidId))
                    {
                        // ignore
                        ReadValue(id);
                    }
                    else
                    {
                        throw new NotImplementedException($"Unexpected ID '{BitAssistant.GetHexString(id)}' at stream offset '{_StreamPosition}'.");
                    }
                }
                else if (!_InCluster)
                {
                    if (Element.Compare(id, SegmentInfo.EbmlId))
                    {
                        _SegmentInfo = new SegmentInfo(ReadValue(id));
                    }
                    else if (Element.Compare(id, SeekHead.EbmlId))
                    {
                        _SeekHeads.Add(new SeekHead(ReadValue(id)));
                    }
                    else if (Element.Compare(id, Track.EbmlId))
                    {
                        _Tracks.Add(new Track(ReadValue(id)));
                    }
                    else if (Element.Compare(id, Cluster.EbmlId))
                    {
                        // don't read the value
                        var clusterLength = ReadValueLength(id);
                        if (clusterLength != -1)
                        {
                            _ClusterEndPosition = _StreamPosition + clusterLength;
                        }

                        _InCluster = true;

                        _ClusterTimecode = -1;
                        _ClusterPosition = -1;
                        _ClusterPrevSize = -1;
                    }
                    else if (Element.Compare(id, new byte[] { 0x12, 0x54, 0xC3, 0x67 }))
                    {
                        //TODO: Tags
                        ReadValue(id);
                    }
                    else if (Element.Compare(id, new byte[] { 0x1C, 0x53, 0xBB, 0x6B }))
                    {
                        //TODO: Cues
                        ReadValue(id);
                    }
                    else if (Element.Compare(id, EbmlCrc32Id))
                    {
                        // verify
                        ReadValue(id);
                    }
                    else if (Element.Compare(id, EbmlVoidId))
                    {
                        // ignore
                        ReadValue(id);
                    }
                    else
                    {
                        throw new NotImplementedException($"Unexpected ID '{BitAssistant.GetHexString(id)}' at stream offset '{_StreamPosition}'.");
                    }
                }
                else if (!_InBlockGroup)
                {
                    if (Element.Compare(id, EbmlClusterTimecodeId))
                    {
                        _ClusterTimecode = Element.ReadUnsignedInteger(ReadValue(id));
                    }
                    else if (Element.Compare(id, EbmlClusterPositionId))
                    {
                        _ClusterPosition = Element.ReadUnsignedInteger(ReadValue(id));
                    }
                    else if (Element.Compare(id, EbmlClusterPrevSizeId))
                    {
                        _ClusterPrevSize = Element.ReadUnsignedInteger(ReadValue(id));
                    }
                    else if (Element.Compare(id, BlockGroup.EbmlId))
                    {
                        // don't read the value
                        var blockGroupLength = ReadValueLength(id);
                        if (blockGroupLength != -1)
                        {
                            _BlockGroupEndPosition = _StreamPosition + blockGroupLength;
                        }

                        _InBlockGroup = true;

                        _ClusterBlockGroupReferenceBlocks.Clear();
                        _ClusterBlockGroupBlockDuration = -1;
                    }
                    else if (Element.Compare(id, SimpleBlock.EbmlId))
                    {
                        var frameLength = ReadFrameLength(id);
                        if (_ClusterBlockTrackNumber == 1)
                        {
                            return(frameLength);
                        }
                        Read(frameLength);
                    }
                    else if (Element.Compare(id, EbmlCrc32Id))
                    {
                        // verify
                        ReadValue(id);
                    }
                    else if (Element.Compare(id, EbmlVoidId))
                    {
                        // ignore
                        ReadValue(id);
                    }
                    else
                    {
                        throw new NotImplementedException($"Unexpected ID '{BitAssistant.GetHexString(id)}' at stream offset '{_StreamPosition}'.");
                    }
                }
                else
                {
                    if (Element.Compare(id, Block.EbmlId))
                    {
                        var frameLength = ReadFrameLength(id);
                        if (_ClusterBlockTrackNumber == 1)
                        {
                            return(frameLength);
                        }
                        Skip(frameLength);
                    }
                    else if (Element.Compare(id, EbmlBlockGroupReferenceBlockId))
                    {
                        _ClusterBlockGroupReferenceBlocks.Add(Element.ReadSignedInteger(ReadValue(id)));
                    }
                    else if (Element.Compare(id, EbmlBlockGroupBlockDurationId))
                    {
                        _ClusterBlockGroupBlockDuration = Element.ReadSignedInteger(ReadValue(id));
                    }
                    else if (Element.Compare(id, new byte[] { 0x75, 0xA1 }))
                    {
                        //TODO: BlockAdditions
                        ReadValue(id);
                    }
                    else if (Element.Compare(id, EbmlCrc32Id))
                    {
                        // verify
                        ReadValue(id);
                    }
                    else if (Element.Compare(id, EbmlVoidId))
                    {
                        // ignore
                        ReadValue(id);
                    }
                    else
                    {
                        throw new NotImplementedException($"Unexpected ID '{BitAssistant.GetHexString(id)}' at stream offset '{_StreamPosition}'.");
                    }
                }
            }
        }