Exemple #1
0
        private static void PublishIndex(IJob job, IAsset asset, JobPublish jobPublish)
        {
            string processorId1 = Constants.Media.ProcessorId.IndexerV1;
            string processorId2 = Constants.Media.ProcessorId.IndexerV2;

            string[] processorIds = new string[] { processorId1, processorId2 };
            ITask[]  jobTasks     = GetJobTasks(job, processorIds);
            if (jobTasks.Length > 0)
            {
                BlobClient blobClient = GetBlobClient(jobPublish);
                foreach (ITask jobTask in jobTasks)
                {
                    IAsset   outputAsset   = jobTask.OutputAssets[0];
                    string   fileExtension = Constants.Media.FileExtension.WebVtt;
                    string[] fileNames     = GetFileNames(outputAsset, fileExtension);
                    foreach (string fileName in fileNames)
                    {
                        string languageCode      = GetLanguageCode(jobTask);
                        string languageExtension = string.Concat(Constants.NamedItemSeparator, languageCode, fileExtension);
                        string languageFileName  = fileName.Replace(fileExtension, languageExtension);
                        blobClient.CopyFile(outputAsset, asset, fileName, languageFileName, false);
                    }
                }
            }
        }
Exemple #2
0
        public static string PublishJob(MediaJobNotification jobNotification, bool webHook)
        {
            string jobPublication = string.Empty;

            if (jobNotification != null && jobNotification.EventType == MediaJobNotificationEvent.JobStateChange &&
                (jobNotification.Properties.NewState == JobState.Error ||
                 jobNotification.Properties.NewState == JobState.Canceled ||
                 jobNotification.Properties.NewState == JobState.Finished))
            {
                if (webHook)
                {
                    string        settingKey    = Constants.AppSettingKey.MediaJobNotificationStorageQueueName;
                    string        queueName     = AppSetting.GetValue(settingKey);
                    MessageClient messageClient = new MessageClient();
                    messageClient.AddMessage(queueName, jobNotification);
                }
                else
                {
                    EntityClient entityClient = new EntityClient();
                    string       tableName    = Constants.Storage.TableName.JobPublish;
                    string       partitionKey = jobNotification.Properties.AccountName;
                    string       rowKey       = jobNotification.Properties.JobId;
                    JobPublish   jobPublish   = entityClient.GetEntity <JobPublish>(tableName, partitionKey, rowKey);
                    if (jobPublish != null)
                    {
                        tableName = Constants.Storage.TableName.JobPublishProtection;
                        ContentProtection contentProtection = entityClient.GetEntity <ContentProtection>(tableName, partitionKey, rowKey);
                        string            accountName       = jobPublish.PartitionKey;
                        string            accountKey        = jobPublish.MediaAccountKey;
                        MediaClient       mediaClient       = new MediaClient(accountName, accountKey);
                        IJob job = mediaClient.GetEntityById(MediaEntity.Job, rowKey) as IJob;
                        if (job != null)
                        {
                            mediaClient.SetProcessorUnits(job, ReservedUnitType.Basic);
                            if (jobNotification.Properties.NewState == JobState.Finished)
                            {
                                PublishContent(mediaClient, job, jobPublish, contentProtection);
                            }
                            string messageText = GetNotificationMessage(accountName, job);
                            MessageClient.SendText(messageText, jobPublish.MobileNumber);
                        }
                        if (contentProtection != null)
                        {
                            tableName = Constants.Storage.TableName.JobPublishProtection;
                            entityClient.DeleteEntity(tableName, contentProtection);
                        }
                        tableName = Constants.Storage.TableName.JobPublish;
                        entityClient.DeleteEntity(tableName, jobPublish);
                    }
                }
            }
            return(jobPublication);
        }
Exemple #3
0
        private static void PublishAnalytics(IJob job, IAsset asset, JobPublish jobPublish)
        {
            string processorId1 = Constants.Media.ProcessorId.FaceDetection;
            string processorId2 = Constants.Media.ProcessorId.FaceRedaction;
            string processorId3 = Constants.Media.ProcessorId.MotionDetection;
            string processorId4 = Constants.Media.ProcessorId.VideoAnnotation;
            string processorId5 = Constants.Media.ProcessorId.CharacterRecognition;
            string processorId6 = Constants.Media.ProcessorId.ContentModeration;

            string[] processorIds = new string[] { processorId1, processorId2, processorId3, processorId4, processorId5, processorId6 };
            ITask[]  jobTasks     = GetJobTasks(job, processorIds);
            if (jobTasks.Length > 0)
            {
                BlobClient blobClient = GetBlobClient(jobPublish);
                using (DatabaseClient databaseClient = new DatabaseClient(true))
                {
                    string collectionId = Constants.Database.DocumentCollection.Metadata;
                    foreach (ITask jobTask in jobTasks)
                    {
                        IAsset   outputAsset   = jobTask.OutputAssets[0];
                        string   fileExtension = Constants.Media.FileExtension.Json;
                        string[] fileNames     = GetFileNames(outputAsset, fileExtension);
                        if (fileNames.Length > 0 && asset != null)
                        {
                            string         sourceContainerName = outputAsset.Uri.Segments[1];
                            string         sourceFileName      = fileNames[0];
                            CloudBlockBlob sourceBlob          = blobClient.GetBlob(sourceContainerName, string.Empty, sourceFileName, false);
                            string         jsonData            = string.Empty;
                            using (Stream sourceStream = sourceBlob.OpenRead())
                            {
                                StreamReader streamReader = new StreamReader(sourceStream);
                                jsonData = streamReader.ReadToEnd();
                            }
                            if (!string.IsNullOrEmpty(jsonData))
                            {
                                string         documentId     = databaseClient.CreateDocument(collectionId, jsonData);
                                MediaProcessor mediaProcessor = Processors.GetMediaProcessorType(jobTask.MediaProcessorId);
                                string         processorName  = Processors.GetMediaProcessorName(mediaProcessor);
                                processorName = processorName.Replace(' ', Constants.NamedItemSeparator);
                                string destinationFileName = string.Concat(documentId, Constants.NamedItemsSeparator, processorName, fileExtension);
                                blobClient.CopyFile(outputAsset, asset, sourceFileName, destinationFileName, false);
                            }
                        }
                        if (jobTask.Configuration.Contains("mode") && jobTask.Configuration.Contains("analyze"))
                        {
                            IAsset inputAsset      = jobTask.InputAssets[0];
                            string primaryFileName = GetPrimaryFile(inputAsset);
                            blobClient.CopyFile(inputAsset, outputAsset, primaryFileName, primaryFileName, true);
                        }
                    }
                }
            }
        }
Exemple #4
0
        private static void PublishContent(MediaClient mediaClient, IJob job, JobPublish jobPublish, ContentProtection contentProtection)
        {
            string processorId1 = Constants.Media.ProcessorId.EncoderStandard;
            string processorId2 = Constants.Media.ProcessorId.EncoderPremium;
            string processorId3 = Constants.Media.ProcessorId.EncoderUltra;

            string[] processorIds = new string[] { processorId1, processorId2, processorId3 };
            ITask[]  jobTasks     = GetJobTasks(job, processorIds);
            foreach (ITask jobTask in jobTasks)
            {
                foreach (IAsset outputAsset in jobTask.OutputAssets)
                {
                    PublishStream(mediaClient, outputAsset, contentProtection);
                    PublishIndex(job, outputAsset, jobPublish);
                    PublishAnalytics(job, outputAsset, jobPublish);
                }
            }
        }
Exemple #5
0
        internal static void TrackJob(string authToken, IJob job, string storageAccount, ContentProtection[] contentProtections)
        {
            string attributeName = Constants.UserAttribute.MediaAccountName;
            string accountName   = AuthToken.GetClaimValue(authToken, attributeName);

            attributeName = Constants.UserAttribute.MediaAccountKey;
            string accountKey = AuthToken.GetClaimValue(authToken, attributeName);

            attributeName = Constants.UserAttribute.UserId;
            string userId = AuthToken.GetClaimValue(authToken, attributeName);

            attributeName = Constants.UserAttribute.MobileNumber;
            string mobileNumber = AuthToken.GetClaimValue(authToken, attributeName);

            JobPublish jobPublish = new JobPublish();

            jobPublish.PartitionKey = accountName;
            jobPublish.RowKey       = job.Id;

            jobPublish.MediaAccountKey    = accountKey;
            jobPublish.StorageAccountName = storageAccount;
            jobPublish.StorageAccountKey  = Storage.GetUserAccountKey(authToken, storageAccount);
            jobPublish.UserId             = userId;
            jobPublish.MobileNumber       = mobileNumber;

            EntityClient entityClient = new EntityClient();

            string tableName = Constants.Storage.TableName.JobPublish;

            entityClient.InsertEntity(tableName, jobPublish);

            tableName = Constants.Storage.TableName.JobPublishProtection;
            foreach (ContentProtection contentProtection in contentProtections)
            {
                contentProtection.PartitionKey = jobPublish.PartitionKey;
                contentProtection.RowKey       = jobPublish.RowKey;
                entityClient.InsertEntity(tableName, contentProtection);
            }
        }
Exemple #6
0
 private static BlobClient GetBlobClient(JobPublish jobPublish)
 {
     string[] accountCredentials = new string[] { jobPublish.StorageAccountName, jobPublish.StorageAccountKey };
     return(new BlobClient(accountCredentials));
 }