Skip to content

Commit

Permalink
Merge pull request #16 from Azure-Samples/xpouyat/feature/update-wide…
Browse files Browse the repository at this point in the history
…vine-and-packages

Update to sample code - updated Widevine classes, Nugget packages, Bug fix
  • Loading branch information
Juliako authored May 7, 2020
2 parents 07599de + 934cbf8 commit cfbdb61
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 149 deletions.
14 changes: 7 additions & 7 deletions AMSV3Tutorials/AnalyzeVideos/AnalyzeVideos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>

<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<StartupObject />
</PropertyGroup>

Expand All @@ -12,12 +12,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Media" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.3.4" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.2" />
<PackageReference Include="Microsoft.Azure.Management.Media" Version="2.0.4" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.5" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.3" />
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down
40 changes: 19 additions & 21 deletions AMSV3Tutorials/AnalyzeVideos/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

using Microsoft.Azure.Management.Media;
using Microsoft.Azure.Management.Media.Models;
using Microsoft.Azure.Storage.Blob;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Rest;
using Microsoft.Rest.Azure.Authentication;
using Microsoft.WindowsAzure.Storage.Blob;

namespace AnalyzeVideos
{
Expand All @@ -37,7 +37,7 @@ public static async Task Main(string[] args)
{
if (exception.Source.Contains("ActiveDirectory"))
{
Console.Error.WriteLine("TIP: Make sure that you have filled out the appsettings.json file before running this sample.");
Console.Error.WriteLine("TIP: Make sure that you have filled out the appsettings.json file before running this sample.");
}

Console.Error.WriteLine($"{exception.Message}");
Expand Down Expand Up @@ -163,10 +163,10 @@ private static async Task<IAzureMediaServicesClient> CreateMediaServicesClientAs
/// <param name="transformName">The name of the transform.</param>
/// <returns></returns>
// <EnsureTransformExists>
private static async Task<Transform> GetOrCreateTransformAsync(IAzureMediaServicesClient client,
string resourceGroupName,
string accountName,
string transformName,
private static async Task<Transform> GetOrCreateTransformAsync(IAzureMediaServicesClient client,
string resourceGroupName,
string accountName,
string transformName,
Preset preset)
{
// Does a Transform already exist with the desired name? Assume that an existing Transform with the desired name
Expand Down Expand Up @@ -265,7 +265,7 @@ private static async Task<Asset> CreateOutputAssetAsync(IAzureMediaServicesClien
// You may want to update this part to throw an Exception instead, and handle name collisions differently.
string uniqueness = $"-{Guid.NewGuid().ToString("N")}";
outputAssetName += uniqueness;

Console.WriteLine("Warning – found an existing Asset with name = " + assetName);
Console.WriteLine("Creating an Asset with this name instead: " + outputAssetName);
}
Expand Down Expand Up @@ -334,7 +334,7 @@ private static async Task<Job> WaitForJobToFinishAsync(IAzureMediaServicesClient
string transformName,
string jobName)
{
const int SleepIntervalMs = 60 * 1000;
const int SleepIntervalMs = 20 * 1000;

Job job = null;

Expand Down Expand Up @@ -410,8 +410,8 @@ private static async Task DownloadOutputAssetAsync(
// A non-negative integer value that indicates the maximum number of results to be returned at a time,
// up to the per-operation limit of 5000. If this value is null, the maximum possible number of results
// will be returned, up to 5000.
int? ListBlobsSegmentMaxResult = null;
int? ListBlobsSegmentMaxResult = null;

BlobResultSegment segment = await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.None, ListBlobsSegmentMaxResult, continuationToken, null, null);

foreach (IListBlobItem blobItem in segment.Results)
Expand All @@ -438,7 +438,7 @@ private static async Task DownloadOutputAssetAsync(
/// <summary>
/// Deletes the jobs and assets that were created.
/// Generally, you should clean up everything except objects
/// that you are planning to reuse (typically, you will reuse Transforms, and you will persist StreamingLocators).
/// that you are planning to reuse (typically, you will reuse Transforms, and you will persist output assets and StreamingLocators).
/// </summary>
/// <param name="client"></param>
/// <param name="resourceGroupName"></param>
Expand All @@ -449,22 +449,20 @@ private static async Task CleanUpAsync(
IAzureMediaServicesClient client,
string resourceGroupName,
string accountName,
string transformName)
string transformName,
string contentKeyPolicyName,
List<string> assetNames,
string jobName)
{
await client.Jobs.DeleteAsync(resourceGroupName, accountName, transformName, jobName);

var jobs = await client.Jobs.ListAsync(resourceGroupName, accountName, transformName);
foreach (var job in jobs)
foreach (var assetName in assetNames)
{
await client.Jobs.DeleteAsync(resourceGroupName, accountName, transformName, job.Name);
await client.Assets.DeleteAsync(resourceGroupName, accountName, assetName);
}

var assets = await client.Assets.ListAsync(resourceGroupName, accountName);
foreach (var asset in assets)
{
await client.Assets.DeleteAsync(resourceGroupName, accountName, asset.Name);
}
client.ContentKeyPolicies.Delete(resourceGroupName, accountName, contentKeyPolicyName);
}
// </CleanUp>

}
}
2 changes: 1 addition & 1 deletion AMSV3Tutorials/AnalyzeVideos/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"Region": "West US 2",
"ResourceGroup": "amsResourceGroup",
"SubscriptionId": "00000000-0000-0000-0000-000000000000"
}
}
5 changes: 5 additions & 0 deletions AMSV3Tutorials/EncryptWithAES/ConfigWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,10 @@ public string Region
{
get { return _config["Region"]; }
}

public string SymmetricKey
{
get { return _config["SymmetricKey"]; }
}
}
}
16 changes: 8 additions & 8 deletions AMSV3Tutorials/EncryptWithAES/EncryptWithAES.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<StartupObject />
</PropertyGroup>

Expand All @@ -11,14 +11,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.5" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt " Version="5.3.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.3.0"/>
<PackageReference Include="Microsoft.Azure.Management.Media" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1"/>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1"/>
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.3.4" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.2" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.3.0" />
<PackageReference Include="Microsoft.Azure.Management.Media" Version="2.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.3" />
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.4.0" />
<PackageReference Include="System.Security.Claims" Version="4.3.0" />
</ItemGroup>

Expand Down
42 changes: 18 additions & 24 deletions AMSV3Tutorials/EncryptWithAES/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

using Microsoft.Azure.Management.Media;
using Microsoft.Azure.Management.Media.Models;
using Microsoft.Azure.Storage.Blob;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.IdentityModel.Tokens;
using Microsoft.Rest;
using Microsoft.Rest.Azure.Authentication;
using Microsoft.WindowsAzure.Storage.Blob;

namespace EncryptWithAES
{
Expand Down Expand Up @@ -96,14 +96,13 @@ private static async Task RunAsync(ConfigWrapper config)
if (!Directory.Exists(OutputFolderName))
Directory.CreateDirectory(OutputFolderName);

// Generate a new random token signing key to use
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetBytes(TokenSigningKey);
// Set a token signing key that you want to use
TokenSigningKey = Convert.FromBase64String(config.SymmetricKey);

//Create the content key policy that configures how the content key is delivered to end clients
// via the Key Delivery component of Azure Media Services.
ContentKeyPolicy policy = await GetOrCreateContentKeyPolicyAsync(client, config.ResourceGroup, config.AccountName, ContentKeyPolicyName);

StreamingLocator locator = await CreateStreamingLocatorAsync(client, config.ResourceGroup, config.AccountName, outputAsset.Name, locatorName, ContentKeyPolicyName);

// We are using the ContentKeyIdentifierClaim in the ContentKeyPolicy which means that the token presented
Expand All @@ -121,15 +120,15 @@ private static async Task RunAsync(ConfigWrapper config)
Console.WriteLine();
Console.WriteLine($"https://ampdemo.azureedge.net/?url={dashPath}&aes=true&aestoken=Bearer%3D{token}");
Console.WriteLine();

}

Console.WriteLine("When finished press enter to cleanup.");
Console.Out.Flush();
Console.ReadLine();

Console.WriteLine("Cleaning up...");
await CleanUpAsync(client, config.ResourceGroup, config.AccountName, AdaptiveStreamingTransformName, ContentKeyPolicyName);
await CleanUpAsync(client, config.ResourceGroup, config.AccountName, AdaptiveStreamingTransformName, ContentKeyPolicyName, new List<string> { outputAsset.Name }, job.Name);
}
// </RunAsync>

Expand Down Expand Up @@ -287,9 +286,9 @@ private static async Task<Asset> CreateOutputAssetAsync(IAzureMediaServicesClien
// You may want to update this part to throw an Exception instead, and handle name collisions differently.
string uniqueness = $"-{Guid.NewGuid().ToString("N")}";
outputAssetName += uniqueness;

Console.WriteLine("Warning – found an existing Asset with name = " + assetName);
Console.WriteLine("Creating an Asset with this name instead: " + outputAssetName);
Console.WriteLine("Creating an Asset with this name instead: " + outputAssetName);
}

return await client.Assets.CreateOrUpdateAsync(resourceGroupName, accountName, outputAssetName, asset);
Expand Down Expand Up @@ -361,7 +360,7 @@ private static async Task<Job> WaitForJobToFinishAsync(IAzureMediaServicesClient
string transformName,
string jobName)
{
const int SleepIntervalMs = 60 * 1000;
const int SleepIntervalMs = 20 * 1000;

Job job = null;

Expand Down Expand Up @@ -565,8 +564,8 @@ private static async Task DownloadOutputAssetAsync(
// A non-negative integer value that indicates the maximum number of results to be returned at a time,
// up to the per-operation limit of 5000. If this value is null, the maximum possible number of results
// will be returned, up to 5000.
int? ListBlobsSegmentMaxResult = null;
int? ListBlobsSegmentMaxResult = null;

BlobResultSegment segment = await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.None, ListBlobsSegmentMaxResult, continuationToken, null, null);

foreach (IListBlobItem blobItem in segment.Results)
Expand Down Expand Up @@ -594,7 +593,7 @@ private static async Task DownloadOutputAssetAsync(
/// <summary>
/// Deletes the jobs and assets that were created.
/// Generally, you should clean up everything except objects
/// that you are planning to reuse (typically, you will reuse Transforms, and you will persist StreamingLocators).
/// that you are planning to reuse (typically, you will reuse Transforms, and you will persist output assets and StreamingLocators).
/// </summary>
/// <param name="client"></param>
/// <param name="resourceGroupName"></param>
Expand All @@ -606,23 +605,18 @@ private static async Task CleanUpAsync(
string resourceGroupName,
string accountName,
string transformName,
string contentKeyPolicyName)
string contentKeyPolicyName,
List<string> assetNames,
string jobName)
{
await client.Jobs.DeleteAsync(resourceGroupName, accountName, transformName, jobName);

var jobs = await client.Jobs.ListAsync(resourceGroupName, accountName, transformName);
foreach (var job in jobs)
foreach (var assetName in assetNames)
{
await client.Jobs.DeleteAsync(resourceGroupName, accountName, transformName, job.Name);
}

var assets = await client.Assets.ListAsync(resourceGroupName, accountName);
foreach (var asset in assets)
{
await client.Assets.DeleteAsync(resourceGroupName, accountName, asset.Name);
await client.Assets.DeleteAsync(resourceGroupName, accountName, assetName);
}

client.ContentKeyPolicies.Delete(resourceGroupName, accountName, contentKeyPolicyName);

}
// </CleanUp>
}
Expand Down
5 changes: 3 additions & 2 deletions AMSV3Tutorials/EncryptWithAES/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"ArmEndpoint": "https://management.azure.com/",
"Region": "West US 2",
"ResourceGroup": "amsResourceGroup",
"SubscriptionId": "00000000-0000-0000-0000-000000000000"
}
"SubscriptionId": "00000000-0000-0000-0000-000000000000",
"SymmetricKey": "LPLSvB5RuzFxpVqFxWsUsCL2D83zLOFlGV0R8rTp1f+xrQTWXO/XAQ=="
}
16 changes: 8 additions & 8 deletions AMSV3Tutorials/EncryptWithDRM/EncryptWithDRM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<StartupObject />
</PropertyGroup>

Expand All @@ -11,14 +11,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.5" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt " Version="5.3.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.3.0"/>
<PackageReference Include="Microsoft.Azure.Management.Media" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1"/>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1"/>
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.3.4" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.2" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.3.0" />
<PackageReference Include="Microsoft.Azure.Management.Media" Version="2.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.3" />
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.4.0" />
<PackageReference Include="System.Security.Claims" Version="4.3.0" />
</ItemGroup>

Expand Down
Loading

0 comments on commit cfbdb61

Please sign in to comment.