OnAudio() public method

public OnAudio ( RTMPMessage msg ) : void
msg PeerCastStation.FLV.RTMP.RTMPMessage
return void
コード例 #1
0
        public ParsedContent Read(Stream stream)
        {
            var processed = false;
            var eos       = false;

            while (!eos)
            {
                var start_pos = stream.Position;
                try {
                    switch (state)
                    {
                    case ReaderState.Header:
                    {
                        var bin    = ReadBytes(stream, 13);
                        var header = new FileHeader(bin);
                        if (header.IsValid)
                        {
                            Logger.Info("FLV Header found");
                            contentBuffer.OnStart();
                            state = ReaderState.Body;
                        }
                        else
                        {
                            throw new BadDataException();
                        }
                    }
                    break;

                    case ReaderState.Body:
                    {
                        var bin        = ReadBytes(stream, 11);
                        var read_valid = false;
                        var body       = new FLVTag(bin);
                        if (body.IsValidHeader)
                        {
                            body.ReadBody(stream);
                            body.ReadFooter(stream);
                            if (body.IsValidFooter)
                            {
                                read_valid = true;
                                switch (body.Type)
                                {
                                case FLVTag.TagType.Audio:
                                    contentBuffer.OnAudio(body.ToRTMPMessage());
                                    break;

                                case FLVTag.TagType.Video:
                                    contentBuffer.OnVideo(body.ToRTMPMessage());
                                    break;

                                case FLVTag.TagType.Script:
                                    contentBuffer.OnData(new RTMP.DataAMF0Message(body.ToRTMPMessage()));
                                    break;
                                }
                            }
                        }
                        if (!read_valid)
                        {
                            stream.Position = start_pos;
                            var header = new FileHeader(ReadBytes(stream, 13));
                            if (header.IsValid)
                            {
                                Logger.Info("New FLV Header found");
                                read_valid = true;
                                contentBuffer.OnStart();
                            }
                        }
                        if (!read_valid)
                        {
                            throw new BadDataException();
                        }
                    }
                    break;
                    }
                    processed = true;
                }
                catch (EndOfStreamException) {
                    if (!processed)
                    {
                        throw;
                    }
                    stream.Position = start_pos;
                    eos             = true;
                }
                catch (BadDataException) {
                    stream.Position = start_pos + 1;
                }
            }
            return(contentBuffer.GetContents());
        }