Exemplo n.º 1
0
        /// <summary>
        /// Step execution
        /// </summary>
        /// <param name="request"></param>
        public override void HandleExecute(ChainRequest request)
        {
            //My request
            myRequest = (ButlerProcessRequest)request;
            //Media Context
            _MediaServicesContext = new CloudMediaContext(myRequest.MediaAccountName, myRequest.MediaAccountKey);
            //0 Encoding Helper
            myEncodigSupport = new EncoderSupport(_MediaServicesContext);
            //1. Storage Manager
            myStorageManager = BlobManagerFactory.CreateBlobManager(myRequest.ProcessConfigConn);
            //2. Load Original Asset (current on context)
            myAssetOriginal = (from m in _MediaServicesContext.Assets select m).Where(m => m.Id == myRequest.AssetId).FirstOrDefault();

            if (IdenpotenceControl())
            {
                ConvertMP4toSmooth(myAssetOriginal);
            }
            else
            {
                //Job Just wait for finish the current job
                myEncodigSupport.OnJobError += MyEncodigSupport_OnJobError;
                myEncodigSupport.JobUpdate  += MyEncodigSupport_JobUpdate;
                myEncodigSupport.WaitJobFinish(currentJob.Id);
            }
            //Update AssetID
            myRequest.AssetId = currentJob.OutputMediaAssets.FirstOrDefault().Id;
        }
        private void  ConvertMP4toSmooth(IAsset assetToConvert)
        {
            string xmlEncodeProfile = "H264 Adaptive Bitrate MP4 Set 1080p.xml";

            //if (this.StepConfiguration != null)
            if (!string.IsNullOrEmpty(this.StepConfiguration))
            {
                //TODO:support storage and LABEL
                xmlEncodeProfile = this.StepConfiguration;
            }
            else
            {
                string txt = string.Format("StandarEncodeStep try to read StepConfiguration but it is not in configuration table! at {0} ", DateTime.Now.ToString());
                Trace.TraceWarning(txt);
            }
            // Declare a new job to contain the tasks
            //currentJob = _MediaServicesContext.Jobs.Create("Convert to Smooth Streaming job " +  myAssetOriginal.Name);
            currentJob = _MediaServicesContext.Jobs.Create("Convert to Smooth Streaming job " + myAssetOriginal.Name);
            // Set up the first Task to convert from MP4 to Smooth Streaming.
            // Read in task configuration XML
            string configMp4ToSmooth = LoadEncodeProfile(xmlEncodeProfile);

            // Get a media packager reference
            //IMediaProcessor processor = GetLatestMediaProcessorByName("Windows Azure Media Encoder");
            IMediaProcessor processor = myEncodigSupport.GetLatestMediaProcessorByName("Windows Azure Media Encoder");

            // Create a task with the conversion details, using the configuration data
            ITask task = currentJob.Tasks.AddNew("Task profile " + xmlEncodeProfile,
                                                 processor,
                                                 configMp4ToSmooth,
                                                 TaskOptions.None);

            // Specify the input asset to be converted.
            task.InputAssets.Add(assetToConvert);
            // Add an output asset to contain the results of the job.
            task.OutputAssets.AddNew(assetToConvert.Name + "_mb", AssetCreationOptions.None);
            // Use the following event handler to check job progress.
            // The StateChange method is the same as the one in the previous sample
            //currentJob.StateChanged += new EventHandler<JobStateChangedEventArgs>(StateChanged);
            currentJob.StateChanged += new EventHandler <JobStateChangedEventArgs>(myEncodigSupport.StateChanged);
            // Launch the job.
            currentJob.Submit();
            //9. Revisa el estado de ejecución del JOB
            Task progressJobTask = currentJob.GetExecutionProgressTask(CancellationToken.None);

            //10. en vez de utilizar  progressJobTask.Wait(); que solo muestra cuando el JOB termina
            //se utiliza el siguiente codigo para mostrar avance en porcentaje, como en el portal
            myEncodigSupport.WaitJobFinish(currentJob.Id);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Execute tarnscoding process base on profile on configuration
        /// </summary>
        /// <param name="assetToConvert">AMS Asset</param>
        private void ConvertMP4toSmooth(IAsset assetToConvert)
        {
            // Declare a new job to contain the tasks
            string jobName = string.Format("Convert to Smooth Streaming job {0} [{1}]", myAssetOriginal.Name, myRequest.ProcessInstanceId);

            currentJob = _MediaServicesContext.Jobs.Create(jobName);
            // Set up the first Task to convert from MP4 to Smooth Streaming.
            // Read in task configuration XML
            var    encodeData             = getEncodeInformation();
            string EncodingProfileXmlData = encodeData[0];
            string encodingProfileLabel   = encodeData[1];

            // Get a media packager reference

            IMediaProcessor processor = myEncodigSupport.GetLatestMediaProcessorByName("Media Encoder Standard");

            // Create a task with the conversion details, using the configuration data
            ITask task = currentJob.Tasks.AddNew("Task profile " + encodingProfileLabel,
                                                 processor,
                                                 EncodingProfileXmlData,
                                                 TaskOptions.None);

            // Specify the input asset to be converted.
            task.InputAssets.Add(assetToConvert);
            // Add an output asset to contain the results of the job.
            task.OutputAssets.AddNew(assetToConvert.Name + "_mb", AssetCreationOptions.None);
            // Use the following event handler to check job progress.
            // The StateChange method is the same as the one in the previous sample
            //currentJob.StateChanged += new EventHandler<JobStateChangedEventArgs>(StateChanged);
            currentJob.StateChanged += new EventHandler <JobStateChangedEventArgs>(myEncodigSupport.StateChanged);

            //Set advantce on 0%
            string message = "job " + currentJob.Id + " Percent complete: 0%";

            MyEncodigSupport_JobUpdate(message, null);

            // Launch the job.
            currentJob.Submit();

            //8. Idenpotence MARK
            myRequest.MetaData.Add(this.GetType() + "_" + myRequest.ProcessInstanceId, currentJob.Id);
            myStorageManager.PersistProcessStatus(myRequest);

            //9. Check Project Status
            myEncodigSupport.OnJobError += MyEncodigSupport_OnJobError;
            myEncodigSupport.JobUpdate  += MyEncodigSupport_JobUpdate;
            myEncodigSupport.WaitJobFinish(currentJob.Id);
        }
        public override void HandleExecute(Common.workflow.ChainRequest request)
        {
            myRequest = (ButlerProcessRequest)request;

            _MediaServicesContext = new CloudMediaContext(myRequest.MediaAccountName, myRequest.MediaAccountKey);
            //0 Helper
            myEncodigSupport = new EncoderSupport(_MediaServicesContext);

            myAssetOriginal = (from m in _MediaServicesContext.Assets select m).Where(m => m.Id == myRequest.AssetId).FirstOrDefault();

            if (IdenpotenceControl())
            {
                ConvertMP4toSmooth(myAssetOriginal);
            }
            else
            {
                //Job Just wait for finish the current job
                myEncodigSupport.WaitJobFinish(currentJob.Id);
            }

            //Update AssetID
            myRequest.AssetId = currentJob.OutputMediaAssets.FirstOrDefault().Id;
            myRequest.MetaData.Add(this.GetType() + "_" + myRequest.ProcessInstanceId, currentJob.Id);
        }