コード例 #1
0
        public void PublishFromBlob(string ExternalStorageConn, string ExternalStorageContainer, string ExternalBlobName, string AssetStorageConn, string AssestBlobName, string myEncodeProcessId)
        {
            //1. Create Asset //
            CloudStorageAccount externalStorageAccount     = CloudStorageAccount.Parse(ExternalStorageConn);
            CloudBlobClient     externalCloudBlobClient    = externalStorageAccount.CreateCloudBlobClient();
            CloudBlobContainer  externalMediaBlobContainer = externalCloudBlobClient.GetContainerReference(ExternalStorageContainer);
            CloudStorageAccount assetStorageAccount        = CloudStorageAccount.Parse(AssetStorageConn);
            CloudBlobClient     AssetBlobStoragclient      = assetStorageAccount.CreateCloudBlobClient();

            System.Collections.Generic.List <JobFinishInfo> NotificationList = new System.Collections.Generic.List <JobFinishInfo>();
            IAsset OriginalAsset;

            try
            {
                OriginalAsset = this.CreateAssetFromBlob(externalMediaBlobContainer, ExternalBlobName, AssetBlobStoragclient, AssestBlobName, myEncodeProcessId);
                if (OriginalAsset == null)
                {
                    throw new Exception("Add Asset from blob Fail!");
                }
            }
            catch (Exception X)
            {
                throw new Exception("[CreateAssetFromBlob] " + X.Message);
            }

            //2. Setup the enviroment//
            string assetName = OriginalAsset.Name;
            IAsset CurrentAsset;
            //0.setup
            EncodeJob myWorkerEncoder = new EncodeJob(ProfileFileDirectory);

            myWorkerEncoder.MediaServiceContext = ObtainContext(_accountMediaName, _accountMediaKey);
            myWorkerEncoder.ConnConfigFiles     = this.myWamsButlerConn;
            //TODO: improve
            myWorkerEncoder.OnJobError  += OnJobError;
            myWorkerEncoder.OnJobFinish += OnJobFinish;
            IAsset   lastEncodedAsset = null;
            IJob     currentJob;
            ILocator currentLocator;

            //1. check Types
            System.Collections.Generic.IEnumerable <OutPutFormat> formatList = GetMediaContentType(myWamsButlerConn, "wamsbutleroutputformat", myAppId);
            if (formatList.Count() == 0)
            {
                throw new Exception("Output Format missing, review Table wamsbutleroutputformat");
            }
            //3. Loop for each Output Format//
            foreach (OutPutFormat encodeX in formatList)
            {
                currentJob     = null;
                currentLocator = null;
                if ((MediaContentType)encodeX.OutTypesId == MediaContentType.HLS)
                {
                    //This is package JOB, not real encoding for this reason uses the last Encode asset
                    //Only use when you are making Static HLS Package
                    CurrentAsset = lastEncodedAsset;
                }
                else
                {
                    CurrentAsset = OriginalAsset;
                }
                //3.1. Encode & output Assets
                try
                {
                    //Here we does the encoding and return the iJOB executed
                    currentJob = myWorkerEncoder.ExecuteJob(encodeX, CurrentAsset, assetName + encodeX.NameTail);
                }
                catch (Exception X)
                {
                    throw new Exception("[ExecuteJob] " + X.Message);
                }

                if (currentJob != null)
                {
                    lastEncodedAsset = currentJob.Tasks[0].OutputAssets[0];
                }

                if (lastEncodedAsset == null)
                {
                    throw new Exception("PublishFromBlob Error: first encode could not be only publish");
                }


                ////3.2. Publish the Asset //
                try
                {
                    currentLocator = this.MasterPublish(encodeX, lastEncodedAsset, myWorkerEncoder);
                }
                catch (Exception X)
                {
                    throw new Exception("[MasterPublish] " + X.Message);
                }

                //Notificaction JOB Complete
                JobFinishInfo jobCompleteMessage = new JobFinishInfo(myEncodeProcessId, ExternalBlobName, currentJob, (MediaContentType)encodeX.OutTypesId, myWorkerEncoder.UrlForClientStreaming);
                NotificationList.Add(jobCompleteMessage);
            }
            //4.Delete Original Asset
            DeleteAssest(OriginalAsset);

            //5. Notification: all encodig jobs are ready for this asset
            //notication File Complete
            INotificator notRobot = new QueueNotificator(myWamsButlerConn);

            try
            {
                notRobot.sendNotification(NotificationList);
            }
            catch (Exception X)
            {
                throw new Exception("[sendNotification] " + X.Message);
            }
        }
コード例 #2
0
        public void PublishFromBlob(string ExternalStorageConn, string ExternalStorageContainer, string ExternalBlobName, string AssetStorageConn, string AssestBlobName, string myEncodeProcessId)
        {
            //1. Create Asset //
            CloudStorageAccount externalStorageAccount = CloudStorageAccount.Parse(ExternalStorageConn);
            CloudBlobClient externalCloudBlobClient = externalStorageAccount.CreateCloudBlobClient();
            CloudBlobContainer externalMediaBlobContainer = externalCloudBlobClient.GetContainerReference(ExternalStorageContainer);
            CloudStorageAccount assetStorageAccount = CloudStorageAccount.Parse(AssetStorageConn);
            CloudBlobClient AssetBlobStoragclient = assetStorageAccount.CreateCloudBlobClient();
            System.Collections.Generic.List<JobFinishInfo> NotificationList = new System.Collections.Generic.List<JobFinishInfo>();
            IAsset OriginalAsset;
            try
            {
                OriginalAsset = this.CreateAssetFromBlob(externalMediaBlobContainer, ExternalBlobName, AssetBlobStoragclient, AssestBlobName, myEncodeProcessId);
                if (OriginalAsset == null)
                {
                    throw new Exception("Add Asset from blob Fail!");
                }
            }
            catch (Exception X)
            {
                throw new Exception("[CreateAssetFromBlob] " + X.Message);
            }

            //2. Setup the enviroment//
            string assetName = OriginalAsset.Name;
            IAsset CurrentAsset;
            //0.setup
            EncodeJob myWorkerEncoder = new EncodeJob(ProfileFileDirectory);
            myWorkerEncoder.MediaServiceContext = ObtainContext(_accountMediaName, _accountMediaKey);
            myWorkerEncoder.ConnConfigFiles = this.myWamsButlerConn;
            //TODO: improve
            myWorkerEncoder.OnJobError += OnJobError;
            myWorkerEncoder.OnJobFinish += OnJobFinish;
            IAsset lastEncodedAsset = null;
            IJob currentJob;
            ILocator currentLocator;
            //1. check Types
            System.Collections.Generic.IEnumerable<OutPutFormat> formatList= GetMediaContentType(myWamsButlerConn, "wamsbutleroutputformat", myAppId);
            if (formatList.Count() == 0)
            {
                throw new Exception("Output Format missing, review Table wamsbutleroutputformat");
            }
            //3. Loop for each Output Format//
            foreach (OutPutFormat encodeX in formatList)
            {
                currentJob = null;
                currentLocator = null;
                if ((MediaContentType)encodeX.OutTypesId == MediaContentType.HLS)
                {
                    //This is package JOB, not real encoding for this reason uses the last Encode asset
                    //Only use when you are making Static HLS Package
                    CurrentAsset = lastEncodedAsset;
                }
                else
                {
                    CurrentAsset = OriginalAsset;
                }
                //3.1. Encode & output Assets
                try
                {
                    //Here we does the encoding and return the iJOB executed
                    currentJob = myWorkerEncoder.ExecuteJob(encodeX, CurrentAsset, assetName + encodeX.NameTail);
                }
                catch (Exception X)
                {
                    
                    throw new Exception("[ExecuteJob] "+ X.Message);
                }
                
                if (currentJob != null)
                {
                    lastEncodedAsset = currentJob.Tasks[0].OutputAssets[0];
                }

                if (lastEncodedAsset == null)
                {
                    throw new Exception("PublishFromBlob Error: first encode could not be only publish");
                }
                

                ////3.2. Publish the Asset //
                try
                {
                    currentLocator = this.MasterPublish(encodeX, lastEncodedAsset, myWorkerEncoder);
                }
                catch (Exception X)
                {
                    
                    throw new Exception("[MasterPublish] "+ X.Message);
                }
                
                //Notificaction JOB Complete
                JobFinishInfo jobCompleteMessage = new JobFinishInfo(myEncodeProcessId, ExternalBlobName, currentJob, (MediaContentType)encodeX.OutTypesId, myWorkerEncoder.UrlForClientStreaming);
                NotificationList.Add(jobCompleteMessage);
            }
            //4.Delete Original Asset
            DeleteAssest(OriginalAsset);

            //5. Notification: all encodig jobs are ready for this asset
            //notication File Complete
            INotificator notRobot = new QueueNotificator(myWamsButlerConn);
            try
            {
                notRobot.sendNotification(NotificationList);
            }
            catch (Exception X)
            {

                throw new Exception("[sendNotification] " + X.Message) ;
            }
        }
コード例 #3
0
        private ILocator MasterPublish(OutPutFormat currentOutPutFormat, IAsset currentAsset, EncodeJob currentWorkerEncoder)
        {
            ILocator currentLocator = null;

            //b. Publish
            switch ((MediaContentType)currentOutPutFormat.OutTypesId)
            {
            case MediaContentType.SmoothStreaming:
                //b. Publish H264
                currentLocator = currentWorkerEncoder.GetDynamicStreamingUrl(currentAsset.Id, LocatorType.OnDemandOrigin, MediaContentType.SmoothStreaming);
                break;

            case MediaContentType.HLS:
                currentLocator = currentWorkerEncoder.GetDynamicStreamingUrl(currentAsset.Id, LocatorType.OnDemandOrigin, MediaContentType.HLS);
                break;

            case MediaContentType.H264Broadband720p:
                //b. Publish H264
                currentLocator = currentWorkerEncoder.GetDynamicStreamingUrl(currentAsset.Id, LocatorType.Sas, MediaContentType.H264Broadband720p);
                break;

            case MediaContentType.HDS:
                currentLocator = currentWorkerEncoder.GetDynamicStreamingUrl(currentAsset.Id, LocatorType.OnDemandOrigin, MediaContentType.HDS);
                break;

            default:
                //b. otherssss
                currentLocator = currentWorkerEncoder.GetDynamicStreamingUrl(currentAsset.Id, LocatorType.Sas, MediaContentType.OtherSingleFile);
                break;
            }
            return(currentLocator);
        }
コード例 #4
0
 private ILocator MasterPublish( OutPutFormat currentOutPutFormat , IAsset currentAsset, EncodeJob currentWorkerEncoder)
 {
     ILocator currentLocator = null;
     //b. Publish
     switch ((MediaContentType)currentOutPutFormat.OutTypesId)
     {
         case MediaContentType.SmoothStreaming:
             //b. Publish H264
             currentLocator = currentWorkerEncoder.GetDynamicStreamingUrl(currentAsset.Id, LocatorType.OnDemandOrigin, MediaContentType.SmoothStreaming);
             break;
         case MediaContentType.HLS:
             currentLocator = currentWorkerEncoder.GetDynamicStreamingUrl(currentAsset.Id, LocatorType.OnDemandOrigin, MediaContentType.HLS);
             break;
         case MediaContentType.H264Broadband720p:
             //b. Publish H264
             currentLocator = currentWorkerEncoder.GetDynamicStreamingUrl(currentAsset.Id, LocatorType.Sas, MediaContentType.H264Broadband720p);
             break;
         case MediaContentType.HDS:
             currentLocator = currentWorkerEncoder.GetDynamicStreamingUrl(currentAsset.Id, LocatorType.OnDemandOrigin, MediaContentType.HDS);
             break;
         default:
             //b. otherssss
              currentLocator = currentWorkerEncoder.GetDynamicStreamingUrl(currentAsset.Id, LocatorType.Sas, MediaContentType.OtherSingleFile);
             break;
     }
     return currentLocator;
 }