protected void UploadAction(object o) { Exception last_exception = new Exception("Unknown error"); for (int i = 0; i < 10; i++) { try { ChunkDetail cd = null; lock (SyncRoot) { lock (WaitingChunks) { cd = WaitingChunks.Peek(); Transform(cd.SourceFilePath, cd.StreamIndex, cd.ChunkIndex); WaitingChunks.Dequeue(); return; } } } catch (Exception ex) { last_exception = ex; System.Diagnostics.Debug.WriteLine("ChunkTransformer.cs: IIS Push failed", ex.Message + "\r\n" + ex.StackTrace); } } WaitingChunks.Dequeue(); //drop the failing fragment. System.Diagnostics.Debug.Fail("ChunkTransformer.cs: IIS Push failed", last_exception.Message + "\r\n" + last_exception.StackTrace); System.Threading.Thread.CurrentThread.Abort(); }
public void ConsumeChunk(int ChunkIndex, int StreamIndex, string FilePath, double chunkDuration) { lock (SyncRoot) { lock (WaitingChunks) { var message = new ChunkDetail(FilePath, ChunkIndex, StreamIndex, chunkDuration); WaitingChunks.Enqueue(message); } } UploadAction(null); }
/// <summary> /// Signal the output to consume the given chunk. /// Should only be called by the encoder. /// </summary> public void NewChunkAvailable(int ChunkIndex, int StreamIndex, double CaptureDuration) { if (SelectedHandler == null) { throw new Exception("Output handler was not initialised"); } string joined = Path.Combine(Config.EncoderSettings.LocalSystemOutputFolder, Config.EncoderSettings.LocalSystemFilePrefix); string chunk_path = joined + "_" + StreamIndex + "-" + ChunkIndex.ToString("00000") + ".ts"; ChunkDetail chunk = new ChunkDetail(chunk_path, ChunkIndex, StreamIndex, CaptureDuration); lock (ChunksCompleted) { ChunksCompleted.Enqueue(chunk); } if (EnableOutput) { // Force work on a seperate thread, to prevent any interference with encoding. // Encoder output to local system SHOULD be unaffected by delays in output handler. // Final output MAY be delayed, but SHOULD be correct. System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ChunkAction)); } }
/// <summary> /// Signal the output to consume the given chunk. /// Should only be called by the encoder. /// </summary> public void NewChunkAvailable(int ChunkIndex, int StreamIndex, double CaptureDuration) { if (SelectedHandler == null) throw new Exception("Output handler was not initialised"); string joined = Path.Combine(Config.EncoderSettings.LocalSystemOutputFolder, Config.EncoderSettings.LocalSystemFilePrefix); string chunk_path = joined + "_" + StreamIndex + "-" + ChunkIndex.ToString("00000") + ".ts"; ChunkDetail chunk = new ChunkDetail(chunk_path, ChunkIndex, StreamIndex, CaptureDuration); lock (ChunksCompleted) { ChunksCompleted.Enqueue(chunk); } if (EnableOutput) { // Force work on a seperate thread, to prevent any interference with encoding. // Encoder output to local system SHOULD be unaffected by delays in output handler. // Final output MAY be delayed, but SHOULD be correct. System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ChunkAction)); } }
public void ConsumeChunk(int ChunkIndex, int StreamIndex, string FilePath, double chunkDuration) { lock (SyncRoot) { lock (WaitingChunks) { var message = new ChunkDetail(FilePath, ChunkIndex, StreamIndex, chunkDuration); WaitingChunks.Enqueue(message); } } UploadAction(null); }
/// <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 }); }