Skip to content

Commit 02c1303

Browse files
authored
feat(VideoStitcher): update slates and CDN keys to return LROs; add live config samples and tests (GoogleCloudPlatform#1876)
1 parent ec929af commit 02c1303

16 files changed

+446
-54
lines changed

media/videostitcher/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"name": "google/video-stitcher-sample",
33
"type": "project",
44
"require": {
5-
"google/cloud-video-stitcher": "^0.3.0"
5+
"google/cloud-video-stitcher": "^0.7.0"
66
}
77
}

media/videostitcher/src/create_cdn_key.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,16 @@ function create_cdn_key(
7575
$cloudCdn->setPrivateKey($privateKey);
7676

7777
// Run CDN key creation request
78-
$response = $stitcherClient->createCdnKey($parent, $cdnKey, $cdnKeyId);
79-
80-
// Print results
81-
printf('CDN key: %s' . PHP_EOL, $response->getName());
78+
$operationResponse = $stitcherClient->createCdnKey($parent, $cdnKey, $cdnKeyId);
79+
$operationResponse->pollUntilComplete();
80+
if ($operationResponse->operationSucceeded()) {
81+
$result = $operationResponse->getResult();
82+
// Print results
83+
printf('CDN key: %s' . PHP_EOL, $result->getName());
84+
} else {
85+
$error = $operationResponse->getError();
86+
// handleError($error)
87+
}
8288
}
8389
// [END videostitcher_create_cdn_key]
8490

media/videostitcher/src/create_cdn_key_akamai.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,16 @@ function create_cdn_key_akamai(
5757
$cdnKey->setAkamaiCdnKey($cloudCdn);
5858

5959
// Run CDN key creation request
60-
$response = $stitcherClient->createCdnKey($parent, $cdnKey, $cdnKeyId);
61-
62-
// Print results
63-
printf('CDN key: %s' . PHP_EOL, $response->getName());
60+
$operationResponse = $stitcherClient->createCdnKey($parent, $cdnKey, $cdnKeyId);
61+
$operationResponse->pollUntilComplete();
62+
if ($operationResponse->operationSucceeded()) {
63+
$result = $operationResponse->getResult();
64+
// Print results
65+
printf('CDN key: %s' . PHP_EOL, $result->getName());
66+
} else {
67+
$error = $operationResponse->getError();
68+
// handleError($error)
69+
}
6470
}
6571
// [END videostitcher_create_cdn_key_akamai]
6672

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2023 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_live_config]
28+
use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient;
29+
use Google\Cloud\Video\Stitcher\V1\AdTracking;
30+
use Google\Cloud\Video\Stitcher\V1\LiveConfig;
31+
32+
/**
33+
* Creates a live config. Live configs are used to configure live sessions.
34+
*
35+
* @param string $callingProjectId The project ID to run the API call under
36+
* @param string $location The location of the live config
37+
* @param string $liveConfigId The name of the live 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+
* @param string $slateId The user-defined slate ID of the default
44+
* slate to use when no slates are specified
45+
* in an ad break's message
46+
*/
47+
function create_live_config(
48+
string $callingProjectId,
49+
string $location,
50+
string $liveConfigId,
51+
string $sourceUri,
52+
string $adTagUri,
53+
string $slateId
54+
): void {
55+
// Instantiate a client.
56+
$stitcherClient = new VideoStitcherServiceClient();
57+
58+
$parent = $stitcherClient->locationName($callingProjectId, $location);
59+
$defaultSlate = $stitcherClient->slateName($callingProjectId, $location, $slateId);
60+
61+
$liveConfig = (new LiveConfig())
62+
->setSourceUri($sourceUri)
63+
->setAdTagUri($adTagUri)
64+
->setAdTracking(AdTracking::SERVER)
65+
->setStitchingPolicy(LiveConfig\StitchingPolicy::CUT_CURRENT)
66+
->setDefaultSlate($defaultSlate);
67+
68+
// Run live config creation request
69+
$operationResponse = $stitcherClient->createLiveConfig($parent, $liveConfigId, $liveConfig);
70+
$operationResponse->pollUntilComplete();
71+
if ($operationResponse->operationSucceeded()) {
72+
$result = $operationResponse->getResult();
73+
// Print results
74+
printf('Live config: %s' . PHP_EOL, $result->getName());
75+
} else {
76+
$error = $operationResponse->getError();
77+
// handleError($error)
78+
}
79+
}
80+
// [END videostitcher_create_live_config]
81+
82+
// The following 2 lines are only needed to run the samples
83+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
84+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

media/videostitcher/src/create_live_session.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
namespace Google\Cloud\Samples\Media\Stitcher;
2626

2727
// [START videostitcher_create_live_session]
28-
use Google\Cloud\Video\Stitcher\V1\AdTag;
2928
use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient;
3029
use Google\Cloud\Video\Stitcher\V1\LiveSession;
3130

@@ -35,33 +34,21 @@
3534
*
3635
* @param string $callingProjectId The project ID to run the API call under
3736
* @param string $location The location of the session
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-
* @param string $slateId The user-defined slate ID of the default
44-
* slate to use when no slates are specified
45-
* in an ad break's message
37+
* @param string $liveConfigId The live config ID to use to create the
38+
* live session
4639
*/
4740
function create_live_session(
4841
string $callingProjectId,
4942
string $location,
50-
string $sourceUri,
51-
string $adTagUri,
52-
string $slateId
43+
string $liveConfigId
5344
): void {
5445
// Instantiate a client.
5546
$stitcherClient = new VideoStitcherServiceClient();
5647

5748
$parent = $stitcherClient->locationName($callingProjectId, $location);
49+
$liveConfig = $stitcherClient->liveConfigName($callingProjectId, $location, $liveConfigId);
5850
$liveSession = new LiveSession();
59-
$liveSession->setSourceUri($sourceUri);
60-
$liveSession->setAdTagMap([
61-
'default' => (new AdTag())
62-
->setUri($adTagUri)
63-
]);
64-
$liveSession->setDefaultSlateId($slateId);
51+
$liveSession->setLiveConfig($liveConfig);
6552

6653
// Run live session creation request
6754
$response = $stitcherClient->createLiveSession($parent, $liveSession);

media/videostitcher/src/create_slate.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,16 @@ function create_slate(
5050
$slate->setUri($slateUri);
5151

5252
// Run slate creation request
53-
$response = $stitcherClient->createSlate($parent, $slateId, $slate);
54-
55-
// Print results
56-
printf('Slate: %s' . PHP_EOL, $response->getName());
53+
$operationResponse = $stitcherClient->createSlate($parent, $slateId, $slate);
54+
$operationResponse->pollUntilComplete();
55+
if ($operationResponse->operationSucceeded()) {
56+
$result = $operationResponse->getResult();
57+
// Print results
58+
printf('Slate: %s' . PHP_EOL, $result->getName());
59+
} else {
60+
$error = $operationResponse->getError();
61+
// handleError($error)
62+
}
5763
}
5864
// [END videostitcher_create_slate]
5965

media/videostitcher/src/create_vod_session.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
// [START videostitcher_create_vod_session]
2828
use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient;
29+
use Google\Cloud\Video\Stitcher\V1\AdTracking;
2930
use Google\Cloud\Video\Stitcher\V1\VodSession;
3031

3132
/**
@@ -53,6 +54,7 @@ function create_vod_session(
5354
$vodSession = new VodSession();
5455
$vodSession->setSourceUri($sourceUri);
5556
$vodSession->setAdTagUri($adTagUri);
57+
$vodSession->setAdTracking(AdTracking::SERVER);
5658

5759
// Run VOD session creation request
5860
$response = $stitcherClient->createVodSession($parent, $vodSession);

media/videostitcher/src/delete_cdn_key.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,15 @@ function delete_cdn_key(
4343
$stitcherClient = new VideoStitcherServiceClient();
4444

4545
$formattedName = $stitcherClient->cdnKeyName($callingProjectId, $location, $cdnKeyId);
46-
$stitcherClient->deleteCdnKey($formattedName);
47-
48-
// Print status
49-
printf('Deleted CDN key %s' . PHP_EOL, $cdnKeyId);
46+
$operationResponse = $stitcherClient->deleteCdnKey($formattedName);
47+
$operationResponse->pollUntilComplete();
48+
if ($operationResponse->operationSucceeded()) {
49+
// Print status
50+
printf('Deleted CDN key %s' . PHP_EOL, $cdnKeyId);
51+
} else {
52+
$error = $operationResponse->getError();
53+
// handleError($error)
54+
}
5055
}
5156
// [END videostitcher_delete_cdn_key]
5257

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2023 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_live_config]
28+
use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient;
29+
30+
/**
31+
* Deletes a live config.
32+
*
33+
* @param string $callingProjectId The project ID to run the API call under
34+
* @param string $location The location of the live config
35+
* @param string $liveConfigId The ID of the live config
36+
*/
37+
function delete_live_config(
38+
string $callingProjectId,
39+
string $location,
40+
string $liveConfigId
41+
): void {
42+
// Instantiate a client.
43+
$stitcherClient = new VideoStitcherServiceClient();
44+
45+
$formattedName = $stitcherClient->liveConfigName($callingProjectId, $location, $liveConfigId);
46+
$operationResponse = $stitcherClient->deleteLiveConfig($formattedName);
47+
$operationResponse->pollUntilComplete();
48+
if ($operationResponse->operationSucceeded()) {
49+
// Print status
50+
printf('Deleted live config %s' . PHP_EOL, $liveConfigId);
51+
} else {
52+
$error = $operationResponse->getError();
53+
// handleError($error)
54+
}
55+
}
56+
// [END videostitcher_delete_live_config]
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);

media/videostitcher/src/delete_slate.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,15 @@ function delete_slate(
4343
$stitcherClient = new VideoStitcherServiceClient();
4444

4545
$formattedName = $stitcherClient->slateName($callingProjectId, $location, $slateId);
46-
$stitcherClient->deleteSlate($formattedName);
47-
48-
// Print status
49-
printf('Deleted slate %s' . PHP_EOL, $slateId);
46+
$operationResponse = $stitcherClient->deleteSlate($formattedName);
47+
$operationResponse->pollUntilComplete();
48+
if ($operationResponse->operationSucceeded()) {
49+
// Print status
50+
printf('Deleted slate %s' . PHP_EOL, $slateId);
51+
} else {
52+
$error = $operationResponse->getError();
53+
// handleError($error)
54+
}
5055
}
5156
// [END videostitcher_delete_slate]
5257

0 commit comments

Comments
 (0)