From a2cdd0548324b409f45af26d269cf3699f9cd499 Mon Sep 17 00:00:00 2001 From: Cody Oss <6331106+codyoss@users.noreply.github.com> Date: Fri, 17 Jun 2022 11:24:04 -0500 Subject: [PATCH] feat(videointelligence): start generating apv1p3beta1 (#6176) --- internal/.repo-metadata-full.json | 9 + internal/gapicgen/generator/config.go | 8 + videointelligence/apiv1p3beta1/doc.go | 168 +++++++++ .../apiv1p3beta1/gapic_metadata.json | 37 ++ .../streaming_video_intelligence_client.go | 212 ++++++++++++ ..._video_intelligence_client_example_test.go | 72 ++++ videointelligence/apiv1p3beta1/version.go | 23 ++ .../apiv1p3beta1/video_intelligence_client.go | 320 ++++++++++++++++++ .../video_intelligence_client_example_test.go | 61 ++++ 9 files changed, 910 insertions(+) create mode 100644 videointelligence/apiv1p3beta1/doc.go create mode 100644 videointelligence/apiv1p3beta1/gapic_metadata.json create mode 100644 videointelligence/apiv1p3beta1/streaming_video_intelligence_client.go create mode 100644 videointelligence/apiv1p3beta1/streaming_video_intelligence_client_example_test.go create mode 100644 videointelligence/apiv1p3beta1/version.go create mode 100644 videointelligence/apiv1p3beta1/video_intelligence_client.go create mode 100644 videointelligence/apiv1p3beta1/video_intelligence_client_example_test.go diff --git a/internal/.repo-metadata-full.json b/internal/.repo-metadata-full.json index 72402161fde9..9432623e7240 100644 --- a/internal/.repo-metadata-full.json +++ b/internal/.repo-metadata-full.json @@ -1673,6 +1673,15 @@ "release_level": "beta", "library_type": "GAPIC_AUTO" }, + "cloud.google.com/go/videointelligence/apiv1p3beta1": { + "distribution_name": "cloud.google.com/go/videointelligence/apiv1p3beta1", + "description": "Cloud Video Intelligence API", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/videointelligence/latest/apiv1p3beta1", + "release_level": "beta", + "library_type": "GAPIC_AUTO" + }, "cloud.google.com/go/vision/apiv1p1beta1": { "distribution_name": "cloud.google.com/go/vision/apiv1p1beta1", "description": "Cloud Vision API", diff --git a/internal/gapicgen/generator/config.go b/internal/gapicgen/generator/config.go index e7da7b11dd4c..c1b72cd355e4 100644 --- a/internal/gapicgen/generator/config.go +++ b/internal/gapicgen/generator/config.go @@ -1514,6 +1514,14 @@ var MicrogenGapicConfigs = []*MicrogenConfig{ // GA after 2022/07/10 ReleaseLevel: "beta", }, + { + InputDirectoryPath: "google/cloud/videointelligence/v1p3beta1", + Pkg: "videointelligence", + ImportPath: "cloud.google.com/go/videointelligence/apiv1p3beta1", + GRPCServiceConfigPath: "videointelligence_grpc_service_config.json", + ApiServiceConfigPath: "videointelligence_v1p3beta1.yaml", + ReleaseLevel: "beta", + }, // Non-Cloud APIs { diff --git a/videointelligence/apiv1p3beta1/doc.go b/videointelligence/apiv1p3beta1/doc.go new file mode 100644 index 000000000000..46d81f46ec78 --- /dev/null +++ b/videointelligence/apiv1p3beta1/doc.go @@ -0,0 +1,168 @@ +// Copyright 2022 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 +// +// https://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. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +// Package videointelligence is an auto-generated package for the +// Cloud Video Intelligence API. +// +// Detects objects, explicit content, and scene changes in videos. It also +// specifies the region for annotation and transcribes speech to text. +// Supports both asynchronous API and streaming API. +// +// NOTE: This package is in beta. It is not stable, and may be subject to changes. +// +// Example usage +// +// To get started with this package, create a client. +// ctx := context.Background() +// c, err := videointelligence.NewClient(ctx) +// if err != nil { +// // TODO: Handle error. +// } +// defer c.Close() +// +// The client will use your default application credentials. Clients should be reused instead of created as needed. +// The methods of Client are safe for concurrent use by multiple goroutines. +// The returned client must be Closed when it is done being used. +// +// Using the Client +// +// The following is an example of making an API call with the newly created client. +// +// ctx := context.Background() +// c, err := videointelligence.NewClient(ctx) +// if err != nil { +// // TODO: Handle error. +// } +// defer c.Close() +// +// req := &videointelligencepb.AnnotateVideoRequest{ +// // TODO: Fill request struct fields. +// // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/videointelligence/v1p3beta1#AnnotateVideoRequest. +// } +// op, err := c.AnnotateVideo(ctx, req) +// if err != nil { +// // TODO: Handle error. +// } +// +// resp, err := op.Wait(ctx) +// if err != nil { +// // TODO: Handle error. +// } +// // TODO: Use resp. +// _ = resp +// +// Use of Context +// +// The ctx passed to NewClient is used for authentication requests and +// for creating the underlying connection, but is not used for subsequent calls. +// Individual methods on the client use the ctx given to them. +// +// To close the open connection, use the Close() method. +// +// For information about setting deadlines, reusing contexts, and more +// please visit https://pkg.go.dev/cloud.google.com/go. +package videointelligence // import "cloud.google.com/go/videointelligence/apiv1p3beta1" + +import ( + "context" + "os" + "runtime" + "strconv" + "strings" + "unicode" + + "google.golang.org/api/option" + "google.golang.org/grpc/metadata" +) + +// For more information on implementing a client constructor hook, see +// https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors. +type clientHookParams struct{} +type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) + +var versionClient string + +func getVersionClient() string { + if versionClient == "" { + return "UNKNOWN" + } + return versionClient +} + +func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { + out, _ := metadata.FromOutgoingContext(ctx) + out = out.Copy() + for _, md := range mds { + for k, v := range md { + out[k] = append(out[k], v...) + } + } + return metadata.NewOutgoingContext(ctx, out) +} + +func checkDisableDeadlines() (bool, error) { + raw, ok := os.LookupEnv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE") + if !ok { + return false, nil + } + + b, err := strconv.ParseBool(raw) + return b, err +} + +// DefaultAuthScopes reports the default set of authentication scopes to use with this package. +func DefaultAuthScopes() []string { + return []string{ + "https://www.googleapis.com/auth/cloud-platform", + } +} + +// versionGo returns the Go runtime version. The returned string +// has no whitespace, suitable for reporting in header. +func versionGo() string { + const develPrefix = "devel +" + + s := runtime.Version() + if strings.HasPrefix(s, develPrefix) { + s = s[len(develPrefix):] + if p := strings.IndexFunc(s, unicode.IsSpace); p >= 0 { + s = s[:p] + } + return s + } + + notSemverRune := func(r rune) bool { + return !strings.ContainsRune("0123456789.", r) + } + + if strings.HasPrefix(s, "go1") { + s = s[2:] + var prerelease string + if p := strings.IndexFunc(s, notSemverRune); p >= 0 { + s, prerelease = s[:p], s[p:] + } + if strings.HasSuffix(s, ".") { + s += "0" + } else if strings.Count(s, ".") < 2 { + s += ".0" + } + if prerelease != "" { + s += "-" + prerelease + } + return s + } + return "UNKNOWN" +} diff --git a/videointelligence/apiv1p3beta1/gapic_metadata.json b/videointelligence/apiv1p3beta1/gapic_metadata.json new file mode 100644 index 000000000000..7a25c38d39ab --- /dev/null +++ b/videointelligence/apiv1p3beta1/gapic_metadata.json @@ -0,0 +1,37 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods.", + "language": "go", + "protoPackage": "google.cloud.videointelligence.v1p3beta1", + "libraryPackage": "cloud.google.com/go/videointelligence/apiv1p3beta1", + "services": { + "StreamingVideoIntelligenceService": { + "clients": { + "grpc": { + "libraryClient": "StreamingVideoIntelligenceClient", + "rpcs": { + "StreamingAnnotateVideo": { + "methods": [ + "StreamingAnnotateVideo" + ] + } + } + } + } + }, + "VideoIntelligenceService": { + "clients": { + "grpc": { + "libraryClient": "Client", + "rpcs": { + "AnnotateVideo": { + "methods": [ + "AnnotateVideo" + ] + } + } + } + } + } + } +} diff --git a/videointelligence/apiv1p3beta1/streaming_video_intelligence_client.go b/videointelligence/apiv1p3beta1/streaming_video_intelligence_client.go new file mode 100644 index 000000000000..490d45e4f300 --- /dev/null +++ b/videointelligence/apiv1p3beta1/streaming_video_intelligence_client.go @@ -0,0 +1,212 @@ +// Copyright 2022 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 +// +// https://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. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package videointelligence + +import ( + "context" + "math" + "time" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + videointelligencepb "google.golang.org/genproto/googleapis/cloud/videointelligence/v1p3beta1" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newStreamingVideoIntelligenceClientHook clientHook + +// StreamingVideoIntelligenceCallOptions contains the retry settings for each method of StreamingVideoIntelligenceClient. +type StreamingVideoIntelligenceCallOptions struct { + StreamingAnnotateVideo []gax.CallOption +} + +func defaultStreamingVideoIntelligenceGRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("videointelligence.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("videointelligence.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://videointelligence.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultStreamingVideoIntelligenceCallOptions() *StreamingVideoIntelligenceCallOptions { + return &StreamingVideoIntelligenceCallOptions{ + StreamingAnnotateVideo: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// internalStreamingVideoIntelligenceClient is an interface that defines the methods availaible from Cloud Video Intelligence API. +type internalStreamingVideoIntelligenceClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + StreamingAnnotateVideo(context.Context, ...gax.CallOption) (videointelligencepb.StreamingVideoIntelligenceService_StreamingAnnotateVideoClient, error) +} + +// StreamingVideoIntelligenceClient is a client for interacting with Cloud Video Intelligence API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// Service that implements streaming Video Intelligence API. +type StreamingVideoIntelligenceClient struct { + // The internal transport-dependent client. + internalClient internalStreamingVideoIntelligenceClient + + // The call options for this service. + CallOptions *StreamingVideoIntelligenceCallOptions +} + +// Wrapper methods routed to the internal client. + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *StreamingVideoIntelligenceClient) Close() error { + return c.internalClient.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *StreamingVideoIntelligenceClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *StreamingVideoIntelligenceClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// StreamingAnnotateVideo performs video annotation with bidirectional streaming: emitting results +// while sending video/audio bytes. +// This method is only available via the gRPC API (not REST). +func (c *StreamingVideoIntelligenceClient) StreamingAnnotateVideo(ctx context.Context, opts ...gax.CallOption) (videointelligencepb.StreamingVideoIntelligenceService_StreamingAnnotateVideoClient, error) { + return c.internalClient.StreamingAnnotateVideo(ctx, opts...) +} + +// streamingVideoIntelligenceGRPCClient is a client for interacting with Cloud Video Intelligence API over gRPC transport. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type streamingVideoIntelligenceGRPCClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // Points back to the CallOptions field of the containing StreamingVideoIntelligenceClient + CallOptions **StreamingVideoIntelligenceCallOptions + + // The gRPC API client. + streamingVideoIntelligenceClient videointelligencepb.StreamingVideoIntelligenceServiceClient + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewStreamingVideoIntelligenceClient creates a new streaming video intelligence service client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// Service that implements streaming Video Intelligence API. +func NewStreamingVideoIntelligenceClient(ctx context.Context, opts ...option.ClientOption) (*StreamingVideoIntelligenceClient, error) { + clientOpts := defaultStreamingVideoIntelligenceGRPCClientOptions() + if newStreamingVideoIntelligenceClientHook != nil { + hookOpts, err := newStreamingVideoIntelligenceClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + client := StreamingVideoIntelligenceClient{CallOptions: defaultStreamingVideoIntelligenceCallOptions()} + + c := &streamingVideoIntelligenceGRPCClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + streamingVideoIntelligenceClient: videointelligencepb.NewStreamingVideoIntelligenceServiceClient(connPool), + CallOptions: &client.CallOptions, + } + c.setGoogleClientInfo() + + client.internalClient = c + + return &client, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *streamingVideoIntelligenceGRPCClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *streamingVideoIntelligenceGRPCClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *streamingVideoIntelligenceGRPCClient) Close() error { + return c.connPool.Close() +} + +func (c *streamingVideoIntelligenceGRPCClient) StreamingAnnotateVideo(ctx context.Context, opts ...gax.CallOption) (videointelligencepb.StreamingVideoIntelligenceService_StreamingAnnotateVideoClient, error) { + ctx = insertMetadata(ctx, c.xGoogMetadata) + var resp videointelligencepb.StreamingVideoIntelligenceService_StreamingAnnotateVideoClient + opts = append((*c.CallOptions).StreamingAnnotateVideo[0:len((*c.CallOptions).StreamingAnnotateVideo):len((*c.CallOptions).StreamingAnnotateVideo)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.streamingVideoIntelligenceClient.StreamingAnnotateVideo(ctx, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/videointelligence/apiv1p3beta1/streaming_video_intelligence_client_example_test.go b/videointelligence/apiv1p3beta1/streaming_video_intelligence_client_example_test.go new file mode 100644 index 000000000000..94b49ddc0dcf --- /dev/null +++ b/videointelligence/apiv1p3beta1/streaming_video_intelligence_client_example_test.go @@ -0,0 +1,72 @@ +// Copyright 2022 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 +// +// https://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. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package videointelligence_test + +import ( + "context" + "io" + + videointelligence "cloud.google.com/go/videointelligence/apiv1p3beta1" + videointelligencepb "google.golang.org/genproto/googleapis/cloud/videointelligence/v1p3beta1" +) + +func ExampleNewStreamingVideoIntelligenceClient() { + ctx := context.Background() + c, err := videointelligence.NewStreamingVideoIntelligenceClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleStreamingVideoIntelligenceClient_StreamingAnnotateVideo() { + ctx := context.Background() + c, err := videointelligence.NewStreamingVideoIntelligenceClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + stream, err := c.StreamingAnnotateVideo(ctx) + if err != nil { + // TODO: Handle error. + } + go func() { + reqs := []*videointelligencepb.StreamingAnnotateVideoRequest{ + // TODO: Create requests. + } + for _, req := range reqs { + if err := stream.Send(req); err != nil { + // TODO: Handle error. + } + } + stream.CloseSend() + }() + for { + resp, err := stream.Recv() + if err == io.EOF { + break + } + if err != nil { + // TODO: handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/videointelligence/apiv1p3beta1/version.go b/videointelligence/apiv1p3beta1/version.go new file mode 100644 index 000000000000..6b1c98b5a729 --- /dev/null +++ b/videointelligence/apiv1p3beta1/version.go @@ -0,0 +1,23 @@ +// Copyright 2022 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. + +// Code generated by gapicgen. DO NOT EDIT. + +package videointelligence + +import "cloud.google.com/go/videointelligence/internal" + +func init() { + versionClient = internal.Version +} diff --git a/videointelligence/apiv1p3beta1/video_intelligence_client.go b/videointelligence/apiv1p3beta1/video_intelligence_client.go new file mode 100644 index 000000000000..a001e1d788d1 --- /dev/null +++ b/videointelligence/apiv1p3beta1/video_intelligence_client.go @@ -0,0 +1,320 @@ +// Copyright 2022 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 +// +// https://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. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package videointelligence + +import ( + "context" + "math" + "time" + + "cloud.google.com/go/longrunning" + lroauto "cloud.google.com/go/longrunning/autogen" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + videointelligencepb "google.golang.org/genproto/googleapis/cloud/videointelligence/v1p3beta1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newClientHook clientHook + +// CallOptions contains the retry settings for each method of Client. +type CallOptions struct { + AnnotateVideo []gax.CallOption +} + +func defaultGRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("videointelligence.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("videointelligence.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://videointelligence.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultCallOptions() *CallOptions { + return &CallOptions{ + AnnotateVideo: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 120000 * time.Millisecond, + Multiplier: 2.50, + }) + }), + }, + } +} + +// internalClient is an interface that defines the methods availaible from Cloud Video Intelligence API. +type internalClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AnnotateVideo(context.Context, *videointelligencepb.AnnotateVideoRequest, ...gax.CallOption) (*AnnotateVideoOperation, error) + AnnotateVideoOperation(name string) *AnnotateVideoOperation +} + +// Client is a client for interacting with Cloud Video Intelligence API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// Service that implements the Video Intelligence API. +type Client struct { + // The internal transport-dependent client. + internalClient internalClient + + // The call options for this service. + CallOptions *CallOptions + + // LROClient is used internally to handle long-running operations. + // It is exposed so that its CallOptions can be modified if required. + // Users should not Close this client. + LROClient *lroauto.OperationsClient +} + +// Wrapper methods routed to the internal client. + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *Client) Close() error { + return c.internalClient.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *Client) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *Client) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AnnotateVideo 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). +func (c *Client) AnnotateVideo(ctx context.Context, req *videointelligencepb.AnnotateVideoRequest, opts ...gax.CallOption) (*AnnotateVideoOperation, error) { + return c.internalClient.AnnotateVideo(ctx, req, opts...) +} + +// AnnotateVideoOperation returns a new AnnotateVideoOperation from a given name. +// The name must be that of a previously created AnnotateVideoOperation, possibly from a different process. +func (c *Client) AnnotateVideoOperation(name string) *AnnotateVideoOperation { + return c.internalClient.AnnotateVideoOperation(name) +} + +// gRPCClient is a client for interacting with Cloud Video Intelligence API over gRPC transport. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type gRPCClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // Points back to the CallOptions field of the containing Client + CallOptions **CallOptions + + // The gRPC API client. + client videointelligencepb.VideoIntelligenceServiceClient + + // LROClient is used internally to handle long-running operations. + // It is exposed so that its CallOptions can be modified if required. + // Users should not Close this client. + LROClient **lroauto.OperationsClient + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewClient creates a new video intelligence service client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// Service that implements the Video Intelligence API. +func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { + clientOpts := defaultGRPCClientOptions() + if newClientHook != nil { + hookOpts, err := newClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + client := Client{CallOptions: defaultCallOptions()} + + c := &gRPCClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + client: videointelligencepb.NewVideoIntelligenceServiceClient(connPool), + CallOptions: &client.CallOptions, + } + c.setGoogleClientInfo() + + client.internalClient = c + + client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) + if err != nil { + // This error "should not happen", since we are just reusing old connection pool + // and never actually need to dial. + // If this does happen, we could leak connp. However, we cannot close conn: + // If the user invoked the constructor with option.WithGRPCConn, + // we would close a connection that's still in use. + // TODO: investigate error conditions. + return nil, err + } + c.LROClient = &client.LROClient + return &client, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *gRPCClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *gRPCClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *gRPCClient) Close() error { + return c.connPool.Close() +} + +func (c *gRPCClient) AnnotateVideo(ctx context.Context, req *videointelligencepb.AnnotateVideoRequest, opts ...gax.CallOption) (*AnnotateVideoOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).AnnotateVideo[0:len((*c.CallOptions).AnnotateVideo):len((*c.CallOptions).AnnotateVideo)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.AnnotateVideo(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &AnnotateVideoOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +// AnnotateVideoOperation manages a long-running operation from AnnotateVideo. +type AnnotateVideoOperation struct { + lro *longrunning.Operation +} + +// AnnotateVideoOperation returns a new AnnotateVideoOperation from a given name. +// The name must be that of a previously created AnnotateVideoOperation, possibly from a different process. +func (c *gRPCClient) AnnotateVideoOperation(name string) *AnnotateVideoOperation { + return &AnnotateVideoOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *AnnotateVideoOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*videointelligencepb.AnnotateVideoResponse, error) { + var resp videointelligencepb.AnnotateVideoResponse + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *AnnotateVideoOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*videointelligencepb.AnnotateVideoResponse, error) { + var resp videointelligencepb.AnnotateVideoResponse + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *AnnotateVideoOperation) Metadata() (*videointelligencepb.AnnotateVideoProgress, error) { + var meta videointelligencepb.AnnotateVideoProgress + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *AnnotateVideoOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *AnnotateVideoOperation) Name() string { + return op.lro.Name() +} diff --git a/videointelligence/apiv1p3beta1/video_intelligence_client_example_test.go b/videointelligence/apiv1p3beta1/video_intelligence_client_example_test.go new file mode 100644 index 000000000000..a6d055850d25 --- /dev/null +++ b/videointelligence/apiv1p3beta1/video_intelligence_client_example_test.go @@ -0,0 +1,61 @@ +// Copyright 2022 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 +// +// https://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. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package videointelligence_test + +import ( + "context" + + videointelligence "cloud.google.com/go/videointelligence/apiv1p3beta1" + videointelligencepb "google.golang.org/genproto/googleapis/cloud/videointelligence/v1p3beta1" +) + +func ExampleNewClient() { + ctx := context.Background() + c, err := videointelligence.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleClient_AnnotateVideo() { + ctx := context.Background() + c, err := videointelligence.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &videointelligencepb.AnnotateVideoRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/videointelligence/v1p3beta1#AnnotateVideoRequest. + } + op, err := c.AnnotateVideo(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +}