Ejemplo n.º 1
0
        public override TSStream Clone()
        {
            TSAudioStream stream = new TSAudioStream();

            CopyTo(stream);

            stream.SampleRate    = SampleRate;
            stream.ChannelLayout = ChannelLayout;
            stream.ChannelCount  = ChannelCount;
            stream.BitDepth      = BitDepth;
            stream.LFE           = LFE;
            stream.DialNorm      = DialNorm;
            stream.AudioMode     = AudioMode;
            if (CoreStream != null)
            {
                stream.CoreStream = (TSAudioStream)CoreStream.Clone();
            }

            return(stream);
        }
Ejemplo n.º 2
0
        public override TSStream Clone()
        {
            TSAudioStream stream = new TSAudioStream();
            CopyTo(stream);

            stream.SampleRate = SampleRate;
            stream.ChannelLayout = ChannelLayout;
            stream.ChannelCount = ChannelCount;
            stream.BitDepth = BitDepth;
            stream.LFE = LFE;
            stream.DialNorm = DialNorm;
            stream.AudioMode = AudioMode;
            if (CoreStream != null)
            {
                stream.CoreStream = (TSAudioStream)CoreStream.Clone();
            }

            return stream;
        }
Ejemplo n.º 3
0
        private void LoadStreamClips()
        {
            AngleClips.Clear();
            if (AngleCount > 0)
            {
                for (int angleIndex = 0; angleIndex < AngleCount; angleIndex++)
                {
                    AngleClips.Add(new Dictionary <double, TSStreamClip>());
                }
            }

            TSStreamClip referenceClip = null;

            if (StreamClips.Count > 0)
            {
                referenceClip = StreamClips[0];
            }
            foreach (TSStreamClip clip in StreamClips)
            {
                if (clip.StreamClipFile.Streams.Count > referenceClip.StreamClipFile.Streams.Count)
                {
                    referenceClip = clip;
                }
                else if (clip.Length > referenceClip.Length)
                {
                    referenceClip = clip;
                }
                if (AngleCount > 0)
                {
                    if (clip.AngleIndex == 0)
                    {
                        for (int angleIndex = 0; angleIndex < AngleCount; angleIndex++)
                        {
                            AngleClips[angleIndex][clip.RelativeTimeIn] = clip;
                        }
                    }
                    else
                    {
                        AngleClips[clip.AngleIndex - 1][clip.RelativeTimeIn] = clip;
                    }
                }
            }

            foreach (TSStream clipStream
                     in referenceClip.StreamClipFile.Streams.Values)
            {
                if (!Streams.ContainsKey(clipStream.PID))
                {
                    TSStream stream = clipStream.Clone();
                    Streams[clipStream.PID] = stream;

                    if (!IsCustom && !PlaylistStreams.ContainsKey(stream.PID))
                    {
                        stream.IsHidden = true;
                        HasHiddenTracks = true;
                    }

                    if (stream.IsVideoStream)
                    {
                        VideoStreams.Add((TSVideoStream)stream);
                    }
                    else if (stream.IsAudioStream)
                    {
                        AudioStreams.Add((TSAudioStream)stream);
                    }
                    else if (stream.IsGraphicsStream)
                    {
                        GraphicsStreams.Add((TSGraphicsStream)stream);
                    }
                    else if (stream.IsTextStream)
                    {
                        TextStreams.Add((TSTextStream)stream);
                    }
                }
            }

            if (referenceClip.StreamFile != null)
            {
                // TODO: Better way to add this in?
                if (BDInfoSettings.EnableSSIF &&
                    referenceClip.StreamFile.InterleavedFile != null &&
                    referenceClip.StreamFile.Streams.ContainsKey(4114) &&
                    !Streams.ContainsKey(4114))
                {
                    TSStream stream = referenceClip.StreamFile.Streams[4114].Clone();
                    Streams[4114] = stream;
                    if (stream.IsVideoStream)
                    {
                        VideoStreams.Add((TSVideoStream)stream);
                    }
                }

                foreach (TSStream clipStream
                         in referenceClip.StreamFile.Streams.Values)
                {
                    if (Streams.ContainsKey(clipStream.PID))
                    {
                        TSStream stream = Streams[clipStream.PID];

                        if (stream.StreamType != clipStream.StreamType)
                        {
                            continue;
                        }

                        if (clipStream.BitRate > stream.BitRate)
                        {
                            stream.BitRate = clipStream.BitRate;
                        }
                        stream.IsVBR = clipStream.IsVBR;

                        if (stream.IsVideoStream &&
                            clipStream.IsVideoStream)
                        {
                            ((TSVideoStream)stream).EncodingProfile =
                                ((TSVideoStream)clipStream).EncodingProfile;
                        }
                        else if (stream.IsAudioStream &&
                                 clipStream.IsAudioStream)
                        {
                            TSAudioStream audioStream     = (TSAudioStream)stream;
                            TSAudioStream clipAudioStream = (TSAudioStream)clipStream;

                            if (clipAudioStream.ChannelCount > audioStream.ChannelCount)
                            {
                                audioStream.ChannelCount = clipAudioStream.ChannelCount;
                            }
                            if (clipAudioStream.LFE > audioStream.LFE)
                            {
                                audioStream.LFE = clipAudioStream.LFE;
                            }
                            if (clipAudioStream.SampleRate > audioStream.SampleRate)
                            {
                                audioStream.SampleRate = clipAudioStream.SampleRate;
                            }
                            if (clipAudioStream.BitDepth > audioStream.BitDepth)
                            {
                                audioStream.BitDepth = clipAudioStream.BitDepth;
                            }
                            if (clipAudioStream.DialNorm < audioStream.DialNorm)
                            {
                                audioStream.DialNorm = clipAudioStream.DialNorm;
                            }
                            if (clipAudioStream.AudioMode != TSAudioMode.Unknown)
                            {
                                audioStream.AudioMode = clipAudioStream.AudioMode;
                            }
                            if (clipAudioStream.CoreStream != null &&
                                audioStream.CoreStream == null)
                            {
                                audioStream.CoreStream = (TSAudioStream)
                                                         clipAudioStream.CoreStream.Clone();
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < AngleCount; i++)
            {
                AngleStreams.Add(new Dictionary <ushort, TSStream>());
            }

            if (!BDInfoSettings.KeepStreamOrder)
            {
                VideoStreams.Sort(CompareVideoStreams);
            }
            foreach (TSStream stream in VideoStreams)
            {
                SortedStreams.Add(stream);
                for (int i = 0; i < AngleCount; i++)
                {
                    TSStream angleStream = stream.Clone();
                    angleStream.AngleIndex           = i + 1;
                    AngleStreams[i][angleStream.PID] = angleStream;
                    SortedStreams.Add(angleStream);
                }
            }

            if (!BDInfoSettings.KeepStreamOrder)
            {
                AudioStreams.Sort(CompareAudioStreams);
            }
            foreach (TSStream stream in AudioStreams)
            {
                SortedStreams.Add(stream);
            }

            if (!BDInfoSettings.KeepStreamOrder)
            {
                GraphicsStreams.Sort(CompareGraphicsStreams);
            }
            foreach (TSStream stream in GraphicsStreams)
            {
                SortedStreams.Add(stream);
            }

            if (!BDInfoSettings.KeepStreamOrder)
            {
                TextStreams.Sort(CompareTextStreams);
            }
            foreach (TSStream stream in TextStreams)
            {
                SortedStreams.Add(stream);
            }
        }
Ejemplo n.º 4
0
        protected TSStream CreatePlaylistStream(byte[] data, ref int pos)
        {
            TSStream stream = null;

            int start = pos;

            int headerLength = data[pos++];
            int headerPos    = pos;
            int headerType   = data[pos++];

            int pid       = 0;
            int subpathid = 0;
            int subclipid = 0;

            switch (headerType)
            {
            case 1:
                pid = ReadInt16(data, ref pos);
                break;

            case 2:
                subpathid = data[pos++];
                subclipid = data[pos++];
                pid       = ReadInt16(data, ref pos);
                break;

            case 3:
                subpathid = data[pos++];
                pid       = ReadInt16(data, ref pos);
                break;

            case 4:
                subpathid = data[pos++];
                subclipid = data[pos++];
                pid       = ReadInt16(data, ref pos);
                break;

            default:
                break;
            }

            pos = headerPos + headerLength;

            int streamLength = data[pos++];
            int streamPos    = pos;

            TSStreamType streamType = (TSStreamType)data[pos++];

            switch (streamType)
            {
            case TSStreamType.MVC_VIDEO:
                // TODO
                break;

            case TSStreamType.AVC_VIDEO:
            case TSStreamType.MPEG1_VIDEO:
            case TSStreamType.MPEG2_VIDEO:
            case TSStreamType.VC1_VIDEO:

                TSVideoFormat videoFormat = (TSVideoFormat)
                                            (data[pos] >> 4);
                TSFrameRate frameRate = (TSFrameRate)
                                        (data[pos] & 0xF);
                TSAspectRatio aspectRatio = (TSAspectRatio)
                                            (data[pos + 1] >> 4);

                stream = new TSVideoStream();
                ((TSVideoStream)stream).VideoFormat = videoFormat;
                ((TSVideoStream)stream).AspectRatio = aspectRatio;
                ((TSVideoStream)stream).FrameRate   = frameRate;

#if DEBUG
                Debug.WriteLine(string.Format(
                                    "\t{0} {1} {2} {3} {4}",
                                    pid,
                                    streamType,
                                    videoFormat,
                                    frameRate,
                                    aspectRatio));
#endif

                break;

            case TSStreamType.AC3_AUDIO:
            case TSStreamType.AC3_PLUS_AUDIO:
            case TSStreamType.AC3_PLUS_SECONDARY_AUDIO:
            case TSStreamType.AC3_TRUE_HD_AUDIO:
            case TSStreamType.DTS_AUDIO:
            case TSStreamType.DTS_HD_AUDIO:
            case TSStreamType.DTS_HD_MASTER_AUDIO:
            case TSStreamType.DTS_HD_SECONDARY_AUDIO:
            case TSStreamType.LPCM_AUDIO:
            case TSStreamType.MPEG1_AUDIO:
            case TSStreamType.MPEG2_AUDIO:

                int audioFormat = ReadByte(data, ref pos);

                TSChannelLayout channelLayout = (TSChannelLayout)
                                                (audioFormat >> 4);
                TSSampleRate sampleRate = (TSSampleRate)
                                          (audioFormat & 0xF);

                string audioLanguage = ReadString(data, 3, ref pos);

                stream = new TSAudioStream();
                ((TSAudioStream)stream).ChannelLayout = channelLayout;
                ((TSAudioStream)stream).SampleRate    = TSAudioStream.ConvertSampleRate(sampleRate);
                ((TSAudioStream)stream).LanguageCode  = audioLanguage;

#if DEBUG
                Debug.WriteLine(string.Format(
                                    "\t{0} {1} {2} {3} {4}",
                                    pid,
                                    streamType,
                                    audioLanguage,
                                    channelLayout,
                                    sampleRate));
#endif

                break;

            case TSStreamType.INTERACTIVE_GRAPHICS:
            case TSStreamType.PRESENTATION_GRAPHICS:

                string graphicsLanguage = ReadString(data, 3, ref pos);

                stream = new TSGraphicsStream();
                ((TSGraphicsStream)stream).LanguageCode = graphicsLanguage;

                if (data[pos] != 0)
                {
                }

#if DEBUG
                Debug.WriteLine(string.Format(
                                    "\t{0} {1} {2}",
                                    pid,
                                    streamType,
                                    graphicsLanguage));
#endif

                break;

            case TSStreamType.SUBTITLE:

                int    code         = ReadByte(data, ref pos); // TODO
                string textLanguage = ReadString(data, 3, ref pos);

                stream = new TSTextStream();
                ((TSTextStream)stream).LanguageCode = textLanguage;

#if DEBUG
                Debug.WriteLine(string.Format(
                                    "\t{0} {1} {2}",
                                    pid,
                                    streamType,
                                    textLanguage));
#endif

                break;

            default:
                break;
            }

            pos = streamPos + streamLength;

            if (stream != null)
            {
                stream.PID        = (ushort)pid;
                stream.StreamType = streamType;
            }

            return(stream);
        }
Ejemplo n.º 5
0
        public static int CompareAudioStreams(
            TSAudioStream x,
            TSAudioStream y)
        {
            if (x == y)
            {
                return(0);
            }
            else if (x == null && y == null)
            {
                return(0);
            }
            else if (x == null && y != null)
            {
                return(-1);
            }
            else if (x != null && y == null)
            {
                return(1);
            }
            else
            {
                if (x.ChannelCount > y.ChannelCount)
                {
                    return(-1);
                }
                else if (y.ChannelCount > x.ChannelCount)
                {
                    return(1);
                }
                else
                {
                    int sortX = GetStreamTypeSortIndex(x.StreamType);
                    int sortY = GetStreamTypeSortIndex(y.StreamType);

                    if (sortX > sortY)
                    {
                        return(-1);
                    }
                    else if (sortY > sortX)
                    {
                        return(1);
                    }
                    else
                    {
                        if (x.LanguageCode == "eng")
                        {
                            return(-1);
                        }
                        else if (y.LanguageCode == "eng")
                        {
                            return(1);
                        }
                        else if (x.LanguageCode != y.LanguageCode)
                        {
                            return(string.Compare(
                                       x.LanguageName, y.LanguageName));
                        }
                        else if (x.PID < y.PID)
                        {
                            return(-1);
                        }
                        else if (y.PID < x.PID)
                        {
                            return(1);
                        }
                        return(0);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public static void Scan(
            TSAudioStream stream,
            TSStreamBuffer buffer,
            ref string tag)
        {
            if (stream.IsInitialized)
            {
                return;
            }

            byte[] sync = buffer.ReadBytes(2);
            if (sync == null ||
                sync[0] != 0x0B ||
                sync[1] != 0x77)
            {
                return;
            }

            int sr_code         = 0;
            int frame_size      = 0;
            int frame_size_code = 0;
            int channel_mode    = 0;
            int lfe_on          = 0;
            int dial_norm       = 0;
            int num_blocks      = 0;

            byte[] hdr  = buffer.ReadBytes(4);
            int    bsid = (hdr[3] & 0xF8) >> 3;

            buffer.Seek(-4, SeekOrigin.Current);
            if (bsid <= 10)
            {
                byte[] crc = buffer.ReadBytes(2);
                sr_code         = buffer.ReadBits(2);
                frame_size_code = buffer.ReadBits(6);
                bsid            = buffer.ReadBits(5);
                int bsmod = buffer.ReadBits(3);

                channel_mode = buffer.ReadBits(3);
                int cmixlev = 0;
                if (((channel_mode & 0x1) > 0) && (channel_mode != 0x1))
                {
                    cmixlev = buffer.ReadBits(2);
                }
                int surmixlev = 0;
                if ((channel_mode & 0x4) > 0)
                {
                    surmixlev = buffer.ReadBits(2);
                }
                int dsurmod = 0;
                if (channel_mode == 0x2)
                {
                    dsurmod = buffer.ReadBits(2);
                    if (dsurmod == 0x2)
                    {
                        stream.AudioMode = TSAudioMode.Surround;
                    }
                }
                lfe_on    = buffer.ReadBits(1);
                dial_norm = buffer.ReadBits(5);
                int compr = 0;
                if (1 == buffer.ReadBits(1))
                {
                    compr = buffer.ReadBits(8);
                }
                int langcod = 0;
                if (1 == buffer.ReadBits(1))
                {
                    langcod = buffer.ReadBits(8);
                }
                int mixlevel = 0;
                int roomtyp  = 0;
                if (1 == buffer.ReadBits(1))
                {
                    mixlevel = buffer.ReadBits(5);
                    roomtyp  = buffer.ReadBits(2);
                }
                if (channel_mode == 0)
                {
                    int dialnorm2 = buffer.ReadBits(5);
                    int compr2    = 0;
                    if (1 == buffer.ReadBits(1))
                    {
                        compr2 = buffer.ReadBits(8);
                    }
                    int langcod2 = 0;
                    if (1 == buffer.ReadBits(1))
                    {
                        langcod2 = buffer.ReadBits(8);
                    }
                    int mixlevel2 = 0;
                    int roomtyp2  = 0;
                    if (1 == buffer.ReadBits(1))
                    {
                        mixlevel2 = buffer.ReadBits(5);
                        roomtyp2  = buffer.ReadBits(2);
                    }
                }
                int copyrightb = buffer.ReadBits(1);
                int origbs     = buffer.ReadBits(1);
                if (bsid == 6)
                {
                    if (1 == buffer.ReadBits(1))
                    {
                        int dmixmod       = buffer.ReadBits(2);
                        int ltrtcmixlev   = buffer.ReadBits(3);
                        int ltrtsurmixlev = buffer.ReadBits(3);
                        int lorocmixlev   = buffer.ReadBits(3);
                        int lorosurmixlev = buffer.ReadBits(3);
                    }
                    if (1 == buffer.ReadBits(1))
                    {
                        int dsurexmod    = buffer.ReadBits(2);
                        int dheadphonmod = buffer.ReadBits(2);
                        if (dheadphonmod == 0x2)
                        {
                            // TODO
                        }
                        int adconvtyp = buffer.ReadBits(1);
                        int xbsi2     = buffer.ReadBits(8);
                        int encinfo   = buffer.ReadBits(1);
                        if (dsurexmod == 2)
                        {
                            stream.AudioMode = TSAudioMode.Extended;
                        }
                    }
                }
            }
            else
            {
                int frame_type  = buffer.ReadBits(2);
                int substreamid = buffer.ReadBits(3);
                frame_size = (buffer.ReadBits(11) + 1) << 1;

                sr_code = buffer.ReadBits(2);
                if (sr_code == 3)
                {
                    sr_code = buffer.ReadBits(2);
                }
                else
                {
                    num_blocks = buffer.ReadBits(2);
                }
                channel_mode = buffer.ReadBits(3);
                lfe_on       = buffer.ReadBits(1);
            }

            switch (channel_mode)
            {
            case 0:     // 1+1
                stream.ChannelCount = 2;
                if (stream.AudioMode == TSAudioMode.Unknown)
                {
                    stream.AudioMode = TSAudioMode.DualMono;
                }
                break;

            case 1:     // 1/0
                stream.ChannelCount = 1;
                break;

            case 2:     // 2/0
                stream.ChannelCount = 2;
                if (stream.AudioMode == TSAudioMode.Unknown)
                {
                    stream.AudioMode = TSAudioMode.Stereo;
                }
                break;

            case 3:     // 3/0
                stream.ChannelCount = 3;
                break;

            case 4:     // 2/1
                stream.ChannelCount = 3;
                break;

            case 5:     // 3/1
                stream.ChannelCount = 4;
                break;

            case 6:     // 2/2
                stream.ChannelCount = 4;
                break;

            case 7:     // 3/2
                stream.ChannelCount = 5;
                break;

            default:
                stream.ChannelCount = 0;
                break;
            }

            switch (sr_code)
            {
            case 0:
                stream.SampleRate = 48000;
                break;

            case 1:
                stream.SampleRate = 44100;
                break;

            case 2:
                stream.SampleRate = 32000;
                break;

            default:
                stream.SampleRate = 0;
                break;
            }

            if (bsid <= 10)
            {
                switch (frame_size_code >> 1)
                {
                case 18:
                    stream.BitRate = 640000;
                    break;

                case 17:
                    stream.BitRate = 576000;
                    break;

                case 16:
                    stream.BitRate = 512000;
                    break;

                case 15:
                    stream.BitRate = 448000;
                    break;

                case 14:
                    stream.BitRate = 384000;
                    break;

                case 13:
                    stream.BitRate = 320000;
                    break;

                case 12:
                    stream.BitRate = 256000;
                    break;

                case 11:
                    stream.BitRate = 224000;
                    break;

                case 10:
                    stream.BitRate = 192000;
                    break;

                case 9:
                    stream.BitRate = 160000;
                    break;

                case 8:
                    stream.BitRate = 128000;
                    break;

                case 7:
                    stream.BitRate = 112000;
                    break;

                case 6:
                    stream.BitRate = 96000;
                    break;

                case 5:
                    stream.BitRate = 80000;
                    break;

                case 4:
                    stream.BitRate = 64000;
                    break;

                case 3:
                    stream.BitRate = 56000;
                    break;

                case 2:
                    stream.BitRate = 48000;
                    break;

                case 1:
                    stream.BitRate = 40000;
                    break;

                case 0:
                    stream.BitRate = 32000;
                    break;

                default:
                    stream.BitRate = 0;
                    break;
                }
            }
            else
            {
                stream.BitRate = (long)
                                 (4.0 * frame_size * stream.SampleRate / (num_blocks * 256));
            }

            stream.LFE = lfe_on;
            if (stream.StreamType != TSStreamType.AC3_PLUS_AUDIO &&
                stream.StreamType != TSStreamType.AC3_PLUS_SECONDARY_AUDIO)
            {
                stream.DialNorm = dial_norm - 31;
            }
            stream.IsVBR         = false;
            stream.IsInitialized = true;
        }
Ejemplo n.º 7
0
        private TSStream CreateStream(
            ushort streamPID, 
            byte streamType, 
            List<TSDescriptor> streamDescriptors)
        {
            TSStream stream = null;

            switch ((TSStreamType)streamType)
            {
                case TSStreamType.MVC_VIDEO:
                case TSStreamType.AVC_VIDEO:
                case TSStreamType.MPEG1_VIDEO:
                case TSStreamType.MPEG2_VIDEO:
                case TSStreamType.VC1_VIDEO:
                {
                    stream = new TSVideoStream();
                }
                break;

                case TSStreamType.AC3_AUDIO:
                case TSStreamType.AC3_PLUS_AUDIO:
                case TSStreamType.AC3_PLUS_SECONDARY_AUDIO:
                case TSStreamType.AC3_TRUE_HD_AUDIO:
                case TSStreamType.DTS_AUDIO:
                case TSStreamType.DTS_HD_AUDIO:
                case TSStreamType.DTS_HD_MASTER_AUDIO:
                case TSStreamType.DTS_HD_SECONDARY_AUDIO:
                case TSStreamType.LPCM_AUDIO:
                case TSStreamType.MPEG1_AUDIO:
                case TSStreamType.MPEG2_AUDIO:
                {
                    stream = new TSAudioStream();
                }
                break;

                case TSStreamType.INTERACTIVE_GRAPHICS:
                case TSStreamType.PRESENTATION_GRAPHICS:
                {
                    stream = new TSGraphicsStream();
                }
                break;

                case TSStreamType.SUBTITLE:
                {
                    stream = new TSTextStream();
                }
                break;

                default:
                    break;
            }

            if (stream != null &&
                !Streams.ContainsKey(streamPID))
            {
                stream.PID = streamPID;
                stream.StreamType = (TSStreamType)streamType;
                stream.Descriptors = streamDescriptors;
                Streams[stream.PID] = stream;
            }
            if (!StreamDiagnostics.ContainsKey(streamPID))
            {
                StreamDiagnostics[streamPID] =
                    new List<TSStreamDiagnostics>();
            }

            return stream;
        } 
Ejemplo n.º 8
0
        public void Scan()
        {
            FileStream fileStream = null;
            BinaryReader fileReader = null;

            try
            {
#if DEBUG
                Debug.WriteLine(string.Format(
                    "Scanning {0}...", Name));
#endif
                Streams.Clear();

                fileStream = File.OpenRead(FileInfo.FullName);
                fileReader = new BinaryReader(fileStream);

                byte[] data = new byte[fileStream.Length];
                fileReader.Read(data, 0, data.Length);

                byte[] fileType = new byte[8];
                Array.Copy(data, 0, fileType, 0, fileType.Length);
                
                FileType = ASCIIEncoding.ASCII.GetString(fileType);
                if (FileType != "HDMV0100" &&
                    FileType != "HDMV0200")
                {
                    throw new Exception(string.Format(
                        "Clip info file {0} has an unknown file type {1}.",
                        FileInfo.Name, FileType));
                }
#if DEBUG                
                Debug.WriteLine(string.Format(
                    "\tFileType: {0}", FileType));
#endif
                int clipIndex =
                    ((int)data[12] << 24) +
                    ((int)data[13] << 16) +
                    ((int)data[14] << 8) +
                    ((int)data[15]);

                int clipLength =
                    ((int)data[clipIndex] << 24) +
                    ((int)data[clipIndex + 1] << 16) +
                    ((int)data[clipIndex + 2] << 8) +
                    ((int)data[clipIndex + 3]);

                byte[] clipData = new byte[clipLength];
                Array.Copy(data, clipIndex + 4, clipData, 0, clipData.Length);

                int streamCount = clipData[8];
#if DEBUG
                Debug.WriteLine(string.Format(
                    "\tStreamCount: {0}", streamCount));
#endif
                int streamOffset = 10;
                for (int streamIndex = 0;
                    streamIndex < streamCount;
                    streamIndex++)
                {
                    TSStream stream = null;

                    ushort PID = (ushort)
                        ((clipData[streamOffset] << 8) + 
                          clipData[streamOffset + 1]);
                    
                    streamOffset += 2;

                    TSStreamType streamType = (TSStreamType)
                        clipData[streamOffset + 1];
                    switch (streamType)
                    {
                        case TSStreamType.MVC_VIDEO:
                            // TODO
                            break;

                        case TSStreamType.AVC_VIDEO:
                        case TSStreamType.MPEG1_VIDEO:
                        case TSStreamType.MPEG2_VIDEO:
                        case TSStreamType.VC1_VIDEO:
                        {
                            TSVideoFormat videoFormat = (TSVideoFormat)
                                (clipData[streamOffset + 2] >> 4);
                            TSFrameRate frameRate = (TSFrameRate)
                                (clipData[streamOffset + 2] & 0xF);
                            TSAspectRatio aspectRatio = (TSAspectRatio)
                                (clipData[streamOffset + 3] >> 4);

                            stream = new TSVideoStream();
                            ((TSVideoStream)stream).VideoFormat = videoFormat;
                            ((TSVideoStream)stream).AspectRatio = aspectRatio;
                            ((TSVideoStream)stream).FrameRate = frameRate;
#if DEBUG
                            Debug.WriteLine(string.Format(
                                "\t{0} {1} {2} {3} {4}",
                                PID,
                                streamType,
                                videoFormat,
                                frameRate,
                                aspectRatio));
#endif
                        }
                        break;

                        case TSStreamType.AC3_AUDIO:
                        case TSStreamType.AC3_PLUS_AUDIO:
                        case TSStreamType.AC3_PLUS_SECONDARY_AUDIO:
                        case TSStreamType.AC3_TRUE_HD_AUDIO:
                        case TSStreamType.DTS_AUDIO:
                        case TSStreamType.DTS_HD_AUDIO:
                        case TSStreamType.DTS_HD_MASTER_AUDIO:
                        case TSStreamType.DTS_HD_SECONDARY_AUDIO:
                        case TSStreamType.LPCM_AUDIO:
                        case TSStreamType.MPEG1_AUDIO:
                        case TSStreamType.MPEG2_AUDIO:
                        {
                            byte[] languageBytes = new byte[3];
                            Array.Copy(clipData, streamOffset + 3,
                                languageBytes, 0, languageBytes.Length);
                            string languageCode =
                                ASCIIEncoding.ASCII.GetString(languageBytes);

                            TSChannelLayout channelLayout = (TSChannelLayout)
                                (clipData[streamOffset + 2] >> 4);
                            TSSampleRate sampleRate = (TSSampleRate)
                                (clipData[streamOffset + 2] & 0xF);

                            stream = new TSAudioStream();
                            ((TSAudioStream)stream).LanguageCode = languageCode;
                            ((TSAudioStream)stream).ChannelLayout = channelLayout;
                            ((TSAudioStream)stream).SampleRate = TSAudioStream.ConvertSampleRate(sampleRate);
                            ((TSAudioStream)stream).LanguageCode = languageCode;
#if DEBUG
                            Debug.WriteLine(string.Format(
                                "\t{0} {1} {2} {3} {4}",
                                PID,
                                streamType,
                                languageCode,
                                channelLayout,
                                sampleRate));
#endif
                        }
                        break;

                        case TSStreamType.INTERACTIVE_GRAPHICS:
                        case TSStreamType.PRESENTATION_GRAPHICS:
                        {
                            byte[] languageBytes = new byte[3];
                            Array.Copy(clipData, streamOffset + 2,
                                languageBytes, 0, languageBytes.Length);
                            string languageCode =
                                ASCIIEncoding.ASCII.GetString(languageBytes);

                            stream = new TSGraphicsStream();
                            stream.LanguageCode = languageCode;
#if DEBUG
                            Debug.WriteLine(string.Format(
                                "\t{0} {1} {2}",
                                PID,
                                streamType,
                                languageCode));
#endif
                        }
                        break;

                        case TSStreamType.SUBTITLE:
                        {
                            byte[] languageBytes = new byte[3];
                            Array.Copy(clipData, streamOffset + 3,
                                languageBytes, 0, languageBytes.Length);
                            string languageCode =
                                ASCIIEncoding.ASCII.GetString(languageBytes);
#if DEBUG
                            Debug.WriteLine(string.Format(
                                "\t{0} {1} {2}",
                                PID,
                                streamType,
                                languageCode));
#endif
                            stream = new TSTextStream();
                            stream.LanguageCode = languageCode;
                        }
                        break;
                    }

                    if (stream != null)
                    {
                        stream.PID = PID;
                        stream.StreamType = streamType;
                        Streams.Add(PID, stream);
                    }

                    streamOffset += clipData[streamOffset] + 1;
                }                
                IsValid = true;
            }
            finally
            {
                if (fileReader != null) fileReader.Close();
                if (fileStream != null) fileStream.Close();
            }
        }
Ejemplo n.º 9
0
        public void Scan()
        {
            FileStream   fileStream = null;
            BinaryReader fileReader = null;

            try
            {
#if DEBUG
                Debug.WriteLine(string.Format(
                                    "Scanning {0}...", Name));
#endif
                Streams.Clear();

                fileStream = File.OpenRead(FileInfo.FullName);
                fileReader = new BinaryReader(fileStream);

                byte[] data = new byte[fileStream.Length];
                fileReader.Read(data, 0, data.Length);

                byte[] fileType = new byte[8];
                Array.Copy(data, 0, fileType, 0, fileType.Length);

                FileType = ASCIIEncoding.ASCII.GetString(fileType);
                if (FileType != "HDMV0100" &&
                    FileType != "HDMV0200")
                {
                    throw new Exception(string.Format(
                                            "Clip info file {0} has an unknown file type {1}.",
                                            FileInfo.Name, FileType));
                }
#if DEBUG
                Debug.WriteLine(string.Format(
                                    "\tFileType: {0}", FileType));
#endif
                int clipIndex =
                    ((int)data[12] << 24) +
                    ((int)data[13] << 16) +
                    ((int)data[14] << 8) +
                    ((int)data[15]);

                int clipLength =
                    ((int)data[clipIndex] << 24) +
                    ((int)data[clipIndex + 1] << 16) +
                    ((int)data[clipIndex + 2] << 8) +
                    ((int)data[clipIndex + 3]);

                byte[] clipData = new byte[clipLength];
                Array.Copy(data, clipIndex + 4, clipData, 0, clipData.Length);

                int streamCount = clipData[8];
#if DEBUG
                Debug.WriteLine(string.Format(
                                    "\tStreamCount: {0}", streamCount));
#endif
                int streamOffset = 10;
                for (int streamIndex = 0;
                     streamIndex < streamCount;
                     streamIndex++)
                {
                    TSStream stream = null;

                    ushort PID = (ushort)
                                 ((clipData[streamOffset] << 8) +
                                  clipData[streamOffset + 1]);

                    streamOffset += 2;

                    TSStreamType streamType = (TSStreamType)
                                              clipData[streamOffset + 1];
                    switch (streamType)
                    {
                    case TSStreamType.MVC_VIDEO:
                        // TODO
                        break;

                    case TSStreamType.AVC_VIDEO:
                    case TSStreamType.MPEG1_VIDEO:
                    case TSStreamType.MPEG2_VIDEO:
                    case TSStreamType.VC1_VIDEO:
                    {
                        TSVideoFormat videoFormat = (TSVideoFormat)
                                                    (clipData[streamOffset + 2] >> 4);
                        TSFrameRate frameRate = (TSFrameRate)
                                                (clipData[streamOffset + 2] & 0xF);
                        TSAspectRatio aspectRatio = (TSAspectRatio)
                                                    (clipData[streamOffset + 3] >> 4);

                        stream = new TSVideoStream();
                        ((TSVideoStream)stream).VideoFormat = videoFormat;
                        ((TSVideoStream)stream).AspectRatio = aspectRatio;
                        ((TSVideoStream)stream).FrameRate   = frameRate;
#if DEBUG
                        Debug.WriteLine(string.Format(
                                            "\t{0} {1} {2} {3} {4}",
                                            PID,
                                            streamType,
                                            videoFormat,
                                            frameRate,
                                            aspectRatio));
#endif
                    }
                    break;

                    case TSStreamType.AC3_AUDIO:
                    case TSStreamType.AC3_PLUS_AUDIO:
                    case TSStreamType.AC3_PLUS_SECONDARY_AUDIO:
                    case TSStreamType.AC3_TRUE_HD_AUDIO:
                    case TSStreamType.DTS_AUDIO:
                    case TSStreamType.DTS_HD_AUDIO:
                    case TSStreamType.DTS_HD_MASTER_AUDIO:
                    case TSStreamType.DTS_HD_SECONDARY_AUDIO:
                    case TSStreamType.LPCM_AUDIO:
                    case TSStreamType.MPEG1_AUDIO:
                    case TSStreamType.MPEG2_AUDIO:
                    {
                        byte[] languageBytes = new byte[3];
                        Array.Copy(clipData, streamOffset + 3,
                                   languageBytes, 0, languageBytes.Length);
                        string languageCode =
                            ASCIIEncoding.ASCII.GetString(languageBytes);

                        TSChannelLayout channelLayout = (TSChannelLayout)
                                                        (clipData[streamOffset + 2] >> 4);
                        TSSampleRate sampleRate = (TSSampleRate)
                                                  (clipData[streamOffset + 2] & 0xF);

                        stream = new TSAudioStream();
                        ((TSAudioStream)stream).LanguageCode  = languageCode;
                        ((TSAudioStream)stream).ChannelLayout = channelLayout;
                        ((TSAudioStream)stream).SampleRate    = TSAudioStream.ConvertSampleRate(sampleRate);
                        ((TSAudioStream)stream).LanguageCode  = languageCode;
#if DEBUG
                        Debug.WriteLine(string.Format(
                                            "\t{0} {1} {2} {3} {4}",
                                            PID,
                                            streamType,
                                            languageCode,
                                            channelLayout,
                                            sampleRate));
#endif
                    }
                    break;

                    case TSStreamType.INTERACTIVE_GRAPHICS:
                    case TSStreamType.PRESENTATION_GRAPHICS:
                    {
                        byte[] languageBytes = new byte[3];
                        Array.Copy(clipData, streamOffset + 2,
                                   languageBytes, 0, languageBytes.Length);
                        string languageCode =
                            ASCIIEncoding.ASCII.GetString(languageBytes);

                        stream = new TSGraphicsStream();
                        stream.LanguageCode = languageCode;
#if DEBUG
                        Debug.WriteLine(string.Format(
                                            "\t{0} {1} {2}",
                                            PID,
                                            streamType,
                                            languageCode));
#endif
                    }
                    break;

                    case TSStreamType.SUBTITLE:
                    {
                        byte[] languageBytes = new byte[3];
                        Array.Copy(clipData, streamOffset + 3,
                                   languageBytes, 0, languageBytes.Length);
                        string languageCode =
                            ASCIIEncoding.ASCII.GetString(languageBytes);
#if DEBUG
                        Debug.WriteLine(string.Format(
                                            "\t{0} {1} {2}",
                                            PID,
                                            streamType,
                                            languageCode));
#endif
                        stream = new TSTextStream();
                        stream.LanguageCode = languageCode;
                    }
                    break;
                    }

                    if (stream != null)
                    {
                        stream.PID        = PID;
                        stream.StreamType = streamType;
                        Streams.Add(PID, stream);
                    }

                    streamOffset += clipData[streamOffset] + 1;
                }
                IsValid = true;
            }
            finally
            {
                if (fileReader != null)
                {
                    fileReader.Close();
                }
                if (fileStream != null)
                {
                    fileStream.Close();
                }
            }
        }
Ejemplo n.º 10
0
        protected TSStream CreatePlaylistStream(byte[] data, ref int pos)
        {
            TSStream stream = null;

            int start = pos;

            int headerLength = data[pos++];
            int headerPos = pos;
            int headerType = data[pos++];

            int pid = 0;
            int subpathid = 0;
            int subclipid = 0;

            switch (headerType)
            {
                case 1:
                    pid = ReadInt16(data, ref pos);
                    break;
                case 2:
                    subpathid = data[pos++];
                    subclipid = data[pos++];
                    pid = ReadInt16(data, ref pos);
                    break;
                case 3:
                    subpathid = data[pos++];
                    pid = ReadInt16(data, ref pos);
                    break;
                case 4:
                    subpathid = data[pos++];
                    subclipid = data[pos++];
                    pid = ReadInt16(data, ref pos);
                    break;
                default:
                    break;
            }

            pos = headerPos + headerLength;

            int streamLength = data[pos++];
            int streamPos = pos;

            TSStreamType streamType = (TSStreamType)data[pos++];
            switch (streamType)
            {
                case TSStreamType.MVC_VIDEO:
                    // TODO
                    break;

                case TSStreamType.AVC_VIDEO:
                case TSStreamType.MPEG1_VIDEO:
                case TSStreamType.MPEG2_VIDEO:
                case TSStreamType.VC1_VIDEO:

                    TSVideoFormat videoFormat = (TSVideoFormat)
                        (data[pos] >> 4);
                    TSFrameRate frameRate = (TSFrameRate)
                        (data[pos] & 0xF);
                    TSAspectRatio aspectRatio = (TSAspectRatio)
                        (data[pos + 1] >> 4);

                    stream = new TSVideoStream();
                    ((TSVideoStream)stream).VideoFormat = videoFormat;
                    ((TSVideoStream)stream).AspectRatio = aspectRatio;
                    ((TSVideoStream)stream).FrameRate = frameRate;

#if DEBUG
                            Debug.WriteLine(string.Format(
                                "\t{0} {1} {2} {3} {4}",
                                pid,
                                streamType,
                                videoFormat,
                                frameRate,
                                aspectRatio));
#endif

                    break;

                case TSStreamType.AC3_AUDIO:
                case TSStreamType.AC3_PLUS_AUDIO:
                case TSStreamType.AC3_PLUS_SECONDARY_AUDIO:
                case TSStreamType.AC3_TRUE_HD_AUDIO:
                case TSStreamType.DTS_AUDIO:
                case TSStreamType.DTS_HD_AUDIO:
                case TSStreamType.DTS_HD_MASTER_AUDIO:
                case TSStreamType.DTS_HD_SECONDARY_AUDIO:
                case TSStreamType.LPCM_AUDIO:
                case TSStreamType.MPEG1_AUDIO:
                case TSStreamType.MPEG2_AUDIO:

                    int audioFormat = ReadByte(data, ref pos);

                    TSChannelLayout channelLayout = (TSChannelLayout)
                        (audioFormat >> 4);
                    TSSampleRate sampleRate = (TSSampleRate)
                        (audioFormat & 0xF);

                    string audioLanguage = ReadString(data, 3, ref pos);

                    stream = new TSAudioStream();
                    ((TSAudioStream)stream).ChannelLayout = channelLayout;
                    ((TSAudioStream)stream).SampleRate = TSAudioStream.ConvertSampleRate(sampleRate);
                    ((TSAudioStream)stream).LanguageCode = audioLanguage;

#if DEBUG
                    Debug.WriteLine(string.Format(
                        "\t{0} {1} {2} {3} {4}",
                        pid,
                        streamType,
                        audioLanguage,
                        channelLayout,
                        sampleRate));
#endif

                    break;

                case TSStreamType.INTERACTIVE_GRAPHICS:
                case TSStreamType.PRESENTATION_GRAPHICS:

                    string graphicsLanguage = ReadString(data, 3, ref pos);

                    stream = new TSGraphicsStream();
                    ((TSGraphicsStream)stream).LanguageCode = graphicsLanguage;

                    if (data[pos] != 0)
                    {
                    }

#if DEBUG
                    Debug.WriteLine(string.Format(
                        "\t{0} {1} {2}",
                        pid,
                        streamType,
                        graphicsLanguage));
#endif

                    break;

                case TSStreamType.SUBTITLE:

                    int code = ReadByte(data, ref pos); // TODO
                    string textLanguage = ReadString(data, 3, ref pos);

                    stream = new TSTextStream();
                    ((TSTextStream)stream).LanguageCode = textLanguage;

#if DEBUG
                    Debug.WriteLine(string.Format(
                        "\t{0} {1} {2}",
                        pid,
                        streamType,
                        textLanguage));
#endif

                    break;

                default:
                    break;
            }

            pos = streamPos + streamLength;

            if (stream != null)
            {
                stream.PID = (ushort)pid;
                stream.StreamType = streamType;
            }

            return stream;
        }
Ejemplo n.º 11
0
        public static int CompareAudioStreams(
            TSAudioStream x, 
            TSAudioStream y)
        {
            if (x == y)
            {
                return 0;
            }
            else if (x == null && y == null)
            {
                return 0;
            }
            else if (x == null && y != null)
            {
                return -1;
            }
            else if (x != null && y == null)
            {
                return 1;
            }
            else
            {
                if (x.ChannelCount > y.ChannelCount)
                {
                    return -1;
                }
                else if (y.ChannelCount > x.ChannelCount)
                {
                    return 1;
                }
                else
                {
                    int sortX = GetStreamTypeSortIndex(x.StreamType);
                    int sortY = GetStreamTypeSortIndex(y.StreamType);

                    if (sortX > sortY)
                    {
                        return -1;
                    }
                    else if (sortY > sortX)
                    {
                        return 1;
                    }
                    else
                    {
                        if (x.LanguageCode == "eng")
                        {
                            return -1;
                        }
                        else if (y.LanguageCode == "eng")
                        {
                            return 1;
                        }
                        else if (x.LanguageCode != y.LanguageCode)
                        {
                            return string.Compare(
                                x.LanguageName, y.LanguageName);
                        }
                        else if (x.PID < y.PID)
                        {
                            return -1;
                        }
                        else if (y.PID < x.PID)
                        {
                            return 1;
                        }
                        return 0;
                    }
                }
            }
        }
Ejemplo n.º 12
0
        public static void Scan(
            TSAudioStream stream,
            TSStreamBuffer buffer,
            ref string tag)
        {
            if (stream.IsInitialized) return;

            byte[] sync = buffer.ReadBytes(2);
            if (sync == null ||
                sync[0] != 0x0B ||
                sync[1] != 0x77)
            {
                return;
            }

            int sr_code = 0;
            int frame_size = 0;
            int frame_size_code = 0;
            int channel_mode = 0;
            int lfe_on = 0;
            int dial_norm = 0;
            int num_blocks = 0;

            byte[] hdr = buffer.ReadBytes(4);
            int bsid = (hdr[3] & 0xF8) >> 3;
            buffer.Seek(-4, SeekOrigin.Current);
            if (bsid <= 10)
            {
                byte[] crc = buffer.ReadBytes(2);
                sr_code = buffer.ReadBits(2);
                frame_size_code = buffer.ReadBits(6);
                bsid = buffer.ReadBits(5);
                int bsmod = buffer.ReadBits(3);

                channel_mode = buffer.ReadBits(3);
                int cmixlev = 0;
                if (((channel_mode & 0x1) > 0) && (channel_mode != 0x1))
                {
                    cmixlev = buffer.ReadBits(2);
                }
                int surmixlev = 0;
                if ((channel_mode & 0x4) > 0)
                {
                    surmixlev = buffer.ReadBits(2);
                }
                int dsurmod = 0;
                if (channel_mode == 0x2)
                {
                    dsurmod = buffer.ReadBits(2);
                    if (dsurmod == 0x2)
                    {
                        stream.AudioMode = TSAudioMode.Surround;
                    }
                }
                lfe_on = buffer.ReadBits(1);
                dial_norm = buffer.ReadBits(5);
                int compr = 0;
                if (1 == buffer.ReadBits(1))
                {
                    compr = buffer.ReadBits(8);
                }
                int langcod = 0;
                if (1 == buffer.ReadBits(1))
                {
                    langcod = buffer.ReadBits(8);
                }
                int mixlevel = 0;
                int roomtyp = 0;
                if (1 == buffer.ReadBits(1))
                {
                    mixlevel = buffer.ReadBits(5);
                    roomtyp = buffer.ReadBits(2);
                }
                if (channel_mode == 0)
                {
                    int dialnorm2 = buffer.ReadBits(5);
                    int compr2 = 0;
                    if (1 == buffer.ReadBits(1))
                    {
                        compr2 = buffer.ReadBits(8);
                    }
                    int langcod2 = 0;
                    if (1 == buffer.ReadBits(1))
                    {
                        langcod2 = buffer.ReadBits(8);
                    }
                    int mixlevel2 = 0;
                    int roomtyp2 = 0;
                    if (1 == buffer.ReadBits(1))
                    {
                        mixlevel2 = buffer.ReadBits(5);
                        roomtyp2 = buffer.ReadBits(2);
                    }
                }
                int copyrightb = buffer.ReadBits(1);
                int origbs = buffer.ReadBits(1);
                if (bsid == 6)
                {
                    if (1 == buffer.ReadBits(1))
                    {
                        int dmixmod = buffer.ReadBits(2);
                        int ltrtcmixlev = buffer.ReadBits(3);
                        int ltrtsurmixlev = buffer.ReadBits(3);
                        int lorocmixlev = buffer.ReadBits(3);
                        int lorosurmixlev = buffer.ReadBits(3);
                    }
                    if (1 == buffer.ReadBits(1))
                    {
                        int dsurexmod = buffer.ReadBits(2);
                        int dheadphonmod = buffer.ReadBits(2);
                        if (dheadphonmod == 0x2)
                        {
                            // TODO
                        }
                        int adconvtyp = buffer.ReadBits(1);
                        int xbsi2 = buffer.ReadBits(8);
                        int encinfo = buffer.ReadBits(1);
                        if (dsurexmod == 2)
                        {
                            stream.AudioMode = TSAudioMode.Extended;
                        }
                    }
                }
            }
            else
            {
                int frame_type = buffer.ReadBits(2);
                int substreamid = buffer.ReadBits(3);
                frame_size = (buffer.ReadBits(11) + 1) << 1;

                sr_code = buffer.ReadBits(2);
                if (sr_code == 3)
                {
                    sr_code = buffer.ReadBits(2);
                }
                else
                {
                    num_blocks = buffer.ReadBits(2);
                }
                channel_mode = buffer.ReadBits(3);
                lfe_on = buffer.ReadBits(1);
            }

            switch (channel_mode)
            {
                case 0: // 1+1
                    stream.ChannelCount = 2;
                    if (stream.AudioMode == TSAudioMode.Unknown)
                    {
                        stream.AudioMode = TSAudioMode.DualMono;
                    }
                    break;
                case 1: // 1/0
                    stream.ChannelCount = 1;
                    break;
                case 2: // 2/0
                    stream.ChannelCount = 2;
                    if (stream.AudioMode == TSAudioMode.Unknown)
                    {
                        stream.AudioMode = TSAudioMode.Stereo;
                    }
                    break;
                case 3: // 3/0
                    stream.ChannelCount = 3;
                    break;
                case 4: // 2/1
                    stream.ChannelCount = 3;
                    break;
                case 5: // 3/1
                    stream.ChannelCount = 4;
                    break;
                case 6: // 2/2
                    stream.ChannelCount = 4;
                    break;
                case 7: // 3/2
                    stream.ChannelCount = 5;
                    break;
                default:
                    stream.ChannelCount = 0;
                    break;
            }

            switch (sr_code)
            {
                case 0:
                    stream.SampleRate = 48000;
                    break;
                case 1:
                    stream.SampleRate = 44100;
                    break;
                case 2:
                    stream.SampleRate = 32000;
                    break;
                default:
                    stream.SampleRate = 0;
                    break;
            }

            if (bsid <= 10)
            {
                switch (frame_size_code >> 1)
                {
                    case 18:
                        stream.BitRate = 640000;
                        break;
                    case 17:
                        stream.BitRate = 576000;
                        break;
                    case 16:
                        stream.BitRate = 512000;
                        break;
                    case 15:
                        stream.BitRate = 448000;
                        break;
                    case 14:
                        stream.BitRate = 384000;
                        break;
                    case 13:
                        stream.BitRate = 320000;
                        break;
                    case 12:
                        stream.BitRate = 256000;
                        break;
                    case 11:
                        stream.BitRate = 224000;
                        break;
                    case 10:
                        stream.BitRate = 192000;
                        break;
                    case 9:
                        stream.BitRate = 160000;
                        break;
                    case 8:
                        stream.BitRate = 128000;
                        break;
                    case 7:
                        stream.BitRate = 112000;
                        break;
                    case 6:
                        stream.BitRate = 96000;
                        break;
                    case 5:
                        stream.BitRate = 80000;
                        break;
                    case 4:
                        stream.BitRate = 64000;
                        break;
                    case 3:
                        stream.BitRate = 56000;
                        break;
                    case 2:
                        stream.BitRate = 48000;
                        break;
                    case 1:
                        stream.BitRate = 40000;
                        break;
                    case 0:
                        stream.BitRate = 32000;
                        break;
                    default:
                        stream.BitRate = 0;
                        break;
                }
            }
            else
            {
                stream.BitRate = (long)
                    (4.0 * frame_size * stream.SampleRate / (num_blocks * 256));
            }

            stream.LFE = lfe_on;
            if (stream.StreamType != TSStreamType.AC3_PLUS_AUDIO &&
                stream.StreamType != TSStreamType.AC3_PLUS_SECONDARY_AUDIO)
            {
                stream.DialNorm = dial_norm - 31;
            }
            stream.IsVBR = false;
            stream.IsInitialized = true;
        }