/// <summary>
        /// Initializes a new instance of the <see cref="ManifestTrack"/> class.
        /// </summary>
        /// <param name="type">The track type.</param>
        /// <param name="tkhd">The <see cref="TrackHeaderFullBox"/> with track general information.</param>
        /// <param name="tfra">The <see cref="TrackFragmentRandomAccessFullBox"/> with list of fragments corresponding to the track.</param>
        /// <param name="stsd">The <see cref="SampleDescriptionFullBox"/> with track codec information.</param>
        public ManifestTrack(string type, TrackHeaderFullBox tkhd, MediaHeaderFullBox mdhd, TrackFragmentRandomAccessFullBox tfra, SampleDescriptionFullBox stsd)
        {
            this.IsSupported = false;
            this.Type = (ManifestTrackType)Enum.Parse(typeof(ManifestTrackType), type, true);
            this.Id = (int)tkhd.TrackId;
            this.Fragments = tfra;
            this.Duration = tkhd.Duration;
            this.Height = tkhd.Height >> 16;
            this.Width = tkhd.Width >> 16;
            this.TimeScale = mdhd.Timescale;
            this.Language = mdhd.Language;

            switch (this.Type)
            {
                case ManifestTrackType.Video:
                    BuildVideoTrack(stsd, tfra);
                    break;
                case ManifestTrackType.Audio:
                    BuildAudioTrack(stsd);
                    break;
                case ManifestTrackType.Text:
                    BuildSubtitleTrack(stsd);
                    break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new Box instance that matches the BoxType specified. This will position the
        /// reader to the end of the box that was read in.
        /// </summary>
        /// <param name="stream">The stream that contains the bytes for the box.</param>
        /// <returns>Returns the box read from the stream; if there was no box to read it
        /// will return null.</returns>
        public static Box Create(BoxBinaryReader stream)
        {
            Box box     = null;
            var offset  = stream.Offset;
            var size    = stream.ReadBoxSize();
            var boxType = stream.ReadBoxType();

            switch (boxType)
            {
            case BoxType.Moov:
                box = new MovieBox(offset, size);
                break;

            case BoxType.Mvhd:
                box = new MovieHeaderFullBox(offset, size);
                break;

            case BoxType.Trak:
                box = new TrackBox(offset, size);
                break;

            case BoxType.Tkhd:
                box = new TrackHeaderFullBox(offset, size);
                break;

            case BoxType.Tref:
                box = new TrackReferenceBox(offset, size);
                break;

            case BoxType.Mdia:
                box = new MediaBox(offset, size);
                break;

            case BoxType.Mdhd:
                box = new MediaHeaderFullBox(offset, size);
                break;

            case BoxType.Hdlr:
                box = new HandlerReferenceFullBox(offset, size);
                break;

            case BoxType.Minf:
                box = new MediaInformationBox(offset, size);
                break;

            case BoxType.Vmhd:
                box = new VideoMediaHeaderFullBox(offset, size);
                break;

            case BoxType.Smhd:
                box = new SoundMediaHeaderFullBox(offset, size);
                break;

            case BoxType.Nmhd:
                box = new NullMediaHeaderFullBox(offset, size);
                break;

            case BoxType.Dinf:
                box = new DataInformationBox(offset, size);
                break;

            case BoxType.Stbl:
                box = new SampleTableBox(offset, size);
                break;

            case BoxType.Stts:
                box = new DecodingTimeToSampleFullBox(offset, size);
                break;

            case BoxType.Stss:
                box = new SyncSamplesBox(offset, size);
                break;

            case BoxType.Ctts:
                box = new CompositionTimeToSampleFullBox(offset, size);
                break;

            case BoxType.Stsd:
                box = new SampleDescriptionFullBox(offset, size);
                break;

            case BoxType.Mp4a:
            case BoxType.Wma:
            case BoxType.Ac_3:
            case BoxType.Ec_3:
            case BoxType.Mlpa:
            case BoxType.Dtsc:
            case BoxType.Dtsh:
            case BoxType.Dtsl:
            case BoxType.Dtse:
                box = new AudioSampleEntryBox(offset, size);
                break;

            case BoxType.Dec3:
                box = new EC3SpecificBox(offset, size);
                break;

            case BoxType.Dac3:
                box = new AC3SpecificBox(offset, size);
                break;

            case BoxType.Dmlp:
                box = new MLPSpecificBox(offset, size);
                break;

            case BoxType.Ddts:
                box = new DTSSpecificBox(offset, size);
                break;

            case BoxType.Avc1:
            case BoxType.Vc_1:
                box = new VisualSampleEntryBox(offset, size);
                break;

            case BoxType.Stpp:
                box = new SubtitleSampleEntryBox(offset, size);
                break;

            case BoxType.Encv:
            case BoxType.Enca:
            case BoxType.Enct:
            case BoxType.Encs:
                box = new ProtectedSampleEntryBox(offset, size, boxType);
                break;

            case BoxType.Esds:
                box = new ElementaryStreamDescriptorFullBox(offset, size);
                break;

            case BoxType.Avcc:
                box = new AdvancedVideoCodingBox(offset, size);
                break;

            case BoxType.Wfex:
                box = new WaveFormatExBox(offset, size);
                break;

            case BoxType.Dvc1:
                box = new DigitalVideoCodingBox(offset, size);
                break;

            case BoxType.Mvex:
                box = new MovieExtendsBox(offset, size);
                break;

            case BoxType.Ftyp:
                box = new FileTypeBox(offset, size);
                break;

            case BoxType.Mdat:
                box = new MediaDataBox(offset, size);
                break;

            case BoxType.Moof:
                box = new MovieFragmentBox(offset, size);
                break;

            case BoxType.Mfra:
                box = new MovieFragmentRandomAccessBox(offset, size);
                break;

            case BoxType.Tfra:
                box = new TrackFragmentRandomAccessFullBox(offset, size);
                break;

            case BoxType.Mfro:
                box = new MovieFragmentRandomAccessOffsetFullBox(offset, size);
                break;

            case BoxType.Mfhd:
                box = new MovieFragmentHeaderFullBox(offset, size);
                break;

            case BoxType.Traf:
                box = new TrackFragmentBox(offset, size);
                break;

            case BoxType.Tfhd:
                box = new TrackFragmentHeaderFullBox(offset, size);
                break;

            case BoxType.Trun:
                box = new TrackFragmentRunFullBox(offset, size);
                break;

            case BoxType.Sdtp:
                box = new IndependentAndDisposableSamplesFullBox(offset, size);
                break;

            case BoxType.Uuid:
                box = ExtensionBox.GetNextBoxFromStream(stream, offset, (uint)size);
                box.ExtendedType = stream.ReadGuid();
                break;

            case BoxType.Pdin:
                box = new ProgressiveDownloadInfoFullBox(offset, size);
                break;

            case BoxType.Bloc:
                box = new BaseLocationFullBox(offset, size);
                break;

            case BoxType.Ainf:
                box = new AssetInformationFullBox(offset, size);
                break;

            case BoxType.Xml:
                box = new XmlFullBox(offset, size);
                break;

            case BoxType.Bxml:
                box = new BinaryXmlFullBox(offset, size);
                break;

            case BoxType.Iloc:
                box = new ItemLocationFullBox(offset, size);
                break;

            case BoxType.Idat:
                box = new ItemDataBox(offset, size);
                break;

            case BoxType.Meta:
                box = new MetaFullBox(offset, size);
                break;

            case BoxType.Free:
            case BoxType.Skip:
                box = new FreeSpaceBox(offset, size);
                break;

            case BoxType.Trik:
                box = new TrickPlayFullBox(offset, size);
                break;

            case BoxType.Btrt:
                box = new BitRateBox(offset, size);
                break;

            case BoxType.Sthd:
                box = new SubtitleMediaHeaderFullBox(offset, size);
                break;

            case BoxType.Subs:
                box = new SubSampleInformationFullBox(offset, size);
                break;

            case BoxType.Tfdt:
                box = new TrackFragmentBaseMediaDecodeTimeFullBox(offset, size);
                break;

            case BoxType.Saiz:
                box = new SampleAuxiliaryInformationSizesFullBox(offset, size);
                break;

            case BoxType.Saio:
                box = new SampleAuxiliaryInformationOffsetsFullBox(offset, size);
                break;

            case BoxType.Prft:
                box = new ProducerReferenceTimeFullBox(offset, size);
                break;

            case BoxType.Pssh:
                box = new ProtectionSystemSpecificHeaderFullBox(offset, size);
                break;

            case BoxType.Tenc:
                box = new TrackEncryptionFullBox(offset, size);
                break;

            case BoxType.Senc:
                box = new SampleEncryptionFullBox(offset, size);
                break;

            case BoxType.Schi:
                box = new SchemeInformationBox(offset, size);
                break;

            case BoxType.Sinf:
                box = new ProtectedSchemeInformationBox(offset, size);
                break;

            case BoxType.Avcn:
                box = new AVCNALBox(offset, size);
                break;

            case BoxType.Sidx:
                box = new SegmentIndexBox(offset, size);
                break;

            case BoxType.Stsc:
                box = new SampleChunkBox(offset, size);
                break;

            case BoxType.Stsz:
                box = new SampleSizeBox(offset, size);
                break;

            case BoxType.Stco:
                box = new SampleChunkOffsetBox(offset, size);
                break;

            case BoxType.Iods:
                box = new InitialObjectDescriptorBox(offset, size);
                break;

            default:
                stream.GotoEndOfBox(offset, size);
                break;
            }

            if (box != null)
            {
                box.ReadBoxFromStream(stream);
            }

            return(box);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new Box instance that matches the BoxType specified. This will position the 
        /// reader to the end of the box that was read in.
        /// </summary>
        /// <param name="stream">The stream that contains the bytes for the box.</param>
        /// <returns>Returns the box read from the stream; if there was no box to read it 
        /// will return null.</returns>
        public static Box Create(BoxBinaryReader stream)
        {
            Box box = null;
            var offset = stream.Offset;
            var size = stream.ReadBoxSize();
            var boxType = stream.ReadBoxType();

            switch (boxType)
            {
                case BoxType.Moov:
                    box = new MovieBox(offset, size);
                    break;
                case BoxType.Mvhd:
                    box = new MovieHeaderFullBox(offset, size);
                    break;
                case BoxType.Trak:
                    box = new TrackBox(offset, size);
                    break;
                case BoxType.Tkhd:
                    box = new TrackHeaderFullBox(offset, size);
                    break;
                case BoxType.Tref:
                    box = new TrackReferenceBox(offset, size);
                    break;
                case BoxType.Mdia:
                    box = new MediaBox(offset, size);
                    break;
                case BoxType.Mdhd:
                    box = new MediaHeaderFullBox(offset, size);
                    break;
                case BoxType.Hdlr:
                    box = new HandlerReferenceFullBox(offset, size);
                    break;
                case BoxType.Minf:
                    box = new MediaInformationBox(offset, size);
                    break;
                case BoxType.Vmhd:
                    box = new VideoMediaHeaderFullBox(offset, size);
                    break;
                case BoxType.Smhd:
                    box = new SoundMediaHeaderFullBox(offset, size);
                    break;
                case BoxType.Nmhd:
                    box = new NullMediaHeaderFullBox(offset, size);
                    break;
                case BoxType.Dinf:
                    box = new DataInformationBox(offset, size);
                    break;
                case BoxType.Stbl:
                    box = new SampleTableBox(offset, size);
                    break;
                case BoxType.Stts:
                    box = new DecodingTimeToSampleFullBox(offset, size);
                    break;
                case BoxType.Stss:
                    box = new SyncSamplesBox(offset, size);
                    break;
                case BoxType.Ctts:
                    box = new CompositionTimeToSampleFullBox(offset, size);
                    break;
                case BoxType.Stsd:
                    box = new SampleDescriptionFullBox(offset, size);
                    break;
                case BoxType.Mp4a:
                case BoxType.Wma:
                case BoxType.Ac_3:
                case BoxType.Ec_3:
                case BoxType.Mlpa:
                case BoxType.Dtsc:
                case BoxType.Dtsh:
                case BoxType.Dtsl:
                case BoxType.Dtse:
                    box = new AudioSampleEntryBox(offset, size);
                    break;
                case BoxType.Dec3:
                    box = new EC3SpecificBox(offset, size);
                    break;
                case BoxType.Dac3:
                    box = new AC3SpecificBox(offset, size);
                    break;
                case BoxType.Dmlp:
                    box = new MLPSpecificBox(offset, size);
                    break;
                case BoxType.Ddts:
                    box = new DTSSpecificBox(offset, size);
                    break;
                case BoxType.Avc1:
                case BoxType.Vc_1:
                    box = new VisualSampleEntryBox(offset, size);
                    break;
                case BoxType.Stpp:
                    box = new SubtitleSampleEntryBox(offset, size);
                    break;
                case BoxType.Encv:
                case BoxType.Enca:
                case BoxType.Enct:
                case BoxType.Encs:
                    box = new ProtectedSampleEntryBox(offset, size, boxType);
                    break;
                case BoxType.Esds:
                    box = new ElementaryStreamDescriptorFullBox(offset, size);
                    break;
                case BoxType.Avcc:
                    box = new AdvancedVideoCodingBox(offset, size);
                    break;
                case BoxType.Wfex:
                    box = new WaveFormatExBox(offset, size);
                    break;
                case BoxType.Dvc1:
                    box = new DigitalVideoCodingBox(offset, size);
                    break;
                case BoxType.Mvex:
                    box = new MovieExtendsBox(offset, size);
                    break;
                case BoxType.Ftyp:
                    box = new FileTypeBox(offset, size);
                    break;
                case BoxType.Mdat:
                    box = new MediaDataBox(offset, size);
                    break;
                case BoxType.Moof:
                    box = new MovieFragmentBox(offset, size);
                    break;
                case BoxType.Mfra:
                    box = new MovieFragmentRandomAccessBox(offset, size);
                    break;
                case BoxType.Tfra:
                    box = new TrackFragmentRandomAccessFullBox(offset, size);
                    break;
                case BoxType.Mfro:
                    box = new MovieFragmentRandomAccessOffsetFullBox(offset, size);
                    break;
                case BoxType.Mfhd:
                    box = new MovieFragmentHeaderFullBox(offset, size);
                    break;
                case BoxType.Traf:
                    box = new TrackFragmentBox(offset, size);
                    break;
                case BoxType.Tfhd:
                    box = new TrackFragmentHeaderFullBox(offset, size);
                    break;
                case BoxType.Trun:
                    box = new TrackFragmentRunFullBox(offset, size);
                    break;
                case BoxType.Sdtp:
                    box = new IndependentAndDisposableSamplesFullBox(offset, size);
                    break;
                case BoxType.Uuid:
                    box = ExtensionBox.GetNextBoxFromStream(stream, offset, (uint)size);
                    box.ExtendedType = stream.ReadGuid();
                    break;
                case BoxType.Pdin:
                    box = new ProgressiveDownloadInfoFullBox(offset, size);
                    break;
                case BoxType.Bloc:
                    box = new BaseLocationFullBox(offset, size);
                    break;
                case BoxType.Ainf:
                    box = new AssetInformationFullBox(offset, size);
                    break;
                case BoxType.Xml:
                    box = new XmlFullBox(offset, size);
                    break;
                case BoxType.Bxml:
                    box = new BinaryXmlFullBox(offset, size);
                    break;
                case BoxType.Iloc:
                    box = new ItemLocationFullBox(offset, size);
                    break;
                case BoxType.Idat:
                    box = new ItemDataBox(offset, size);
                    break;
                case BoxType.Meta:
                    box = new MetaFullBox(offset, size);
                    break;
                case BoxType.Free:
                case BoxType.Skip:
                    box = new FreeSpaceBox(offset, size);
                    break;
                case BoxType.Trik:
                    box = new TrickPlayFullBox(offset, size);
                    break;
                case BoxType.Btrt:
                    box = new BitRateBox(offset, size);
                    break;
                case BoxType.Sthd:
                    box = new SubtitleMediaHeaderFullBox(offset, size);
                    break;
                case BoxType.Subs:
                    box = new SubSampleInformationFullBox(offset, size);
                    break;
                case BoxType.Tfdt:
                    box = new TrackFragmentBaseMediaDecodeTimeFullBox(offset, size);
                    break;
                case BoxType.Saiz:
                    box = new SampleAuxiliaryInformationSizesFullBox(offset, size);
                    break;
                case BoxType.Saio:
                    box = new SampleAuxiliaryInformationOffsetsFullBox(offset, size);
                    break;
                case BoxType.Prft:
                    box = new ProducerReferenceTimeFullBox(offset, size);
                    break;
                case BoxType.Pssh:
                    box = new ProtectionSystemSpecificHeaderFullBox(offset, size);
                    break;
                case BoxType.Tenc:
                    box = new TrackEncryptionFullBox(offset, size);
                    break;
                case BoxType.Senc:
                    box = new SampleEncryptionFullBox(offset, size);
                    break;
                case BoxType.Schi:
                    box = new SchemeInformationBox(offset, size);
                    break;
                case BoxType.Sinf:
                    box = new ProtectedSchemeInformationBox(offset, size);
                    break;
                case BoxType.Avcn:
                    box = new AVCNALBox(offset, size);
                    break;
                case BoxType.Sidx:
                    box = new SegmentIndexBox(offset, size);
                    break;
                case BoxType.Stsc:
                    box = new SampleChunkBox(offset, size);
                    break;
                case BoxType.Stsz:
                    box = new SampleSizeBox(offset, size);
                    break;
                case BoxType.Stco:
                    box = new SampleChunkOffsetBox(offset, size);
                    break;
                case BoxType.Iods:
                    box = new InitialObjectDescriptorBox(offset, size);
                    break;
                default:
                    stream.GotoEndOfBox(offset, size);
                    break;
            }

            if (box != null)
            {
                box.ReadBoxFromStream(stream);
            }

            return box;
        }