Skip to content

Commit

Permalink
feat(VideoStitcher): add samples and test for VOD config; update VOD …
Browse files Browse the repository at this point in the history
…session creation (#2042)
  • Loading branch information
irataxy authored Aug 26, 2024
1 parent bcd993b commit 09b6fdf
Show file tree
Hide file tree
Showing 7 changed files with 496 additions and 38 deletions.
80 changes: 80 additions & 0 deletions media/videostitcher/src/create_vod_config.php
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);
13 changes: 4 additions & 9 deletions media/videostitcher/src/create_vod_session.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,20 @@
*
* @param string $callingProjectId The project ID to run the API call under
* @param string $location The location of the session
* @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
* @param string $vodConfigId The name of the VOD config to use for the session
*/
function create_vod_session(
string $callingProjectId,
string $location,
string $sourceUri,
string $adTagUri
string $vodConfigId
): void {
// Instantiate a client.
$stitcherClient = new VideoStitcherServiceClient();

$parent = $stitcherClient->locationName($callingProjectId, $location);
$vodConfig = $stitcherClient->vodConfigName($callingProjectId, $location, $vodConfigId);
$vodSession = new VodSession();
$vodSession->setSourceUri($sourceUri);
$vodSession->setAdTagUri($adTagUri);
$vodSession->setVodConfig($vodConfig);
$vodSession->setAdTracking(AdTracking::SERVER);

// Run VOD session creation request
Expand Down
63 changes: 63 additions & 0 deletions media/videostitcher/src/delete_vod_config.php
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);
58 changes: 58 additions & 0 deletions media/videostitcher/src/get_vod_config.php
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);
60 changes: 60 additions & 0 deletions media/videostitcher/src/list_vod_configs.php
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);
80 changes: 80 additions & 0 deletions media/videostitcher/src/update_vod_config.php
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);
Loading

0 comments on commit 09b6fdf

Please sign in to comment.