|
| 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); |
0 commit comments