Skip to content

Commit 09b6fdf

Browse files
authored
feat(VideoStitcher): add samples and test for VOD config; update VOD session creation (#2042)
1 parent bcd993b commit 09b6fdf

File tree

7 files changed

+496
-38
lines changed

7 files changed

+496
-38
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2024 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/videostitcher/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\Stitcher;
26+
27+
// [START videostitcher_create_vod_config]
28+
use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient;
29+
use Google\Cloud\Video\Stitcher\V1\CreateVodConfigRequest;
30+
use Google\Cloud\Video\Stitcher\V1\VodConfig;
31+
32+
/**
33+
* Creates a VOD config. VOD configs are used to configure VOD sessions.
34+
*
35+
* @param string $callingProjectId The project ID to run the API call under
36+
* @param string $location The location of the VOD config
37+
* @param string $vodConfigId The name of the VOD config to be created
38+
* @param string $sourceUri Uri of the media to stitch; this URI must
39+
* reference either an MPEG-DASH manifest
40+
* (.mpd) file or an M3U playlist manifest
41+
* (.m3u8) file.
42+
* @param string $adTagUri The Uri of the ad tag
43+
*/
44+
function create_vod_config(
45+
string $callingProjectId,
46+
string $location,
47+
string $vodConfigId,
48+
string $sourceUri,
49+
string $adTagUri
50+
): void {
51+
// Instantiate a client.
52+
$stitcherClient = new VideoStitcherServiceClient();
53+
54+
$parent = $stitcherClient->locationName($callingProjectId, $location);
55+
56+
$vodConfig = (new VodConfig())
57+
->setSourceUri($sourceUri)
58+
->setAdTagUri($adTagUri);
59+
60+
// Run VOD config creation request
61+
$request = (new CreateVodConfigRequest())
62+
->setParent($parent)
63+
->setVodConfigId($vodConfigId)
64+
->setVodConfig($vodConfig);
65+
$operationResponse = $stitcherClient->createVodConfig($request);
66+
$operationResponse->pollUntilComplete();
67+
if ($operationResponse->operationSucceeded()) {
68+
$result = $operationResponse->getResult();
69+
// Print results
70+
printf('VOD config: %s' . PHP_EOL, $result->getName());
71+
} else {
72+
$error = $operationResponse->getError();
73+
// handleError($error)
74+
}
75+
}
76+
// [END videostitcher_create_vod_config]
77+
78+
// The following 2 lines are only needed to run the samples
79+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
80+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

media/videostitcher/src/create_vod_session.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,20 @@
3636
*
3737
* @param string $callingProjectId The project ID to run the API call under
3838
* @param string $location The location of the session
39-
* @param string $sourceUri Uri of the media to stitch; this URI must
40-
* reference either an MPEG-DASH manifest
41-
* (.mpd) file or an M3U playlist manifest
42-
* (.m3u8) file.
43-
* @param string $adTagUri The Uri of the ad tag
39+
* @param string $vodConfigId The name of the VOD config to use for the session
4440
*/
4541
function create_vod_session(
4642
string $callingProjectId,
4743
string $location,
48-
string $sourceUri,
49-
string $adTagUri
44+
string $vodConfigId
5045
): void {
5146
// Instantiate a client.
5247
$stitcherClient = new VideoStitcherServiceClient();
5348

5449
$parent = $stitcherClient->locationName($callingProjectId, $location);
50+
$vodConfig = $stitcherClient->vodConfigName($callingProjectId, $location, $vodConfigId);
5551
$vodSession = new VodSession();
56-
$vodSession->setSourceUri($sourceUri);
57-
$vodSession->setAdTagUri($adTagUri);
52+
$vodSession->setVodConfig($vodConfig);
5853
$vodSession->setAdTracking(AdTracking::SERVER);
5954

6055
// Run VOD session creation request
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2024 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/videostitcher/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\Stitcher;
26+
27+
// [START videostitcher_delete_vod_config]
28+
use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient;
29+
use Google\Cloud\Video\Stitcher\V1\DeleteVodConfigRequest;
30+
31+
/**
32+
* Deletes a VOD config.
33+
*
34+
* @param string $callingProjectId The project ID to run the API call under
35+
* @param string $location The location of the VOD config
36+
* @param string $vodConfigId The ID of the VOD config
37+
*/
38+
function delete_vod_config(
39+
string $callingProjectId,
40+
string $location,
41+
string $vodConfigId
42+
): void {
43+
// Instantiate a client.
44+
$stitcherClient = new VideoStitcherServiceClient();
45+
46+
$formattedName = $stitcherClient->vodConfigName($callingProjectId, $location, $vodConfigId);
47+
$request = (new DeleteVodConfigRequest())
48+
->setName($formattedName);
49+
$operationResponse = $stitcherClient->deleteVodConfig($request);
50+
$operationResponse->pollUntilComplete();
51+
if ($operationResponse->operationSucceeded()) {
52+
// Print status
53+
printf('Deleted VOD config %s' . PHP_EOL, $vodConfigId);
54+
} else {
55+
$error = $operationResponse->getError();
56+
// handleError($error)
57+
}
58+
}
59+
// [END videostitcher_delete_vod_config]
60+
61+
// The following 2 lines are only needed to run the samples
62+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
63+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2024 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/videostitcher/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\Stitcher;
26+
27+
// [START videostitcher_get_vod_config]
28+
use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient;
29+
use Google\Cloud\Video\Stitcher\V1\GetVodConfigRequest;
30+
31+
/**
32+
* Gets a VOD config.
33+
*
34+
* @param string $callingProjectId The project ID to run the API call under
35+
* @param string $location The location of the VOD config
36+
* @param string $vodConfigId The ID of the VOD config
37+
*/
38+
function get_vod_config(
39+
string $callingProjectId,
40+
string $location,
41+
string $vodConfigId
42+
): void {
43+
// Instantiate a client.
44+
$stitcherClient = new VideoStitcherServiceClient();
45+
46+
$formattedName = $stitcherClient->vodConfigName($callingProjectId, $location, $vodConfigId);
47+
$request = (new GetVodConfigRequest())
48+
->setName($formattedName);
49+
$vodConfig = $stitcherClient->getVodConfig($request);
50+
51+
// Print results
52+
printf('VOD config: %s' . PHP_EOL, $vodConfig->getName());
53+
}
54+
// [END videostitcher_get_vod_config]
55+
56+
// The following 2 lines are only needed to run the samples
57+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
58+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2024 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/videostitcher/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\Stitcher;
26+
27+
// [START videostitcher_list_vod_configs]
28+
use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient;
29+
use Google\Cloud\Video\Stitcher\V1\ListVodConfigsRequest;
30+
31+
/**
32+
* Lists all VOD configs for a location.
33+
*
34+
* @param string $callingProjectId The project ID to run the API call under
35+
* @param string $location The location of the VOD configs
36+
*/
37+
function list_vod_configs(
38+
string $callingProjectId,
39+
string $location
40+
): void {
41+
// Instantiate a client.
42+
$stitcherClient = new VideoStitcherServiceClient();
43+
44+
$parent = $stitcherClient->locationName($callingProjectId, $location);
45+
$request = (new ListVodConfigsRequest())
46+
->setParent($parent);
47+
$response = $stitcherClient->listVodConfigs($request);
48+
49+
// Print the VOD config list.
50+
$vodConfigs = $response->iterateAllElements();
51+
print('VOD configs:' . PHP_EOL);
52+
foreach ($vodConfigs as $vodConfig) {
53+
printf('%s' . PHP_EOL, $vodConfig->getName());
54+
}
55+
}
56+
// [END videostitcher_list_vod_configs]
57+
58+
// The following 2 lines are only needed to run the samples
59+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
60+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2024 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/videostitcher/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\Stitcher;
26+
27+
// [START videostitcher_update_vod_config]
28+
use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient;
29+
use Google\Cloud\Video\Stitcher\V1\UpdateVodConfigRequest;
30+
use Google\Cloud\Video\Stitcher\V1\VodConfig;
31+
use Google\Protobuf\FieldMask;
32+
33+
/**
34+
* Updates the VOD config's sourceUri field.
35+
*
36+
* @param string $callingProjectId The project ID to run the API call under
37+
* @param string $location The location of the VOD config
38+
* @param string $vodConfigId The name of the VOD config to update
39+
* @param string $sourceUri Updated uri of the media to stitch; this URI must
40+
* reference either an MPEG-DASH manifest
41+
* (.mpd) file or an M3U playlist manifest
42+
* (.m3u8) file.
43+
*/
44+
function update_vod_config(
45+
string $callingProjectId,
46+
string $location,
47+
string $vodConfigId,
48+
string $sourceUri
49+
): void {
50+
// Instantiate a client.
51+
$stitcherClient = new VideoStitcherServiceClient();
52+
53+
$formattedName = $stitcherClient->vodConfigName($callingProjectId, $location, $vodConfigId);
54+
$vodConfig = new VodConfig();
55+
$vodConfig->setName($formattedName);
56+
$vodConfig->setSourceUri($sourceUri);
57+
$updateMask = new FieldMask([
58+
'paths' => ['sourceUri']
59+
]);
60+
61+
// Run VOD config update request
62+
$request = (new UpdateVodConfigRequest())
63+
->setVodConfig($vodConfig)
64+
->setUpdateMask($updateMask);
65+
$operationResponse = $stitcherClient->updateVodConfig($request);
66+
$operationResponse->pollUntilComplete();
67+
if ($operationResponse->operationSucceeded()) {
68+
$result = $operationResponse->getResult();
69+
// Print results
70+
printf('Updated VOD config: %s' . PHP_EOL, $result->getName());
71+
} else {
72+
$error = $operationResponse->getError();
73+
// handleError($error)
74+
}
75+
}
76+
// [END videostitcher_update_vod_config]
77+
78+
// The following 2 lines are only needed to run the samples
79+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
80+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

0 commit comments

Comments
 (0)