1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package rekognition
4
5import (
6	"context"
7	"fmt"
8	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
10	"github.com/aws/aws-sdk-go-v2/service/rekognition/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Gets the label detection results of a Amazon Rekognition Video analysis started
16// by StartLabelDetection. The label detection operation is started by a call to
17// StartLabelDetection which returns a job identifier (JobId). When the label
18// detection operation finishes, Amazon Rekognition publishes a completion status
19// to the Amazon Simple Notification Service topic registered in the initial call
20// to StartlabelDetection. To get the results of the label detection operation,
21// first check that the status value published to the Amazon SNS topic is
22// SUCCEEDED. If so, call GetLabelDetection and pass the job identifier (JobId)
23// from the initial call to StartLabelDetection. GetLabelDetection returns an array
24// of detected labels (Labels) sorted by the time the labels were detected. You can
25// also sort by the label name by specifying NAME for the SortBy input parameter.
26// The labels returned include the label name, the percentage confidence in the
27// accuracy of the detected label, and the time the label was detected in the
28// video. The returned labels also include bounding box information for common
29// objects, a hierarchical taxonomy of detected labels, and the version of the
30// label model used for detection. Use MaxResults parameter to limit the number of
31// labels returned. If there are more results than specified in MaxResults, the
32// value of NextToken in the operation response contains a pagination token for
33// getting the next set of results. To get the next page of results, call
34// GetlabelDetection and populate the NextToken request parameter with the token
35// value returned from the previous call to GetLabelDetection.
36func (c *Client) GetLabelDetection(ctx context.Context, params *GetLabelDetectionInput, optFns ...func(*Options)) (*GetLabelDetectionOutput, error) {
37	if params == nil {
38		params = &GetLabelDetectionInput{}
39	}
40
41	result, metadata, err := c.invokeOperation(ctx, "GetLabelDetection", params, optFns, addOperationGetLabelDetectionMiddlewares)
42	if err != nil {
43		return nil, err
44	}
45
46	out := result.(*GetLabelDetectionOutput)
47	out.ResultMetadata = metadata
48	return out, nil
49}
50
51type GetLabelDetectionInput struct {
52
53	// Job identifier for the label detection operation for which you want results
54	// returned. You get the job identifer from an initial call to StartlabelDetection.
55	//
56	// This member is required.
57	JobId *string
58
59	// Maximum number of results to return per paginated call. The largest value you
60	// can specify is 1000. If you specify a value greater than 1000, a maximum of 1000
61	// results is returned. The default value is 1000.
62	MaxResults *int32
63
64	// If the previous response was incomplete (because there are more labels to
65	// retrieve), Amazon Rekognition Video returns a pagination token in the response.
66	// You can use this pagination token to retrieve the next set of labels.
67	NextToken *string
68
69	// Sort to use for elements in the Labels array. Use TIMESTAMP to sort array
70	// elements by the time labels are detected. Use NAME to alphabetically group
71	// elements for a label together. Within each label group, the array element are
72	// sorted by detection confidence. The default sort is by TIMESTAMP.
73	SortBy types.LabelDetectionSortBy
74}
75
76type GetLabelDetectionOutput struct {
77
78	// The current status of the label detection job.
79	JobStatus types.VideoJobStatus
80
81	// Version number of the label detection model that was used to detect labels.
82	LabelModelVersion *string
83
84	// An array of labels detected in the video. Each element contains the detected
85	// label and the time, in milliseconds from the start of the video, that the label
86	// was detected.
87	Labels []types.LabelDetection
88
89	// If the response is truncated, Amazon Rekognition Video returns this token that
90	// you can use in the subsequent request to retrieve the next set of labels.
91	NextToken *string
92
93	// If the job fails, StatusMessage provides a descriptive error message.
94	StatusMessage *string
95
96	// Information about a video that Amazon Rekognition Video analyzed. Videometadata
97	// is returned in every page of paginated responses from a Amazon Rekognition video
98	// operation.
99	VideoMetadata *types.VideoMetadata
100
101	// Metadata pertaining to the operation's result.
102	ResultMetadata middleware.Metadata
103}
104
105func addOperationGetLabelDetectionMiddlewares(stack *middleware.Stack, options Options) (err error) {
106	err = stack.Serialize.Add(&awsAwsjson11_serializeOpGetLabelDetection{}, middleware.After)
107	if err != nil {
108		return err
109	}
110	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpGetLabelDetection{}, middleware.After)
111	if err != nil {
112		return err
113	}
114	if err = addSetLoggerMiddleware(stack, options); err != nil {
115		return err
116	}
117	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
118		return err
119	}
120	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
121		return err
122	}
123	if err = addResolveEndpointMiddleware(stack, options); err != nil {
124		return err
125	}
126	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
127		return err
128	}
129	if err = addRetryMiddlewares(stack, options); err != nil {
130		return err
131	}
132	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
133		return err
134	}
135	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
136		return err
137	}
138	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
139		return err
140	}
141	if err = addClientUserAgent(stack); err != nil {
142		return err
143	}
144	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
145		return err
146	}
147	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
148		return err
149	}
150	if err = addOpGetLabelDetectionValidationMiddleware(stack); err != nil {
151		return err
152	}
153	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetLabelDetection(options.Region), middleware.Before); err != nil {
154		return err
155	}
156	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
157		return err
158	}
159	if err = addResponseErrorMiddleware(stack); err != nil {
160		return err
161	}
162	if err = addRequestResponseLogging(stack, options); err != nil {
163		return err
164	}
165	return nil
166}
167
168// GetLabelDetectionAPIClient is a client that implements the GetLabelDetection
169// operation.
170type GetLabelDetectionAPIClient interface {
171	GetLabelDetection(context.Context, *GetLabelDetectionInput, ...func(*Options)) (*GetLabelDetectionOutput, error)
172}
173
174var _ GetLabelDetectionAPIClient = (*Client)(nil)
175
176// GetLabelDetectionPaginatorOptions is the paginator options for GetLabelDetection
177type GetLabelDetectionPaginatorOptions struct {
178	// Maximum number of results to return per paginated call. The largest value you
179	// can specify is 1000. If you specify a value greater than 1000, a maximum of 1000
180	// results is returned. The default value is 1000.
181	Limit int32
182
183	// Set to true if pagination should stop if the service returns a pagination token
184	// that matches the most recent token provided to the service.
185	StopOnDuplicateToken bool
186}
187
188// GetLabelDetectionPaginator is a paginator for GetLabelDetection
189type GetLabelDetectionPaginator struct {
190	options   GetLabelDetectionPaginatorOptions
191	client    GetLabelDetectionAPIClient
192	params    *GetLabelDetectionInput
193	nextToken *string
194	firstPage bool
195}
196
197// NewGetLabelDetectionPaginator returns a new GetLabelDetectionPaginator
198func NewGetLabelDetectionPaginator(client GetLabelDetectionAPIClient, params *GetLabelDetectionInput, optFns ...func(*GetLabelDetectionPaginatorOptions)) *GetLabelDetectionPaginator {
199	if params == nil {
200		params = &GetLabelDetectionInput{}
201	}
202
203	options := GetLabelDetectionPaginatorOptions{}
204	if params.MaxResults != nil {
205		options.Limit = *params.MaxResults
206	}
207
208	for _, fn := range optFns {
209		fn(&options)
210	}
211
212	return &GetLabelDetectionPaginator{
213		options:   options,
214		client:    client,
215		params:    params,
216		firstPage: true,
217	}
218}
219
220// HasMorePages returns a boolean indicating whether more pages are available
221func (p *GetLabelDetectionPaginator) HasMorePages() bool {
222	return p.firstPage || p.nextToken != nil
223}
224
225// NextPage retrieves the next GetLabelDetection page.
226func (p *GetLabelDetectionPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*GetLabelDetectionOutput, error) {
227	if !p.HasMorePages() {
228		return nil, fmt.Errorf("no more pages available")
229	}
230
231	params := *p.params
232	params.NextToken = p.nextToken
233
234	var limit *int32
235	if p.options.Limit > 0 {
236		limit = &p.options.Limit
237	}
238	params.MaxResults = limit
239
240	result, err := p.client.GetLabelDetection(ctx, &params, optFns...)
241	if err != nil {
242		return nil, err
243	}
244	p.firstPage = false
245
246	prevToken := p.nextToken
247	p.nextToken = result.NextToken
248
249	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
250		p.nextToken = nil
251	}
252
253	return result, nil
254}
255
256func newServiceMetadataMiddleware_opGetLabelDetection(region string) *awsmiddleware.RegisterServiceMetadata {
257	return &awsmiddleware.RegisterServiceMetadata{
258		Region:        region,
259		ServiceID:     ServiceID,
260		SigningName:   "rekognition",
261		OperationName: "GetLabelDetection",
262	}
263}
264