From b990edc11adb7dbc6916cc9565e1f7c6ffff5296 Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Wed, 17 May 2017 11:26:37 -0700 Subject: [PATCH 1/6] Add GAPIC only video intelligence --- README.md | 35 ++ composer.json | 2 +- src/VideoIntelligence/LICENSE | 202 +++++++++ src/VideoIntelligence/README.md | 16 + src/VideoIntelligence/V1beta1/README.md | 5 + .../VideoIntelligenceServiceClient.php | 428 ++++++++++++++++++ ...eo_intelligence_service_client_config.json | 33 ++ src/VideoIntelligence/VERSION | 1 + src/VideoIntelligence/composer.json | 25 + 9 files changed, 746 insertions(+), 1 deletion(-) create mode 100644 src/VideoIntelligence/LICENSE create mode 100644 src/VideoIntelligence/README.md create mode 100644 src/VideoIntelligence/V1beta1/README.md create mode 100644 src/VideoIntelligence/V1beta1/VideoIntelligenceServiceClient.php create mode 100644 src/VideoIntelligence/V1beta1/resources/video_intelligence_service_client_config.json create mode 100644 src/VideoIntelligence/VERSION create mode 100644 src/VideoIntelligence/composer.json diff --git a/README.md b/README.md index 8fc1b37ab204..7b45d29d790f 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ This client supports the following Google Cloud Platform services at a [Beta](#v This client supports the following Google Cloud Platform services at an [Alpha](#versioning) quality level: * [Google Cloud Pub/Sub](#google-cloud-pubsub-alpha) (Alpha) * [Google Cloud Speech](#google-cloud-speech-alpha) (Alpha) +* [Google Cloud Video Intelligence](#google-cloud-videointelligence-alpha) (Alpha) * [Google Stackdriver Trace](#google-stackdriver-trace-alpha) (Alpha) If you need support for other Google APIs, please check out the [Google APIs Client Library for PHP](https://github.com/google/google-api-php-client). @@ -445,6 +446,40 @@ $storage = new StorageClient([ ]); ``` +## Google Cloud Video Intelligence (Alpha) + +- [API Documentation](http://googlecloudplatform.github.io/google-cloud-php/#/docs/latest/videointelligence/readme) +- [Official Documentation](https://cloud.google.com/video-intelligence/docs) + +#### Preview + +```php +require __DIR__ . '/vendor/autoload.php'; + +use Google\Cloud\VideoIntelligence\V1beta1\VideoIntelligenceServiceClient; +use google\cloud\videointelligence\v1beta1\Feature; + +$client = new VideoIntelligenceServiceClient(); + +$inputUri = "gs://example-bucket/example-video.mp4"; +$features = [ + Feature::LABEL_DETECTION, +]; +$operationResponse = $client->annotateVideo($inputUri, $features); +$operationResponse->pollUntilComplete(); +if ($operationResponse->operationSucceeded()) { + $results = $operationResponse->getResult(); + foreach ($results->getAnnotationResultsList() as $result) { + foreach ($result->getLabelAnnotationsList() as $labelAnnotation) { + echo "Label: " . $labelAnnotation->getDescription() . "\n"; + } + } +} else { + $error = $operationResponse->getError(); + echo "error: " . $error->getMessage() . "\n"; +} +``` + ## Google Stackdriver Trace (Alpha) - [API Documentation](http://googlecloudplatform.github.io/google-cloud-php/#/docs/latest/trace/traceclient) diff --git a/composer.json b/composer.json index 38de7429e585..7c312fbaef98 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,7 @@ "league/json-guard": "^0.3", "erusev/parsedown": "^1.6", "vierbergenlars/php-semver": "^3.0", - "google/proto-client-php": "^0.12", + "google/proto-client-php": "^0.13", "google/gax": "^0.8" }, "suggest": { diff --git a/src/VideoIntelligence/LICENSE b/src/VideoIntelligence/LICENSE new file mode 100644 index 000000000000..8f71f43fee3f --- /dev/null +++ b/src/VideoIntelligence/LICENSE @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + 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. + diff --git a/src/VideoIntelligence/README.md b/src/VideoIntelligence/README.md new file mode 100644 index 000000000000..7f6259d31e63 --- /dev/null +++ b/src/VideoIntelligence/README.md @@ -0,0 +1,16 @@ +# Google Cloud PHP Video Intelligence + +> Idiomatic PHP client for [Cloud Video Intelligence](https://cloud.google.com/video-intelligence/). + +* [Homepage](http://googlecloudplatform.github.io/google-cloud-php) +* [API documentation](http://googlecloudplatform.github.io/google-cloud-php/#/docs/cloud-videointelligence/latest/readme) + +**NOTE:** This repository is part of [Google Cloud PHP](https://github.com/googlecloudplatform/google-cloud-php). Any +support requests, bug reports, or development contributions should be directed to +that project. + +## Installation + +``` +$ composer require google/cloud-videointelligence +``` diff --git a/src/VideoIntelligence/V1beta1/README.md b/src/VideoIntelligence/V1beta1/README.md new file mode 100644 index 000000000000..45254ec9fc85 --- /dev/null +++ b/src/VideoIntelligence/V1beta1/README.md @@ -0,0 +1,5 @@ +# Cloud Video Intelligence + +Google Cloud Video Intelligence API makes videos searchable, and discoverable, by extracting metadata with an easy to use API. + +For more information, see [cloud.google.com](https://cloud.google.com/video-intelligence/). diff --git a/src/VideoIntelligence/V1beta1/VideoIntelligenceServiceClient.php b/src/VideoIntelligence/V1beta1/VideoIntelligenceServiceClient.php new file mode 100644 index 000000000000..4248d500acb5 --- /dev/null +++ b/src/VideoIntelligence/V1beta1/VideoIntelligenceServiceClient.php @@ -0,0 +1,428 @@ +annotateVideo($inputUri, $features); + * $operationResponse->pollUntilComplete(); + * if ($operationResponse->operationSucceeded()) { + * $result = $operationResponse->getResult(); + * // doSomethingWith($result) + * } else { + * $error = $operationResponse->getError(); + * // handleError($error) + * } + * + * // OR start the operation, keep the operation name, and resume later + * $operationResponse = $videoIntelligenceServiceClient->annotateVideo($inputUri, $features); + * $operationName = $operationResponse->getName(); + * // ... do other work + * $newOperationResponse = $videoIntelligenceServiceClient->resumeOperation($operationName, 'annotateVideo'); + * while (!$newOperationResponse->isDone()) { + * // ... do other work + * $newOperationResponse->reload(); + * } + * if ($newOperationResponse->operationSucceeded()) { + * $result = $newOperationResponse->getResult(); + * // doSomethingWith($result) + * } else { + * $error = $newOperationResponse->getError(); + * // handleError($error) + * } + * } finally { + * $videoIntelligenceServiceClient->close(); + * } + * ``` + * + * Many parameters require resource names to be formatted in a particular way. To assist + * with these names, this class includes a format method for each type of name, and additionally + * a parse method to extract the individual identifiers contained within names that are + * returned. + */ +class VideoIntelligenceServiceClient +{ + /** + * The default address of the service. + */ + const SERVICE_ADDRESS = 'videointelligence.googleapis.com'; + + /** + * The default port of the service. + */ + const DEFAULT_SERVICE_PORT = 443; + + /** + * The default timeout for non-retrying methods. + */ + const DEFAULT_TIMEOUT_MILLIS = 30000; + + /** + * The name of the code generator, to be included in the agent header. + */ + const CODEGEN_NAME = 'gapic'; + + /** + * The code generator version, to be included in the agent header. + */ + const CODEGEN_VERSION = '0.0.5'; + + private $grpcCredentialsHelper; + private $videoIntelligenceServiceStub; + private $scopes; + private $defaultCallSettings; + private $descriptors; + private $operationsClient; + + private static function getLongRunningDescriptors() + { + return [ + 'annotateVideo' => [ + 'operationReturnType' => '\google\cloud\videointelligence\v1beta1\AnnotateVideoResponse', + 'metadataReturnType' => '\google\cloud\videointelligence\v1beta1\AnnotateVideoProgress', + ], + ]; + } + + private static function getGapicVersion() + { + if (file_exists(__DIR__.'/../VERSION')) { + return trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + return \Google\Cloud\ServiceBuilder::VERSION; + } else { + return; + } + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return \Google\GAX\LongRunning\OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started + * by a long running API method. If $methodName is not provided, or does + * not match a long running API method, then the operation can still be + * resumed, but the OperationResponse object will not deserialize the + * final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return \Google\GAX\OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $lroDescriptors = self::getLongRunningDescriptors(); + if (!is_null($methodName) && array_key_exists($methodName, $lroDescriptors)) { + $options = $lroDescriptors[$methodName]; + } else { + $options = []; + } + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + + return $operation; + } + + // TODO(garrettjones): add channel (when supported in gRPC) + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $serviceAddress The domain name of the API remote host. + * Default 'videointelligence.googleapis.com'. + * @type mixed $port The port on which to connect to the remote host. Default 443. + * @type \Grpc\ChannelCredentials $sslCreds + * A `ChannelCredentials` for use with an SSL-enabled channel. + * Default: a credentials object returned from + * \Grpc\ChannelCredentials::createSsl() + * @type array $scopes A string array of scopes to use when acquiring credentials. + * Default the scopes for the Google Cloud Video Intelligence API. + * @type array $retryingOverride + * An associative array of string => RetryOptions, where the keys + * are method names (e.g. 'createFoo'), that overrides default retrying + * settings. A value of null indicates that the method in question should + * not retry. + * @type int $timeoutMillis The timeout in milliseconds to use for calls + * that don't use retries. For calls that use retries, + * set the timeout in RetryOptions. + * Default: 30000 (30 seconds) + * @type \Google\Auth\CredentialsLoader $credentialsLoader + * A CredentialsLoader object created using the + * Google\Auth library. + * } + */ + public function __construct($options = []) + { + $defaultOptions = [ + 'serviceAddress' => self::SERVICE_ADDRESS, + 'port' => self::DEFAULT_SERVICE_PORT, + 'scopes' => [ + 'https://www.googleapis.com/auth/cloud-platform', + ], + 'retryingOverride' => null, + 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, + 'libName' => null, + 'libVersion' => null, + ]; + $options = array_merge($defaultOptions, $options); + + if (array_key_exists('operationsClient', $options)) { + $this->operationsClient = $options['operationsClient']; + } else { + $this->operationsClient = new OperationsClient([ + 'serviceAddress' => $options['serviceAddress'], + 'scopes' => $options['scopes'], + 'libName' => $options['libName'], + 'libVersion' => $options['libVersion'], + ]); + } + + $gapicVersion = $options['libVersion'] ?: self::getGapicVersion(); + + $headerDescriptor = new AgentHeaderDescriptor([ + 'libName' => $options['libName'], + 'libVersion' => $options['libVersion'], + 'gapicVersion' => $gapicVersion, + ]); + + $defaultDescriptors = ['headerDescriptor' => $headerDescriptor]; + $this->descriptors = [ + 'annotateVideo' => $defaultDescriptors, + ]; + $longRunningDescriptors = self::getLongRunningDescriptors(); + foreach ($longRunningDescriptors as $method => $longRunningDescriptor) { + $this->descriptors[$method]['longRunningDescriptor'] = $longRunningDescriptor + ['operationsClient' => $this->operationsClient]; + } + + $clientConfigJsonString = file_get_contents(__DIR__.'/resources/video_intelligence_service_client_config.json'); + $clientConfig = json_decode($clientConfigJsonString, true); + $this->defaultCallSettings = + CallSettings::load( + 'google.cloud.videointelligence.v1beta1.VideoIntelligenceService', + $clientConfig, + $options['retryingOverride'], + GrpcConstants::getStatusCodeNames(), + $options['timeoutMillis'] + ); + + $this->scopes = $options['scopes']; + + $createStubOptions = []; + if (array_key_exists('sslCreds', $options)) { + $createStubOptions['sslCreds'] = $options['sslCreds']; + } + $grpcCredentialsHelperOptions = array_diff_key($options, $defaultOptions); + $this->grpcCredentialsHelper = new GrpcCredentialsHelper($this->scopes, $grpcCredentialsHelperOptions); + + $createVideoIntelligenceServiceStubFunction = function ($hostname, $opts) { + return new VideoIntelligenceServiceGrpcClient($hostname, $opts); + }; + if (array_key_exists('createVideoIntelligenceServiceStubFunction', $options)) { + $createVideoIntelligenceServiceStubFunction = $options['createVideoIntelligenceServiceStubFunction']; + } + $this->videoIntelligenceServiceStub = $this->grpcCredentialsHelper->createStub( + $createVideoIntelligenceServiceStubFunction, + $options['serviceAddress'], + $options['port'], + $createStubOptions + ); + } + + /** + * Performs asynchronous video annotation. Progress and results can be + * retrieved through the `google.longrunning.Operations` interface. + * `Operation.metadata` contains `AnnotateVideoProgress` (progress). + * `Operation.response` contains `AnnotateVideoResponse` (results). + * + * Sample code: + * ``` + * try { + * $videoIntelligenceServiceClient = new VideoIntelligenceServiceClient(); + * $inputUri = ""; + * $features = []; + * $operationResponse = $videoIntelligenceServiceClient->annotateVideo($inputUri, $features); + * $operationResponse->pollUntilComplete(); + * if ($operationResponse->operationSucceeded()) { + * $result = $operationResponse->getResult(); + * // doSomethingWith($result) + * } else { + * $error = $operationResponse->getError(); + * // handleError($error) + * } + * + * // OR start the operation, keep the operation name, and resume later + * $operationResponse = $videoIntelligenceServiceClient->annotateVideo($inputUri, $features); + * $operationName = $operationResponse->getName(); + * // ... do other work + * $newOperationResponse = $videoIntelligenceServiceClient->resumeOperation($operationName, 'annotateVideo'); + * while (!$newOperationResponse->isDone()) { + * // ... do other work + * $newOperationResponse->reload(); + * } + * if ($newOperationResponse->operationSucceeded()) { + * $result = $newOperationResponse->getResult(); + * // doSomethingWith($result) + * } else { + * $error = $newOperationResponse->getError(); + * // handleError($error) + * } + * } finally { + * $videoIntelligenceServiceClient->close(); + * } + * ``` + * + * @param string $inputUri Input video location. Currently, only + * [Google Cloud Storage](https://cloud.google.com/storage/) URIs are + * supported, which must be specified in the following format: + * `gs://bucket-id/object-id` (other URI formats return + * [google.rpc.Code.INVALID_ARGUMENT][google.rpc.Code.INVALID_ARGUMENT]). For more information, see + * [Request URIs](/storage/docs/reference-uris). + * A video URI may include wildcards in `object-id`, and thus identify + * multiple videos. Supported wildcards: '*' to match 0 or more characters; + * '?' to match 1 character. If unset, the input video should be embedded + * in the request as `input_content`. If set, `input_content` should be unset. + * @param Feature[] $features Requested video annotation features. + * @param array $optionalArgs { + * Optional. + * + * @type string $inputContent + * The video data bytes. Encoding: base64. If unset, the input video(s) + * should be specified via `input_uri`. If set, `input_uri` should be unset. + * @type VideoContext $videoContext + * Additional video context and/or feature-specific parameters. + * @type string $outputUri + * Optional location where the output (in JSON format) should be stored. + * Currently, only [Google Cloud Storage](https://cloud.google.com/storage/) + * URIs are supported, which must be specified in the following format: + * `gs://bucket-id/object-id` (other URI formats return + * [google.rpc.Code.INVALID_ARGUMENT][google.rpc.Code.INVALID_ARGUMENT]). For more information, see + * [Request URIs](/storage/docs/reference-uris). + * @type string $locationId + * Optional cloud region where annotation should take place. Supported cloud + * regions: `us-east1`, `us-west1`, `europe-west1`, `asia-east1`. If no region + * is specified, a region will be determined based on video file location. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \google\longrunning\Operation + * + * @throws \Google\GAX\ApiException if the remote call fails + */ + public function annotateVideo($inputUri, $features, $optionalArgs = []) + { + $request = new AnnotateVideoRequest(); + $request->setInputUri($inputUri); + foreach ($features as $elem) { + $request->addFeatures($elem); + } + if (isset($optionalArgs['inputContent'])) { + $request->setInputContent($optionalArgs['inputContent']); + } + if (isset($optionalArgs['videoContext'])) { + $request->setVideoContext($optionalArgs['videoContext']); + } + if (isset($optionalArgs['outputUri'])) { + $request->setOutputUri($optionalArgs['outputUri']); + } + if (isset($optionalArgs['locationId'])) { + $request->setLocationId($optionalArgs['locationId']); + } + + $mergedSettings = $this->defaultCallSettings['annotateVideo']->merge( + new CallSettings($optionalArgs) + ); + $callable = ApiCallable::createApiCall( + $this->videoIntelligenceServiceStub, + 'AnnotateVideo', + $mergedSettings, + $this->descriptors['annotateVideo'] + ); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Initiates an orderly shutdown in which preexisting calls continue but new + * calls are immediately cancelled. + */ + public function close() + { + $this->videoIntelligenceServiceStub->close(); + } + + private function createCredentialsCallback() + { + return $this->grpcCredentialsHelper->createCallCredentialsCallback(); + } +} diff --git a/src/VideoIntelligence/V1beta1/resources/video_intelligence_service_client_config.json b/src/VideoIntelligence/V1beta1/resources/video_intelligence_service_client_config.json new file mode 100644 index 000000000000..7dd61bbb7b5d --- /dev/null +++ b/src/VideoIntelligence/V1beta1/resources/video_intelligence_service_client_config.json @@ -0,0 +1,33 @@ +{ + "interfaces": { + "google.cloud.videointelligence.v1beta1.VideoIntelligenceService": { + "retry_codes": { + "idempotent": [ + "DEADLINE_EXCEEDED", + "UNAVAILABLE" + ], + "non_idempotent": [ + "UNAVAILABLE" + ] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 1000, + "retry_delay_multiplier": 2.5, + "max_retry_delay_millis": 120000, + "initial_rpc_timeout_millis": 120000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 120000, + "total_timeout_millis": 600000 + } + }, + "methods": { + "AnnotateVideo": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + } + } + } + } +} diff --git a/src/VideoIntelligence/VERSION b/src/VideoIntelligence/VERSION new file mode 100644 index 000000000000..6e8bf73aa550 --- /dev/null +++ b/src/VideoIntelligence/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/src/VideoIntelligence/composer.json b/src/VideoIntelligence/composer.json new file mode 100644 index 000000000000..3350a2da70d4 --- /dev/null +++ b/src/VideoIntelligence/composer.json @@ -0,0 +1,25 @@ +{ + "name": "google/cloud-videointelligence", + "description": "Cloud Video Intelligence Client for PHP", + "license": "Apache-2.0", + "minimum-stability": "stable", + "require": { + "ext-grpc": "*", + "google/cloud-core": "^1.0", + "google/proto-client-php": "^0.13", + "google/gax": "^0.9" + }, + "extra": { + "component": { + "id": "cloud-videointelligence", + "target": "GoogleCloudPlatform/google-cloud-php-videointelligence.git", + "path": "src/VideoIntelligence", + "entry": null + } + }, + "autoload": { + "psr-4": { + "Google\\Cloud\\VideoIntelligence\\": "" + } + } +} From ed48da5153e64a513037639812e9e124accfda9f Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Wed, 17 May 2017 13:21:39 -0700 Subject: [PATCH 2/6] Add docs --- docs/contents/cloud-videointelligence.json | 18 ++++++++++++++++++ docs/manifest.json | 9 +++++++++ 2 files changed, 27 insertions(+) create mode 100644 docs/contents/cloud-videointelligence.json diff --git a/docs/contents/cloud-videointelligence.json b/docs/contents/cloud-videointelligence.json new file mode 100644 index 000000000000..a43d2c6aeb97 --- /dev/null +++ b/docs/contents/cloud-videointelligence.json @@ -0,0 +1,18 @@ +{ + "title": "Video Intelligence", + "pattern": "videointelligence\/\\w{1,}", + "services": [{ + "title": "Overview", + "type": "videointelligence/readme" + }, { + "title": "v1beta1", + "type": "videointelligence/v1beta1/readme", + "patterns": [ + "videointelligence/v1beta1/\\w{1,}" + ], + "nav": [{ + "title": "VideoIntelligenceServiceClient", + "type": "videointelligence/v1beta1/videointelligenceserviceclient" + }] + }] +} diff --git a/docs/manifest.json b/docs/manifest.json index 811e7c8ef55c..b3e2db1fca7c 100644 --- a/docs/manifest.json +++ b/docs/manifest.json @@ -163,6 +163,15 @@ "master" ] }, + { + "id": "cloud-videointelligence", + "name": "google/cloud-videointelligence", + "defaultService": "videointelligence/videointelligenceserviceclient", + "versions": [ + "v0.1.0", + "master" + ] + }, { "id": "cloud-vision", "name": "google/cloud-vision", From af38d6a79e90cda237fdaf0350ede261a972c0be Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Wed, 17 May 2017 13:34:08 -0700 Subject: [PATCH 3/6] Update namespace capitalization --- .../V1beta1/VideoIntelligenceServiceClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VideoIntelligence/V1beta1/VideoIntelligenceServiceClient.php b/src/VideoIntelligence/V1beta1/VideoIntelligenceServiceClient.php index 4248d500acb5..93bb42949234 100644 --- a/src/VideoIntelligence/V1beta1/VideoIntelligenceServiceClient.php +++ b/src/VideoIntelligence/V1beta1/VideoIntelligenceServiceClient.php @@ -26,7 +26,7 @@ * backwards compatibility. */ -namespace Google\Cloud\VideoIntelligence\V1Beta1; +namespace Google\Cloud\VideoIntelligence\V1beta1; use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; From 40959b6aaf8c0e3b6cd470d0a2c9db700ee97c70 Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Wed, 17 May 2017 15:16:20 -0700 Subject: [PATCH 4/6] Address PR comments --- docs/external-classes.json | 9 +++++++++ docs/manifest.json | 1 - src/VideoIntelligence/README.md | 10 ++++++++++ .../V1beta1/VideoIntelligenceServiceClient.php | 3 ++- src/VideoIntelligence/composer.json | 1 - 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/external-classes.json b/docs/external-classes.json index 2eab6a7b0fc5..97d764de7904 100644 --- a/docs/external-classes.json +++ b/docs/external-classes.json @@ -85,5 +85,14 @@ }, { "name": "PushConfig", "uri": "https://github.com/googleapis/proto-client-php/blob/master/src/pubsub/v1/pubsub.php#L1827" +}, { + "name": "google\\cloud\\videointelligence\\v1beta1\\", + "uri": "https://github.com/googleapis/proto-client-php/tree/master/src/videointelligence/v1beta1" +}, { + "name": "VideoContext", + "uri": "https://github.com/googleapis/proto-client-php/blob/master/src/videointelligence/v1beta1/video_intelligence.php#L379" +}, { + "name": "google\\cloud\\videointelligence\\v1beta1\\Feature", + "uri": "https://github.com/googleapis/proto-client-php/blob/master/src/videointelligence/v1beta1/video_intelligence.php#8" }] diff --git a/docs/manifest.json b/docs/manifest.json index b3e2db1fca7c..b69caa2a35d5 100644 --- a/docs/manifest.json +++ b/docs/manifest.json @@ -168,7 +168,6 @@ "name": "google/cloud-videointelligence", "defaultService": "videointelligence/videointelligenceserviceclient", "versions": [ - "v0.1.0", "master" ] }, diff --git a/src/VideoIntelligence/README.md b/src/VideoIntelligence/README.md index 7f6259d31e63..e37b92fb494a 100644 --- a/src/VideoIntelligence/README.md +++ b/src/VideoIntelligence/README.md @@ -9,6 +9,16 @@ support requests, bug reports, or development contributions should be directed to that project. +This client supports transport over gRPC. In order to enable gRPC support please make sure to install and enable +the gRPC extension through PECL: + +```sh +$ pecl install grpc +``` + +NOTE: Support for gRPC is currently at an Alpha quality level, meaning it is still +a work in progress and is more likely to get backwards-incompatible updates. + ## Installation ``` diff --git a/src/VideoIntelligence/V1beta1/VideoIntelligenceServiceClient.php b/src/VideoIntelligence/V1beta1/VideoIntelligenceServiceClient.php index 93bb42949234..05cd49b9580c 100644 --- a/src/VideoIntelligence/V1beta1/VideoIntelligenceServiceClient.php +++ b/src/VideoIntelligence/V1beta1/VideoIntelligenceServiceClient.php @@ -344,7 +344,8 @@ public function __construct($options = []) * multiple videos. Supported wildcards: '*' to match 0 or more characters; * '?' to match 1 character. If unset, the input video should be embedded * in the request as `input_content`. If set, `input_content` should be unset. - * @param Feature[] $features Requested video annotation features. + * @param int[] $features Requested video annotation features. For allowed values, use constants defined on + * {@see google\cloud\videointelligence\v1beta1\Feature}. * @param array $optionalArgs { * Optional. * diff --git a/src/VideoIntelligence/composer.json b/src/VideoIntelligence/composer.json index 3350a2da70d4..b2730781b126 100644 --- a/src/VideoIntelligence/composer.json +++ b/src/VideoIntelligence/composer.json @@ -5,7 +5,6 @@ "minimum-stability": "stable", "require": { "ext-grpc": "*", - "google/cloud-core": "^1.0", "google/proto-client-php": "^0.13", "google/gax": "^0.9" }, From 5708c9951a6b508321aef9f591b2ec74cf9f9585 Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Wed, 17 May 2017 15:18:02 -0700 Subject: [PATCH 5/6] Fix * escaping --- .../V1beta1/VideoIntelligenceServiceClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VideoIntelligence/V1beta1/VideoIntelligenceServiceClient.php b/src/VideoIntelligence/V1beta1/VideoIntelligenceServiceClient.php index 05cd49b9580c..a283ef134b70 100644 --- a/src/VideoIntelligence/V1beta1/VideoIntelligenceServiceClient.php +++ b/src/VideoIntelligence/V1beta1/VideoIntelligenceServiceClient.php @@ -341,7 +341,7 @@ public function __construct($options = []) * [google.rpc.Code.INVALID_ARGUMENT][google.rpc.Code.INVALID_ARGUMENT]). For more information, see * [Request URIs](/storage/docs/reference-uris). * A video URI may include wildcards in `object-id`, and thus identify - * multiple videos. Supported wildcards: '*' to match 0 or more characters; + * multiple videos. Supported wildcards: '*' to match 0 or more characters; * '?' to match 1 character. If unset, the input video should be embedded * in the request as `input_content`. If set, `input_content` should be unset. * @param int[] $features Requested video annotation features. For allowed values, use constants defined on From 209beb7ed7cd9be79948ae2fcd3f68e2173c3330 Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Wed, 17 May 2017 15:24:44 -0700 Subject: [PATCH 6/6] Update grpc install description --- src/VideoIntelligence/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/VideoIntelligence/README.md b/src/VideoIntelligence/README.md index e37b92fb494a..04570727b8b2 100644 --- a/src/VideoIntelligence/README.md +++ b/src/VideoIntelligence/README.md @@ -16,6 +16,16 @@ the gRPC extension through PECL: $ pecl install grpc ``` +If you are using Video Intelligence through the umbrella package (google/cloud), +you will also need to install the following dependencies through composer: + +```sh +$ composer require google/gax && composer require google/proto-client-php +``` + +Please take care in installing the same version of these libraries that are +outlined in the project's composer.json require-dev keyword. + NOTE: Support for gRPC is currently at an Alpha quality level, meaning it is still a work in progress and is more likely to get backwards-incompatible updates.