CreateAndSubmitOneTaskJob() public static method

public static CreateAndSubmitOneTaskJob ( CloudMediaContext context, string name, IMediaProcessor mediaProcessor, string preset, IAsset asset, TaskOptions options ) : IJob
context CloudMediaContext
name string
mediaProcessor IMediaProcessor
preset string
asset IAsset
options TaskOptions
return IJob
        private IAsset RunJobAndGetOutPutAsset(string jobName, out IAsset asset, out IJob job)
        {
            asset = CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.StorageEncrypted);
            IMediaProcessor mediaProcessor = JobTests.GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName);

            job = JobTests.CreateAndSubmitOneTaskJob(_mediaContext, jobName, mediaProcessor, JobTests.GetWamePreset(mediaProcessor), asset, TaskOptions.None);
            JobTests.WaitForJob(job.Id, JobState.Finished, JobTests.VerifyAllTasksFinished);
            Assert.IsTrue(job.OutputMediaAssets.Count > 0);
            IAsset outasset = job.OutputMediaAssets[0];

            Assert.IsNotNull(outasset);
            return(outasset);
        }
Example #2
0
        public void ApplyDynamicManifestFilter()
        {
            const string typeAudio = "Type=\"audio\"";
            const string typeVideo = "Type=\"video\"";

            string          configuration  = File.ReadAllText(WindowsAzureMediaServicesTestConfiguration.DefaultMp4ToSmoothConfig);
            IAsset          inputAsset     = AssetTests.CreateAsset(_mediaContext, WindowsAzureMediaServicesTestConfiguration.SmallMp41, AssetCreationOptions.None);
            IMediaProcessor mediaProcessor = JobTests.GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpPackagerName);
            IJob            job            = JobTests.CreateAndSubmitOneTaskJob(_mediaContext, "ApplyDynamicManifestFilter" + Guid.NewGuid().ToString().Substring(0, 5), mediaProcessor, configuration, inputAsset, TaskOptions.None);

            JobTests.WaitForJob(job.Id, JobState.Finished, JobTests.VerifyAllTasksFinished);


            var outputAsset = job.OutputMediaAssets.FirstOrDefault();

            outputAsset = _mediaContext.Assets.Where(c => c.Id == outputAsset.Id).FirstOrDefault();
            var assetFile = outputAsset.AssetFiles.Where(c => c.Name.EndsWith(".ism")).First();

            IAccessPolicy policy        = _mediaContext.AccessPolicies.Create("ApplyDynamicManifestFilter" + Guid.NewGuid().ToString().Substring(0, 5), TimeSpan.FromDays(30), AccessPermissions.Read);
            ILocator      originLocator = _mediaContext.Locators.CreateLocator(LocatorType.OnDemandOrigin, outputAsset, policy, DateTime.UtcNow.AddMinutes(-5));

            string     urlForClientStreaming = originLocator.Path + assetFile.Name + "/manifest";
            HttpClient client  = new HttpClient();
            var        message = client.GetAsync(urlForClientStreaming).Result;
            var        content = message.Content;
            var        result  = content.ReadAsStringAsync().Result;

            Assert.AreEqual(message.StatusCode, HttpStatusCode.OK);
            Assert.IsTrue(result.Length > 0);

            Assert.IsTrue(result.Contains(typeAudio));

            Assert.IsTrue(result.Contains(typeVideo));

            var manifestLength = result.Length;

            // string filterName = "ApplyDynamicManifestFilter_" + DateTime.Now;
            string filterName = "ApplyDynamicManifestFilter_" + Guid.NewGuid().ToString().Substring(0, 5);
            List <FilterTrackSelectStatement> filterTrackSelectStatements = new List <FilterTrackSelectStatement>();
            FilterTrackSelectStatement        filterTrackSelectStatement  = new FilterTrackSelectStatement();

            filterTrackSelectStatement.PropertyConditions = new List <IFilterTrackPropertyCondition>();
            filterTrackSelectStatement.PropertyConditions.Add(new FilterTrackTypeCondition(FilterTrackType.Video, FilterTrackCompareOperator.NotEqual));
            filterTrackSelectStatements.Add(filterTrackSelectStatement);
            IStreamingFilter filter = _mediaContext.Filters.Create(filterName, new PresentationTimeRange(), filterTrackSelectStatements);

            Assert.IsNotNull(filter);


            var        filterUrlForClientStreaming = originLocator.Path + assetFile.Name + String.Format("/manifest(filter={0})", filterName);
            HttpClient filterclient  = new HttpClient();
            var        filtermessage = filterclient.GetAsync(filterUrlForClientStreaming).Result;

            Assert.AreEqual(filtermessage.StatusCode, HttpStatusCode.OK);
            var filtercontent = filtermessage.Content;
            var filterresult  = filtercontent.ReadAsStringAsync().Result;

            Assert.IsTrue(filterresult.Length > 0);
            Assert.AreNotEqual(manifestLength, filterresult);
            Assert.IsTrue(filterresult.Contains(typeAudio));
            Assert.IsFalse(filterresult.Contains(typeVideo));

            outputAsset.DeleteAsync();
            inputAsset.DeleteAsync();
            job.DeleteAsync();
            filter.DeleteAsync();
        }