コード例 #1
0
        public static SmoothStreamingMediaStreamIndex GenerateClientManifestStreamIndex(ManifestTrack track, Box moov)
        {
            var streamIndex = new SmoothStreamingMediaStreamIndex();
            streamIndex.Type = track.Type.ToString().ToLower();

            var qualityLevel = new SmoothStreamingMediaStreamIndexQualityLevel();
            streamIndex.QualityLevel.Add(qualityLevel);
            streamIndex.TimeScale = track.TimeScale;

            var mdhd = moov.InnerBoxes.Single(box =>
                    box.Type == BoxType.Trak
                    && (box.InnerBoxes.Single(tkhd => tkhd.Type == BoxType.Tkhd) as TrackHeaderFullBox).TrackId == track.Id)
                .InnerBoxes.Single(box => box.Type == BoxType.Mdia)
                .InnerBoxes.Single(box => box.Type == BoxType.Mdhd) as MediaHeaderFullBox;

            streamIndex.Language = mdhd.Language;

            switch (track.Type)
            {
                case ManifestTrackType.Video:
                    //populate track
                    streamIndex.MaxHeight = track.Height;
                    streamIndex.MaxWidth = track.Width;
                    streamIndex.DisplayWidth = track.DisplayWidth;
                    streamIndex.DisplayHeight = track.DisplayHeight;

                    //populate quality level
                    qualityLevel.Index = 0;
                    qualityLevel.Bitrate = track.Bitrate;
                    qualityLevel.FourCC = track.FourCodecCode;
                    qualityLevel.MaxHeight = track.Height;
                    qualityLevel.MaxWidth = track.Width;
                    qualityLevel.CodecPrivateData = track.CodecPrivateData;

                    break;
                case ManifestTrackType.Audio:

                    streamIndex.FourCC = track.FourCodecCode;
                    streamIndex.Index = 0;

                    //populate quality level
                    qualityLevel.Bitrate = track.Bitrate;
                    qualityLevel.SamplingRate = track.SampleRate;
                    qualityLevel.Channels = track.ChannelCount;
                    qualityLevel.BitsPerSample = track.SampleSize;
                    qualityLevel.PacketSize = track.PacketSize;
                    qualityLevel.AudioTag = track.AudioTag;
                    qualityLevel.CodecPrivateData = track.CodecPrivateData;
                    qualityLevel.FourCC = track.FourCodecCode;

                    break;
                case ManifestTrackType.Text:
                    int i = 0;
                    i++;
                    break;
            }

            if (track.Fragments != null)
            {
                streamIndex.c.AddRange(GenerateClientManifestChunks(track, moov));
                streamIndex.Chunks = (uint)streamIndex.c.Count;
            }
            return streamIndex;
        }
コード例 #2
0
        private static IEnumerable<KeyValuePair<string, ChunkLocation>> GetChunkLookups(SmoothStreamingMediaStreamIndex streamIndex, SmoothStreamingMediaStreamIndexQualityLevel track, Uri chunkUri, SegmentIndexBox sidx)
        {
            int i = 0;
            ulong byteOffset = sidx.FirstOffset;
            ulong timeOffset = 0;
            foreach (var c in streamIndex.c)
            {
                var subsegment = sidx.Subsegments[i];
                // create a lookup table for each chunk
                var key = "/" + streamIndex.Url
                    .Replace("{bitrate}", track.Bitrate.ToString())
                    .Replace("{start time}", timeOffset.ToString());

                var location = new ChunkLocation()
                {
                    Uri = chunkUri,
                    From = byteOffset,
                    To = byteOffset += subsegment.ReferencedSize
                };
                yield return new KeyValuePair<string, ChunkLocation>(key, location);

                timeOffset += subsegment.Duration;
                i++;
            }
        }
コード例 #3
0
        public static SmoothStreamingMediaStreamIndex GenerateClientManifestStreamIndex(ManifestTrack track, Box moov)
        {
            var streamIndex = new SmoothStreamingMediaStreamIndex();

            streamIndex.Type = track.Type.ToString().ToLower();

            var qualityLevel = new SmoothStreamingMediaStreamIndexQualityLevel();

            streamIndex.QualityLevel.Add(qualityLevel);
            streamIndex.TimeScale = track.TimeScale;

            var mdhd = moov.InnerBoxes.Single(box =>
                                              box.Type == BoxType.Trak &&
                                              (box.InnerBoxes.Single(tkhd => tkhd.Type == BoxType.Tkhd) as TrackHeaderFullBox).TrackId == track.Id)
                       .InnerBoxes.Single(box => box.Type == BoxType.Mdia)
                       .InnerBoxes.Single(box => box.Type == BoxType.Mdhd) as MediaHeaderFullBox;

            streamIndex.Language = mdhd.Language;

            switch (track.Type)
            {
            case ManifestTrackType.Video:
                //populate track
                streamIndex.MaxHeight     = track.Height;
                streamIndex.MaxWidth      = track.Width;
                streamIndex.DisplayWidth  = track.DisplayWidth;
                streamIndex.DisplayHeight = track.DisplayHeight;

                //populate quality level
                qualityLevel.Index            = 0;
                qualityLevel.Bitrate          = track.Bitrate;
                qualityLevel.FourCC           = track.FourCodecCode;
                qualityLevel.MaxHeight        = track.Height;
                qualityLevel.MaxWidth         = track.Width;
                qualityLevel.CodecPrivateData = track.CodecPrivateData;

                break;

            case ManifestTrackType.Audio:

                streamIndex.FourCC = track.FourCodecCode;
                streamIndex.Index  = 0;

                //populate quality level
                qualityLevel.Bitrate          = track.Bitrate;
                qualityLevel.SamplingRate     = track.SampleRate;
                qualityLevel.Channels         = track.ChannelCount;
                qualityLevel.BitsPerSample    = track.SampleSize;
                qualityLevel.PacketSize       = track.PacketSize;
                qualityLevel.AudioTag         = track.AudioTag;
                qualityLevel.CodecPrivateData = track.CodecPrivateData;
                qualityLevel.FourCC           = track.FourCodecCode;

                break;

            case ManifestTrackType.Text:
                int i = 0;
                i++;
                break;
            }

            if (track.Fragments != null)
            {
                streamIndex.c.AddRange(GenerateClientManifestChunks(track, moov));
                streamIndex.Chunks = (uint)streamIndex.c.Count;
            }
            return(streamIndex);
        }