/**
  * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::createAsset
  * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::createJob
  * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::getJobList
  * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::getJobInputMediaAssets
  * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::getJobOutputMediaAssets
  */
 public function testListAllJobsAndAssets()
 {
     $asset1 = $this->createAssetWithFile();
     $outputAssetName1 = $this->getOutputAssetName();
     $asset2 = $this->createAssetWithFile();
     $outputAssetName2 = $this->getOutputAssetName();
     $taskBody1 = '<?xml version="1.0" encoding="utf-8"?><taskBody><inputAsset>JobInputAsset(0)</inputAsset><outputAsset assetCreationOptions="0" assetName="' . $outputAssetName1 . '">JobOutputAsset(0)</outputAsset></taskBody>';
     $mediaProcessorId = 'nb:mpid:UUID:2e7aa8f3-4961-4e0c-b4db-0e0439e524f5';
     $task1 = new Task($taskBody1, $mediaProcessorId, TaskOptions::NONE);
     $task1->setConfiguration('H.264 HD 720p VBR');
     $taskBody2 = '<?xml version="1.0" encoding="utf-8"?><taskBody><inputAsset>JobInputAsset(0)</inputAsset><outputAsset assetCreationOptions="0" assetName="' . $outputAssetName2 . '">JobOutputAsset(0)</outputAsset></taskBody>';
     $task2 = new Task($taskBody2, $mediaProcessorId, TaskOptions::NONE);
     $task2->setConfiguration('H.264 HD 720p VBR');
     $job1 = new Job();
     $job1->setName(TestResources::MEDIA_SERVICES_JOB_NAME . $this->createSuffix());
     $jobResult1 = $this->createJob($job1, array($asset1), array($task1));
     $job2 = new Job();
     $job2->setName(TestResources::MEDIA_SERVICES_JOB_NAME . $this->createSuffix());
     $jobResult2 = $this->createJob($job2, array($asset2), array($task2));
     // Test
     $jobList = $this->restProxy->getJobList();
     $resultInput1 = $this->restProxy->getJobInputMediaAssets($jobList[0]);
     $resultOutput1 = $this->restProxy->getJobOutputMediaAssets($jobList[0]);
     $resultInput2 = $this->restProxy->getJobInputMediaAssets($jobList[1]);
     $resultOutput2 = $this->restProxy->getJobOutputMediaAssets($jobList[1]);
     // Assert
     $this->assertEquals(2, count($resultInput1) + count($resultInput2));
     $this->assertEquals(2, count($resultOutput1) + count($resultOutput2));
     $this->assertEquals(2, count($jobList));
     $this->assertEquals($asset1->getId(), $resultInput2[0]->getId());
     $this->assertEquals($asset1->getName(), $resultInput2[0]->getName());
     $this->assertNotEquals($asset1->getId(), $resultOutput2[0]->getId());
     $this->assertEquals($outputAssetName1, $resultOutput2[0]->getName());
     $this->assertEquals($asset2->getId(), $resultInput1[0]->getId());
     $this->assertEquals($asset2->getName(), $resultInput1[0]->getName());
     $this->assertNotEquals($asset2->getId(), $resultOutput1[0]->getId());
     $this->assertEquals($outputAssetName2, $resultOutput1[0]->getName());
 }
 /**
  * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::getAssetParentAssets
  */
 public function testGetAssetParentAsset()
 {
     // Setup
     $name = $this->getOutputAssetName();
     $mediaProcessor = $this->restProxy->getLatestMediaProcessor('Windows Azure Media Encoder');
     $inputAsset = $this->createAssetWithFile();
     $taskBody = '<?xml version="1.0" encoding="utf-8"?><taskBody><inputAsset>JobInputAsset(0)</inputAsset><outputAsset assetCreationOptions="0" assetName="' . $name . '">JobOutputAsset(0)</outputAsset></taskBody>';
     $task = new Task($taskBody, $mediaProcessor->getId(), TaskOptions::NONE);
     $task->setConfiguration('H.264 HD 720p VBR');
     $job = new Job();
     $job->setName($name);
     $job = $this->createJob($job, array($inputAsset), array($task));
     $assetList = $this->restProxy->getAssetList();
     // Test
     foreach ($assetList as $assetElement) {
         if (strcmp($assetElement->getName(), $name) == 0) {
             $parentAssetId = $this->restProxy->getAssetParentAssets($assetElement);
         }
     }
     // Assert
     $this->assertEquals(1, count($parentAssetId));
     $this->assertEquals($inputAsset->getId(), $parentAssetId[0]->getId());
 }
 /**
  * Add convert job to Microsoft Azure Media Services
  * @param int $sourceAssetId Asset Id of source file
  * @param array $preset Preset for encoding
  * @return int|false Job Id or error
  */
 public function addConvertJob($sourceAssetId, $preset)
 {
     if (!is_array($preset)) {
         return false;
     }
     $mediaProcessor = $this->_mediaServiceProxy->getLatestMediaProcessor(self::MEDIA_PROCESSOR_NAME);
     $sourceAsset = $this->getAssetById($sourceAssetId);
     if (!$sourceAsset) {
         return false;
     }
     $entryName = $this->getEntryName($sourceAssetId);
     if ($entryName) {
         $assetName = $entryName . ' - ' . $preset[self::CONVERT_PARAM_PRESET_NAME];
     } else {
         $assetName = $sourceAsset->getName() . ' - ' . $preset[self::CONVERT_PARAM_PRESET_NAME];
     }
     $confParams = array();
     $confParams[self::CONF_PARAM_AUDIO_BITRATE] = $preset[self::CONVERT_PARAM_AUDIO_BITRATE];
     $confParams[self::CONF_PARAM_AUDIO_CHANNELS] = $preset[self::CONVERT_PARAM_AUDIO_CHANNELS];
     $confParams[self::CONF_PARAM_AUDIO_CODEC] = $this->audioCodecs[$preset[self::CONVERT_PARAM_AUDIO_CODEC]];
     $confParams[self::CONF_PARAM_AUDIO_SAMPLE_RATE] = $preset[self::CONVERT_PARAM_AUDIO_SAMPLE_RATE];
     $confParams[self::CONF_PARAM_VIDEO_PROFILE_NAME] = $this->videoProfiles[$preset[self::CONVERT_PARAM_VIDEO_CODEC]];
     $confParams[self::CONF_PARAM_VIDEO_WIDTH] = $preset[self::CONVERT_PARAM_VIDEO_WIDTH];
     $confParams[self::CONF_PARAM_VIDEO_HEIGHT] = $preset[self::CONVERT_PARAM_VIDEO_HEIGHT];
     $confParams[self::CONF_PARAM_VIDEO_BITRATE] = $preset[self::CONVERT_PARAM_VIDEO_BITRATE];
     $configuration = $this->renderConfiguration($this->confPath . self::TEMPLATE_FILE_CONVERT, $confParams);
     $taskParams = array();
     $taskParams[self::CONF_PARAM_ASSET_NAME] = $assetName;
     $taskBody = $this->renderConfiguration($this->confPath . self::TEMPLATE_FILE_TASK_BODY, $taskParams);
     $task = new Task($taskBody, $mediaProcessor->getId(), 0);
     $task->setConfiguration($configuration);
     $job = new Job();
     $job->setName('Converting ' . $sourceAsset->getName() . ' to ' . $preset[self::CONVERT_PARAM_PRESET_NAME]);
     return $this->_mediaServiceProxy->createJob($job, array($sourceAsset), array($task))->getId();
 }
 public function createJobWithTasks($name)
 {
     $mediaProcessor = $this->restProxy->getLatestMediaProcessor(TestResources::MEDIA_SERVICES_PROCESSOR_NAME);
     $inputAsset = $this->createAssetWithFile();
     $taskBody = TestResources::getMediaServicesTask($this->getOutputAssetName());
     $task = new Task($taskBody, $mediaProcessor->getId(), TaskOptions::NONE);
     $task->setConfiguration(TestResources::MEDIA_SERVICES_TASK_COFIGURATION);
     $job = new Job();
     $job->setName($name);
     $jobResult = $this->createJob($job, array($inputAsset), array($task));
     $this->job[$jobResult->getId()] = $jobResult;
     return $jobResult;
 }
function encodeToAdaptiveBitrateMP4Set($restProxy, $asset)
{
    // 2.1 retrieve the latest 'Media Encoder Standard' processor version
    $mediaProcessor = $restProxy->getLatestMediaProcessor('Media Encoder Standard');
    echo "Using Media Processor: {$mediaProcessor->getName()} version {$mediaProcessor->getVersion()}" . PHP_EOL;
    // 2.2 Create the Job; this automatically schedules and runs it
    $outputAssetName = "Encoded " . $asset->getName();
    $outputAssetCreationOption = Asset::OPTIONS_NONE;
    $taskBody = '<?xml version="1.0" encoding="utf-8"?><taskBody><inputAsset>JobInputAsset(0)</inputAsset><outputAsset assetCreationOptions="' . $outputAssetCreationOption . '" assetName="' . $outputAssetName . '">JobOutputAsset(0)</outputAsset></taskBody>';
    $task = new Task($taskBody, $mediaProcessor->getId(), TaskOptions::NONE);
    $task->setConfiguration('H264 Multiple Bitrate 720p');
    $job = new Job();
    $job->setName('Encoding Job');
    $job = $restProxy->createJob($job, array($asset), array($task));
    echo "Created Job with Id: {$job->getId()}" . PHP_EOL;
    // 2.3 Check to see if the Job has completed
    $result = $restProxy->getJobStatus($job);
    $jobStatusMap = array('Queued', 'Scheduled', 'Processing', 'Finished', 'Error', 'Canceled', 'Canceling');
    while ($result != Job::STATE_FINISHED && $result != Job::STATE_ERROR && $result != Job::STATE_CANCELED) {
        echo "Job status: {$jobStatusMap[$result]}" . PHP_EOL;
        sleep(5);
        $result = $restProxy->getJobStatus($job);
    }
    if ($result != Job::STATE_FINISHED) {
        echo "The job has finished with a wrong status: {$jobStatusMap[$result]}" . PHP_EOL;
        exit(-1);
    }
    echo "Job Finished!" . PHP_EOL;
    // 2.4 Get output asset
    $outputAssets = $restProxy->getJobOutputMediaAssets($job);
    $encodedAsset = $outputAssets[0];
    echo "Asset encoded: name={$encodedAsset->getName()} id={$encodedAsset->getId()}" . PHP_EOL;
    return $encodedAsset;
}
$restProxy->uploadAssetFile($sasLocator, $mezzanineFileName, $fileContent);
// 1.7. notify Media Services that the file upload operation is done to generate the asset file metadata
$restProxy->createFileInfos($asset);
print "File uploaded: size=" . strlen($fileContent) . "\r\n";
// 1.8. delete the SAS Locator (and Access Policy) for the Asset since we are done uploading files
$restProxy->deleteLocator($sasLocator);
$restProxy->deleteAccessPolicy($accessPolicy);
// Phase 2 - encode the output asset
// 2.1 retrieve the last Media Encoder Standard
$mediaProcessor = $restProxy->getLatestMediaProcessor('Media Encoder Standard');
print "Using Media Processor: {$mediaProcessor->getName()} version {$mediaProcessor->getVersion()}\r\n";
// 2.2 Create the Job; this automatically schedules and runs it.
$outputAssetName = "Encoded " . $mezzanineFileName;
$taskBody = '<?xml version="1.0" encoding="utf-8"?><taskBody><inputAsset>JobInputAsset(0)</inputAsset><outputAsset assetCreationOptions="0" assetName="' . $outputAssetName . '">JobOutputAsset(0)</outputAsset></taskBody>';
$task = new Task($taskBody, $mediaProcessor->getId(), TaskOptions::NONE);
$task->setConfiguration('H264 Multiple Bitrate 720p');
$job = new Job();
$job->setName('Encoding Job');
$job = $restProxy->createJob($job, array($asset), array($task));
print "Created Job with Id: {$job->getId()}\r\n";
// 2.3 Check to see if the Job has completed
$result = $restProxy->getJobStatus($job);
while ($result != 3 && $result != 4 && $result != 5) {
    print "Job status: {$result}\r\n";
    sleep(5);
    $result = $restProxy->getJobStatus($job);
}
if ($result != 3) {
    print "The job has finished with a wrong status: {$result}\r\n";
    return;
}