-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only create pipes when pipes are enabled.
Remove duplication between BlobStream and BlobSource. Refactor the pipe code. Fixes #151
- Loading branch information
Showing
6 changed files
with
85 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"profiles": { | ||
"AMSMigrate": { | ||
"commandName": "Project", | ||
"commandLineArgs": "assets -s b2c12710-ecdf-4532-9ba6-7e74a219b5f2 --break-output-lease --keep-working-folder --enable-live-asset -g pohhsuTest -n pohhsumediaservice -f \"name eq 'asset-audio-leading-audio-discontinuity'\" --skip-migrated false -t \"$web/bug/${AssetName}\" -o amsencodermsitest" | ||
}, | ||
"Docker": { | ||
"commandName": "Docker", | ||
"commandLineArgs": "analyze -s b2c12710-ecdf-4532-9ba6-7e74a219b5f2 -g provenance -n provenanceuswc" | ||
}, | ||
"WSL": { | ||
"commandName": "WSL2", | ||
"commandLineArgs": "AMSMigrate.dll assets -s b2c12710-ecdf-4532-9ba6-7e74a219b5f2 --break-output-lease --keep-working-folder --enable-live-asset -g pohhsuTest -n pohhsumediaservice -f \"name eq 'asset-audio-leading-audio-discontinuity'\" --skip-migrated false -t \"$web/bug/${AssetName}\" -o amsencodermsitest", | ||
"distributionName": "" | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,80 @@ | ||
using AMSMigrate.Decryption; | ||
| ||
using AMSMigrate.Decryption; | ||
using Azure.ResourceManager.Media.Models; | ||
using Azure.Storage.Blobs; | ||
using Azure.Storage.Blobs.Models; | ||
using Azure.Storage.Blobs.Specialized; | ||
using FFMpegCore.Pipes; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace AMSMigrate.Pipes | ||
{ | ||
internal class BlobSource : IPipeSource | ||
sealed class BlobSource : IPipeSource | ||
{ | ||
private static readonly IReadOnlyDictionary<string, string> ExtensionToFormatMap = new Dictionary<string, string> | ||
{ | ||
{ ".ts", "mpegts" }, | ||
{ ".vtt", "webvtt" } | ||
}; | ||
|
||
private readonly BlockBlobClient _blobClient; | ||
private readonly StorageEncryptedAssetDecryptionInfo? _decryptInfo; | ||
private readonly ILogger _logger; | ||
private readonly BlockBlobClient _blob; | ||
private readonly StorageEncryptedAssetDecryptionInfo? _decryptInfo; | ||
|
||
public BlobSource(BlockBlobClient blobClient, StorageEncryptedAssetDecryptionInfo? decryptInfo, ILogger logger) | ||
public BlobSource(BlobContainerClient container, string blobName, StorageEncryptedAssetDecryptionInfo? decryptInfo, ILogger logger) : | ||
this(container.GetBlockBlobClient(blobName), decryptInfo, logger) | ||
{ | ||
_blobClient = blobClient; | ||
_decryptInfo = decryptInfo; | ||
_logger = logger; | ||
} | ||
|
||
public string GetStreamArguments() | ||
public BlobSource(BlockBlobClient blob, StorageEncryptedAssetDecryptionInfo? decryptInfo, ILogger logger) | ||
{ | ||
var extension = Path.GetExtension(_blobClient.Name); | ||
if (!ExtensionToFormatMap.TryGetValue(extension, out var format)) | ||
{ | ||
format = "mp4"; // fallback to mp4. | ||
} | ||
return $"-f {format}"; | ||
_blob = blob; | ||
_logger = logger; | ||
_decryptInfo = decryptInfo; | ||
} | ||
|
||
public async Task WriteAsync(Stream outputStream, CancellationToken cancellationToken) | ||
public async Task DownloadAsync(Stream stream, CancellationToken cancellationToken) | ||
{ | ||
_logger.LogDebug("Begin downloading track: {name}", _blobClient.Name); | ||
var options = new BlobDownloadOptions | ||
{ | ||
ProgressHandler = new Progress<long>( | ||
progress => | ||
{ | ||
_logger.LogTrace("Download progress of blob {blob} is {progress}", _blobClient.Name, progress); | ||
}) | ||
}; | ||
using BlobDownloadStreamingResult result = await _blobClient.DownloadStreamingAsync(options, cancellationToken); | ||
try | ||
_logger.LogDebug("Begin downloading {name}", _blob.Name); | ||
|
||
using var aesTransform = AssetDecryptor.GetAesCtrTransform(_decryptInfo, _blob.Name, false); | ||
|
||
if (aesTransform != null) | ||
{ | ||
await result.Content.CopyToAsync(outputStream, cancellationToken); | ||
_logger.LogDebug("Finished downloading track: {name}", _blobClient.Name); | ||
await AssetDecryptor.DecryptTo(aesTransform, _blob, stream, cancellationToken); | ||
} | ||
catch (Exception ex) | ||
else | ||
{ | ||
_logger.LogError(ex, "Failed to download {blob}", _blobClient.Name); | ||
throw; | ||
await _blob.DownloadToAsync(stream, cancellationToken: cancellationToken); | ||
} | ||
|
||
_logger.LogDebug("Finished download of {name}", _blob.Name); | ||
} | ||
|
||
public async Task DownloadAsync(string filePath, CancellationToken cancellationToken) | ||
{ | ||
using var aesTransform = AssetDecryptor.GetAesCtrTransform(_decryptInfo, _blobClient.Name, false); | ||
using var stream = File.OpenWrite(filePath); | ||
await DownloadAsync(stream, cancellationToken); | ||
} | ||
|
||
if (aesTransform != null) | ||
{ | ||
await AssetDecryptor.DecryptTo(aesTransform, _blobClient, filePath, cancellationToken); | ||
} | ||
else | ||
public async Task UploadAsync(Stream stream, CancellationToken cancellationToken) | ||
{ | ||
BlobContentInfo info = await _blob.UploadAsync(stream, cancellationToken: cancellationToken); | ||
} | ||
|
||
public string GetStreamArguments() | ||
{ | ||
var extension = Path.GetExtension(_blob.Name); | ||
if (!ExtensionToFormatMap.TryGetValue(extension, out var format)) | ||
{ | ||
await _blobClient.DownloadToAsync(filePath, cancellationToken); | ||
format = "mp4"; // fallback to mp4. | ||
} | ||
return $"-f {format}"; | ||
} | ||
|
||
public async Task WriteAsync(Stream outputStream, CancellationToken cancellationToken) | ||
{ | ||
await DownloadAsync(outputStream, cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.