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++;
            }
        }
Esempio n. 2
0
        private async Task <WebRequestorResponse> GetChunkAsync(Uri source, CancellationToken c)
        {
            if (ChunkLookup != null && ChunkLookup.Any())
            {
                var key = source.AbsolutePath;

                if (ChunkLookup.ContainsKey(key))
                {
                    ChunkLocation chunkLocation = ChunkLookup[key];
                    if (ChunkRequested != null)
                    {
                        ChunkRequested(this, new ChunkRequestedEventArgs(source, chunkLocation.Uri, string.Format("{0}-{1}", chunkLocation.From, chunkLocation.To)));
                    }
                    return(await DownloadResolvedChunkAsync(source, chunkLocation, c));
                }
            }
            if (ChunkRequested != null)
            {
                ChunkRequested(this, new ChunkRequestedEventArgs(source, source, null));
            }
#if SILVERLIGHT // SILVERLIGHT requires that we download the chunk
            return(await WebRequestor.GetResponseAsync(source));
#else
            return(null);
#endif
        }
        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++;
            }
        }
 private static async Task<WebRequestorResponse> DownloadResolvedChunkAsync(Uri source, ChunkLocation chunkLocation, CancellationToken c)
 {
     // download the chunk and keep the stream open
     return await WebRequestor.GetResponseAsync(chunkLocation.Uri, (long)chunkLocation.From, (long)chunkLocation.To);
 }
Esempio n. 5
0
 private static async Task <WebRequestorResponse> DownloadResolvedChunkAsync(Uri source, ChunkLocation chunkLocation, CancellationToken c)
 {
     // download the chunk and keep the stream open
     return(await WebRequestor.GetResponseAsync(chunkLocation.Uri, (long)chunkLocation.From, (long)chunkLocation.To));
 }