BDInfo.TSStreamFile.UpdateStreamBitrate C# (CSharp) 메소드

UpdateStreamBitrate() 개인적인 메소드

private UpdateStreamBitrate ( ushort PID, ushort PTSPID, ulong PTS, ulong PTSDiff ) : void
PID ushort
PTSPID ushort
PTS ulong
PTSDiff ulong
리턴 void
        private void UpdateStreamBitrate(
            ushort PID,
            ushort PTSPID,
            ulong PTS,
            ulong PTSDiff)
        {
            if (Playlists == null) return;

            TSStreamState streamState = StreamStates[PID];
            double streamTime = (double)PTS / 90000;
            double streamInterval = (double)PTSDiff / 90000;
            double streamOffset = streamTime + streamInterval;

            foreach (TSPlaylistFile playlist in Playlists)
            {
                foreach (TSStreamClip clip in playlist.StreamClips)
                {
                    if (clip.Name != this.Name) continue;

                    if (streamTime == 0 ||
                        (streamTime >= clip.TimeIn &&
                         streamTime <= clip.TimeOut))
                    {
                        clip.PayloadBytes += streamState.WindowBytes;
                        clip.PacketCount += streamState.WindowPackets;

                        if (streamOffset > clip.TimeIn &&
                            streamOffset - clip.TimeIn > clip.PacketSeconds)
                        {
                            clip.PacketSeconds = streamOffset - clip.TimeIn;
                        }

                        Dictionary<ushort, TSStream> playlistStreams = playlist.Streams;
                        if (clip.AngleIndex > 0 && 
                            clip.AngleIndex < playlist.AngleStreams.Count + 1)
                        {
                            playlistStreams = playlist.AngleStreams[clip.AngleIndex - 1];
                        }
                        if (playlistStreams.ContainsKey(PID))
                        {
                            TSStream stream = playlistStreams[PID];

                            stream.PayloadBytes += streamState.WindowBytes;
                            stream.PacketCount += streamState.WindowPackets;

                            if (stream.IsVideoStream)
                            {
                                stream.PacketSeconds += streamInterval;

                                stream.ActiveBitRate = (long)Math.Round(
                                    ((stream.PayloadBytes * 8.0) /
                                    stream.PacketSeconds));
                            }

                            if (stream.StreamType == TSStreamType.AC3_TRUE_HD_AUDIO &&
                                ((TSAudioStream)stream).CoreStream != null)
                            {
                                stream.ActiveBitRate -=
                                    ((TSAudioStream)stream).CoreStream.BitRate;
                            }
                        }
                    }
                }
            }

            if (Streams.ContainsKey(PID))
            {
                TSStream stream = Streams[PID];
                stream.PayloadBytes += streamState.WindowBytes;
                stream.PacketCount += streamState.WindowPackets;
                
                if (stream.IsVideoStream)
                {
                    TSStreamDiagnostics diag = new TSStreamDiagnostics();
                    diag.Marker = (double)PTS / 90000;
                    diag.Interval = (double)PTSDiff / 90000;
                    diag.Bytes = streamState.WindowBytes;
                    diag.Packets = streamState.WindowPackets;
                    diag.Tag = streamState.StreamTag;
                    StreamDiagnostics[PID].Add(diag);

                    stream.PacketSeconds += streamInterval;
                }
            }
            streamState.WindowPackets = 0;
            streamState.WindowBytes = 0;
        }