-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(VideoStitcher): add samples and test for VOD config; update VOD …
…session creation (#2042)
- Loading branch information
Showing
7 changed files
with
496 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2024 Google LLC. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* For instructions on how to run the samples: | ||
* | ||
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/videostitcher/README.md | ||
*/ | ||
|
||
namespace Google\Cloud\Samples\Media\Stitcher; | ||
|
||
// [START videostitcher_create_vod_config] | ||
use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; | ||
use Google\Cloud\Video\Stitcher\V1\CreateVodConfigRequest; | ||
use Google\Cloud\Video\Stitcher\V1\VodConfig; | ||
|
||
/** | ||
* Creates a VOD config. VOD configs are used to configure VOD sessions. | ||
* | ||
* @param string $callingProjectId The project ID to run the API call under | ||
* @param string $location The location of the VOD config | ||
* @param string $vodConfigId The name of the VOD config to be created | ||
* @param string $sourceUri Uri of the media to stitch; this URI must | ||
* reference either an MPEG-DASH manifest | ||
* (.mpd) file or an M3U playlist manifest | ||
* (.m3u8) file. | ||
* @param string $adTagUri The Uri of the ad tag | ||
*/ | ||
function create_vod_config( | ||
string $callingProjectId, | ||
string $location, | ||
string $vodConfigId, | ||
string $sourceUri, | ||
string $adTagUri | ||
): void { | ||
// Instantiate a client. | ||
$stitcherClient = new VideoStitcherServiceClient(); | ||
|
||
$parent = $stitcherClient->locationName($callingProjectId, $location); | ||
|
||
$vodConfig = (new VodConfig()) | ||
->setSourceUri($sourceUri) | ||
->setAdTagUri($adTagUri); | ||
|
||
// Run VOD config creation request | ||
$request = (new CreateVodConfigRequest()) | ||
->setParent($parent) | ||
->setVodConfigId($vodConfigId) | ||
->setVodConfig($vodConfig); | ||
$operationResponse = $stitcherClient->createVodConfig($request); | ||
$operationResponse->pollUntilComplete(); | ||
if ($operationResponse->operationSucceeded()) { | ||
$result = $operationResponse->getResult(); | ||
// Print results | ||
printf('VOD config: %s' . PHP_EOL, $result->getName()); | ||
} else { | ||
$error = $operationResponse->getError(); | ||
// handleError($error) | ||
} | ||
} | ||
// [END videostitcher_create_vod_config] | ||
|
||
// The following 2 lines are only needed to run the samples | ||
require_once __DIR__ . '/../../../testing/sample_helpers.php'; | ||
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2024 Google LLC. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* For instructions on how to run the samples: | ||
* | ||
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/videostitcher/README.md | ||
*/ | ||
|
||
namespace Google\Cloud\Samples\Media\Stitcher; | ||
|
||
// [START videostitcher_delete_vod_config] | ||
use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; | ||
use Google\Cloud\Video\Stitcher\V1\DeleteVodConfigRequest; | ||
|
||
/** | ||
* Deletes a VOD config. | ||
* | ||
* @param string $callingProjectId The project ID to run the API call under | ||
* @param string $location The location of the VOD config | ||
* @param string $vodConfigId The ID of the VOD config | ||
*/ | ||
function delete_vod_config( | ||
string $callingProjectId, | ||
string $location, | ||
string $vodConfigId | ||
): void { | ||
// Instantiate a client. | ||
$stitcherClient = new VideoStitcherServiceClient(); | ||
|
||
$formattedName = $stitcherClient->vodConfigName($callingProjectId, $location, $vodConfigId); | ||
$request = (new DeleteVodConfigRequest()) | ||
->setName($formattedName); | ||
$operationResponse = $stitcherClient->deleteVodConfig($request); | ||
$operationResponse->pollUntilComplete(); | ||
if ($operationResponse->operationSucceeded()) { | ||
// Print status | ||
printf('Deleted VOD config %s' . PHP_EOL, $vodConfigId); | ||
} else { | ||
$error = $operationResponse->getError(); | ||
// handleError($error) | ||
} | ||
} | ||
// [END videostitcher_delete_vod_config] | ||
|
||
// The following 2 lines are only needed to run the samples | ||
require_once __DIR__ . '/../../../testing/sample_helpers.php'; | ||
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2024 Google LLC. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* For instructions on how to run the samples: | ||
* | ||
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/videostitcher/README.md | ||
*/ | ||
|
||
namespace Google\Cloud\Samples\Media\Stitcher; | ||
|
||
// [START videostitcher_get_vod_config] | ||
use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; | ||
use Google\Cloud\Video\Stitcher\V1\GetVodConfigRequest; | ||
|
||
/** | ||
* Gets a VOD config. | ||
* | ||
* @param string $callingProjectId The project ID to run the API call under | ||
* @param string $location The location of the VOD config | ||
* @param string $vodConfigId The ID of the VOD config | ||
*/ | ||
function get_vod_config( | ||
string $callingProjectId, | ||
string $location, | ||
string $vodConfigId | ||
): void { | ||
// Instantiate a client. | ||
$stitcherClient = new VideoStitcherServiceClient(); | ||
|
||
$formattedName = $stitcherClient->vodConfigName($callingProjectId, $location, $vodConfigId); | ||
$request = (new GetVodConfigRequest()) | ||
->setName($formattedName); | ||
$vodConfig = $stitcherClient->getVodConfig($request); | ||
|
||
// Print results | ||
printf('VOD config: %s' . PHP_EOL, $vodConfig->getName()); | ||
} | ||
// [END videostitcher_get_vod_config] | ||
|
||
// The following 2 lines are only needed to run the samples | ||
require_once __DIR__ . '/../../../testing/sample_helpers.php'; | ||
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2024 Google LLC. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* For instructions on how to run the samples: | ||
* | ||
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/videostitcher/README.md | ||
*/ | ||
|
||
namespace Google\Cloud\Samples\Media\Stitcher; | ||
|
||
// [START videostitcher_list_vod_configs] | ||
use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; | ||
use Google\Cloud\Video\Stitcher\V1\ListVodConfigsRequest; | ||
|
||
/** | ||
* Lists all VOD configs for a location. | ||
* | ||
* @param string $callingProjectId The project ID to run the API call under | ||
* @param string $location The location of the VOD configs | ||
*/ | ||
function list_vod_configs( | ||
string $callingProjectId, | ||
string $location | ||
): void { | ||
// Instantiate a client. | ||
$stitcherClient = new VideoStitcherServiceClient(); | ||
|
||
$parent = $stitcherClient->locationName($callingProjectId, $location); | ||
$request = (new ListVodConfigsRequest()) | ||
->setParent($parent); | ||
$response = $stitcherClient->listVodConfigs($request); | ||
|
||
// Print the VOD config list. | ||
$vodConfigs = $response->iterateAllElements(); | ||
print('VOD configs:' . PHP_EOL); | ||
foreach ($vodConfigs as $vodConfig) { | ||
printf('%s' . PHP_EOL, $vodConfig->getName()); | ||
} | ||
} | ||
// [END videostitcher_list_vod_configs] | ||
|
||
// The following 2 lines are only needed to run the samples | ||
require_once __DIR__ . '/../../../testing/sample_helpers.php'; | ||
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2024 Google LLC. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* For instructions on how to run the samples: | ||
* | ||
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/videostitcher/README.md | ||
*/ | ||
|
||
namespace Google\Cloud\Samples\Media\Stitcher; | ||
|
||
// [START videostitcher_update_vod_config] | ||
use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; | ||
use Google\Cloud\Video\Stitcher\V1\UpdateVodConfigRequest; | ||
use Google\Cloud\Video\Stitcher\V1\VodConfig; | ||
use Google\Protobuf\FieldMask; | ||
|
||
/** | ||
* Updates the VOD config's sourceUri field. | ||
* | ||
* @param string $callingProjectId The project ID to run the API call under | ||
* @param string $location The location of the VOD config | ||
* @param string $vodConfigId The name of the VOD config to update | ||
* @param string $sourceUri Updated uri of the media to stitch; this URI must | ||
* reference either an MPEG-DASH manifest | ||
* (.mpd) file or an M3U playlist manifest | ||
* (.m3u8) file. | ||
*/ | ||
function update_vod_config( | ||
string $callingProjectId, | ||
string $location, | ||
string $vodConfigId, | ||
string $sourceUri | ||
): void { | ||
// Instantiate a client. | ||
$stitcherClient = new VideoStitcherServiceClient(); | ||
|
||
$formattedName = $stitcherClient->vodConfigName($callingProjectId, $location, $vodConfigId); | ||
$vodConfig = new VodConfig(); | ||
$vodConfig->setName($formattedName); | ||
$vodConfig->setSourceUri($sourceUri); | ||
$updateMask = new FieldMask([ | ||
'paths' => ['sourceUri'] | ||
]); | ||
|
||
// Run VOD config update request | ||
$request = (new UpdateVodConfigRequest()) | ||
->setVodConfig($vodConfig) | ||
->setUpdateMask($updateMask); | ||
$operationResponse = $stitcherClient->updateVodConfig($request); | ||
$operationResponse->pollUntilComplete(); | ||
if ($operationResponse->operationSucceeded()) { | ||
$result = $operationResponse->getResult(); | ||
// Print results | ||
printf('Updated VOD config: %s' . PHP_EOL, $result->getName()); | ||
} else { | ||
$error = $operationResponse->getError(); | ||
// handleError($error) | ||
} | ||
} | ||
// [END videostitcher_update_vod_config] | ||
|
||
// The following 2 lines are only needed to run the samples | ||
require_once __DIR__ . '/../../../testing/sample_helpers.php'; | ||
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv); |
Oops, something went wrong.