protected void UploadAction(object o)
 {
     lock (waitingChunks) {
         while (waitingChunks.Count > 0)
         {
             Exception last_exception = new Exception("Unknown error");
             for (int i = 0; i < 10; i++)
             {
                 try {
                     ChunkDetail cd = null;
                     lock (SyncRoot) {
                         cd = waitingChunks.Peek();
                         SendChunk(cd);
                         waitingChunks.Dequeue();
                         return;
                     }
                 } catch (Exception ex) {
                     last_exception = ex;
                     System.Diagnostics.Debug.WriteLine("UploadManager.cs: HTTP Live transfer failed", ex.Message + "\r\n" + ex.StackTrace);
                 }
             }
             waitingChunks.Dequeue();                     //drop the failing fragment.
             System.Diagnostics.Debug.Fail("UploadManager.cs: HTTP Live transfer failed", last_exception.Message + "\r\n" + last_exception.StackTrace);
             System.Threading.Thread.CurrentThread.Abort();
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Add a chunk to the playlist and write.
 /// </summary>
 public void AddChunk(int index, double duration)
 {
     lock (SyncRoot) {
         var cd = new ChunkDetail(index, 0, duration);
         if (!ChunkIndices.Contains(cd))
         {
             ChunkIndices.Add(cd);
         }
         ChunkIndices.Sort();                 // just in case the uploads go out-of-order.
         WritePlaylist();
         TransportPlaylist();
     }
 }
        private void SendChunk(ChunkDetail chunk)
        {
            string frag = "-" + chunk.ChunkIndex.ToString("00000") + ".ts";
            string fn   = pre + frag;


            using (Stream fs = File.Open(chunk.SourceFilePath, FileMode.Open)) {
                TransferAgent.Transfer(fs, new Uri(dest + fn));
            }
            OnUploadComplete(this, new ChunkUploadedEventArgs()
            {
                ChunkIndex = chunk.ChunkIndex, ChunkDuration = chunk.ChunkDuration, SourceFilePath = chunk.SourceFilePath
            });
        }