示例#1
0
 /// <summary>
 /// Downloads a new chunk
 /// </summary>
 /// <param name="baseUrl">the base url of the file to download</param>
 /// <param name="urlGenerator">the class that will generator the url for this chunk</param>
 /// <param name="chunk">the chunk we are trying to download</param>
 /// <param name="completeCallback">the event handler to call when we are complete</param>
 /// <param name="instance">A unique id to group downloads. Can be used to group audio and video downloads separately</param>
 public static void Start(
     string baseUrl,
     IUrlGenerator urlGenerator,
     MediaChunk chunk,
     EventHandler<DownloadCompleteEventArgs> completeCallback,
     Guid instance)
 {
     Tracer.Assert(chunk.Bitrate > 0, String.Format(CultureInfo.InvariantCulture, "Cannot load chunk {0} with zero bitrate.", chunk.Sid));
     Downloader downloader = new Downloader(baseUrl, urlGenerator, chunk, completeCallback, instance);
     downloader.StartDownload();
 }
        /// <summary>
        /// Fired when a download is complete
        /// </summary>
        /// <param name="sender">object that sent it to us</param>
        /// <param name="args">download complete evet args</param>
        private void ReportDownloadComplete(object sender, Downloader.DownloadCompleteEventArgs args)
        {
            MediaChunk chunk = args.Chunk;
            try
            {
                if (chunk.State == MediaChunk.ChunkState.Error)
                {
                    Tracer.Trace(TraceChannel.Error, "Media data chunk {0} ({2} kbps) was not loaded, chunk state is {1}.", chunk.Sid, chunk.State, chunk.Bitrate);
                }
                else if (chunk.State == MediaChunk.ChunkState.Loaded)
                {
                    m_workQueue.Enqueue(new WorkQueueElement(WorkQueueElement.Command.ParseChunk, chunk));
                    m_manifestInfo.GetStreamInfoForStreamType(chunk.MediaType).Queue.UpdateBufferSizes();
                }

                // Send this message to our heuristics module
                m_heuristics.OnDownloadCompleted(chunk.StreamId, chunk.ChunkId, chunk.Bitrate, chunk.DownloadStartTime, chunk.DownloadCompleteTime, chunk.Length);

                // Fire our public chunk download event for anyone listening
                if (MediaChunkDownloaded != null)
                {
                    MediaChunkDownloaded(this, new MediaChunkDownloadedEventArgs(chunk.StreamId, chunk.ChunkId, chunk.Bitrate));
                }
            }
            catch (AdaptiveStreamingException e)
            {
                RaiseError(e);
            }
            catch (Exception e)
            {
                RaiseError(e);
                throw;
            }
        }