public async Task ExtractAllAttachments( string inputFile, MediaSourceInfo mediaSource, string outputPath, CancellationToken cancellationToken) { var semaphore = _semaphoreLocks.GetOrAdd(outputPath, key => new SemaphoreSlim(1, 1)); await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false); try { if (!Directory.Exists(outputPath)) { await ExtractAllAttachmentsInternal( _mediaEncoder.GetInputArgument(inputFile, mediaSource), outputPath, cancellationToken).ConfigureAwait(false); } } finally { semaphore.Release(); } }
/// <summary> /// Extracts the text subtitle. /// </summary> /// <param name="inputFiles">The input files.</param> /// <param name="protocol">The protocol.</param> /// <param name="subtitleStreamIndex">Index of the subtitle stream.</param> /// <param name="outputCodec">The output codec.</param> /// <param name="outputPath">The output path.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> /// <exception cref="ArgumentException">Must use inputPath list overload</exception> private async Task ExtractTextSubtitle( string[] inputFiles, MediaProtocol protocol, int subtitleStreamIndex, string outputCodec, string outputPath, CancellationToken cancellationToken) { var semaphore = GetLock(outputPath); await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false); try { if (!File.Exists(outputPath)) { await ExtractTextSubtitleInternal( _mediaEncoder.GetInputArgument(inputFiles, protocol), subtitleStreamIndex, outputCodec, outputPath, cancellationToken).ConfigureAwait(false); } } finally { semaphore.Release(); } }
private async Task ExtractAttachment( string inputFile, MediaProtocol protocol, int attachmentStreamIndex, string outputPath, CancellationToken cancellationToken) { var semaphore = _semaphoreLocks.GetOrAdd(outputPath, key => new SemaphoreSlim(1, 1)); await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false); try { if (!File.Exists(outputPath)) { await ExtractAttachmentInternal( _mediaEncoder.GetInputArgument(new[] { inputFile }, protocol), attachmentStreamIndex, outputPath, cancellationToken).ConfigureAwait(false); } } finally { semaphore.Release(); } }