/// <summary> /// Transfer task. Retrieves data from underlying storage and pushes it down /// to ESPlayer /// </summary> /// <param name="token">CancellationToken</param> private async Task TransferTask() { CancellationToken token = transferCts.Token; logger.Info($"{streamType}: Started"); try { while (!token.IsCancellationRequested) { var shouldContinue = await ProcessNextPacket(token); if (!shouldContinue) { break; } await _dataSynchronizer.Synchronize(streamType, token); } } catch (InvalidOperationException e) { logger.Error(e, $"{streamType}: Stream completed"); } catch (OperationCanceledException) { logger.Info($"{streamType}: Transfer cancelled"); } catch (PacketSubmitException pse) { logger.Error(pse, $"{streamType}: Submit Error " + pse.SubmitStatus); DisableInput(); } catch (DrmException drme) { logger.Error(drme, $"{streamType}: Decrypt Error"); DisableInput(); playbackErrorSubject.OnNext("Playback Error"); } catch (Exception e) { // Dump unhandled exception. Running as a task so they will not be reported. logger.Error(e, $"{streamType}"); DisableInput(); playbackErrorSubject.OnNext("Playback Error"); } finally { if (_firstDataPacketTcs?.Task.IsCompleted == false) { logger.Info($"{streamType}: Cancelling first data packet request"); _firstDataPacketTcs.TrySetException( new OperationCanceledException("Terminated before notifying first data packet")); } logger.Info($"{streamType}: Terminated. "); } }
/// <summary> /// Transfer task. Retrieves data from underlying storage and pushes it down /// to ESPlayer /// </summary> /// <param name="token">CancellationToken</param> private async Task TransferTask(CancellationToken token) { logger.Info($"{streamType}: Started"); _bufferingSubject.OnNext(true); try { while (!token.IsCancellationRequested) { var shouldContinue = await ProcessNextPacket(token); if (!shouldContinue) { break; } await _dataSynchronizer.Synchronize(streamType, token); } } catch (InvalidOperationException e) { logger.Error(e, $"{streamType}: Stream completed"); } catch (OperationCanceledException) { logger.Info($"{streamType}: Transfer cancelled"); } catch (PacketSubmitException pse) { logger.Error(pse, $"{streamType}: Submit Error " + pse.SubmitStatus); DisableInput(); } catch (DrmException drme) { logger.Error(drme, $"{streamType}: Decrypt Error"); DisableInput(); playbackErrorSubject.OnNext("Playback Error"); } catch (Exception e) { // Dump unhandled exception. Running as a task so they will not be reported. logger.Error(e, $"{streamType}"); DisableInput(); playbackErrorSubject.OnNext("Playback Error"); } finally { _packetProcessed.OnNext(typeof(EOSPacket)); _bufferingSubject.OnNext(false); logger.Info($"{streamType}: Terminated. "); } }