67 lines
2.5 KiB
C++
67 lines
2.5 KiB
C++
#include "google/cloudai/video_intelligence.h"
|
|||
|
|
|
||
|
|
#include "google/cloudai/caps.h"
|
||
|
|
#include "google/errors.h"
|
||
|
|
|
||
|
|
namespace molo::google::cloudai {
|
||
|
|
|
||
|
|
using clients::body::Json;
|
||
|
|
|
||
|
|
Json VideoIntelligence::annotate_body(const VideoRequest& r) const {
|
||
|
|
if (r.features.empty() || r.features.size() > 9) throw GoogleError::invalid("features: 1..9 required");
|
||
|
|
Json feats = Json::array();
|
||
|
|
for (const auto& f : r.features) {
|
||
|
|
if (!valid_enum("GoogleCloudVideointelligenceV1_AnnotateVideoRequest.features", f))
|
||
|
|
throw GoogleError::invalid("unknown video feature " + f);
|
||
|
|
feats.push(Json(f));
|
||
|
|
}
|
||
|
|
Json b = Json::object();
|
||
|
|
if (!r.input_uri.empty()) {
|
||
|
|
if (!r.input_content_base64.empty()) throw GoogleError::invalid("give inputUri or content, not both");
|
||
|
|
b.set("inputUri", Json(checked_gcs_uri(r.input_uri, "inputUri")));
|
||
|
|
} else {
|
||
|
|
if (r.input_content_base64.empty()) throw GoogleError::invalid("inputUri or content is required");
|
||
|
|
if (r.input_content_base64.size() / 4 * 3 > CloudAiCaps::kMaxAudioBytes)
|
||
|
|
throw GoogleError::invalid("inline video over 10 MiB");
|
||
|
|
b.set("inputContent", Json(r.input_content_base64));
|
||
|
|
}
|
||
|
|
b.set("features", feats);
|
||
|
|
if (!r.output_uri.empty()) b.set("outputUri", Json(checked_gcs_uri(r.output_uri, "outputUri")));
|
||
|
|
if (!r.location_id.empty()) {
|
||
|
|
for (const char* ok : {"us-east1", "us-west1", "europe-west1", "asia-east1"})
|
||
|
|
if (r.location_id == ok) {
|
||
|
|
b.set("locationId", Json(r.location_id));
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
if (!b.find("locationId")) throw GoogleError::invalid("locationId must be us-east1, us-west1, europe-west1 or asia-east1");
|
||
|
|
}
|
||
|
|
return b;
|
||
|
|
}
|
||
|
|
|
||
|
|
Operation VideoIntelligence::annotate_start(const VideoRequest& r) const {
|
||
|
|
Json b = annotate_body(r);
|
||
|
|
return start(Call::kVideoVideosAnnotate, "", &b);
|
||
|
|
}
|
||
|
|
|
||
|
|
Operation VideoIntelligence::get_operation(const std::string& name) const {
|
||
|
|
return operation(Call::kVideoLocationsOperationsGet, name);
|
||
|
|
}
|
||
|
|
|
||
|
|
Json VideoIntelligence::list_operations(const std::string& filter) const {
|
||
|
|
Query q;
|
||
|
|
if (!filter.empty()) q.emplace_back("filter", filter);
|
||
|
|
return list(Call::kVideoLocationsOperationsList, parent(), "operations", q);
|
||
|
|
}
|
||
|
|
|
||
|
|
void VideoIntelligence::cancel_operation(const std::string& name) const {
|
||
|
|
invoke(Call::kVideoLocationsOperationsCancel, name);
|
||
|
|
}
|
||
|
|
void VideoIntelligence::delete_operation(const std::string& name) const {
|
||
|
|
invoke(Call::kVideoLocationsOperationsDelete, name);
|
||
|
|
}
|
||
|
|
Operation VideoIntelligence::wait_operation_done(const std::string& name) const {
|
||
|
|
return wait(Call::kVideoLocationsOperationsGet, name);
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace molo::google::cloudai
|