Beispiel #1
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
        }
Beispiel #2
0
        private async Task <WebRequestorResponse> DownloadManifestAsync(Uri source, CancellationToken c)
        {
            // download and convert the manifest
            var response = await WebRequestor.GetResponseAsync(source);

            c.ThrowIfCancellationRequested();
            // convert the DASH stream to Smooth Streaming format
            XDocument sourceXml = XDocument.Load(response.Stream);
            Stream    destStream;

            switch (sourceXml.Root.Name.LocalName)
            {
            case "SmoothStreamingMedia":
                destStream = response.Stream;
                break;

            case "MPD":
                response.Stream.Dispose();     // we don't need it anymore
                var conversionResult = await DashManifestConverter.ConvertToSmoothManifest(sourceXml, source);

                destStream  = conversionResult.Manifest.ToStream();
                ChunkLookup = conversionResult.ChunkLookup;
                break;

            default:
                throw new NotImplementedException();
            }

            if (ManifestRequested != null)
            {
                var destXml = new StreamReader(destStream).ReadToEnd();
                ManifestRequested(this, new ManifestRequestedEventArgs(source, sourceXml.ToString(), destXml));
            }

            destStream.Seek(0, SeekOrigin.Begin);
            response.Stream = destStream;
            return(response);
        }
Beispiel #3
0
 private static async Task <WebRequestorResponse> DownloadFragment(Uri uri, long offset, long size)
 {
     return(await WebRequestor.GetResponseAsync(uri, offset, offset + size - 1));
 }
Beispiel #4
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));
 }