Internal change

PiperOrigin-RevId: 522263621
This commit is contained in:
MediaPipe Team 2023-04-06 00:19:23 -07:00 committed by Copybara-Service
parent d05508cb7b
commit 22186299c4
13 changed files with 53 additions and 50 deletions

View File

@ -66,17 +66,17 @@ class ClockLatencyCalculator : public CalculatorBase {
absl::Status Process(CalculatorContext* cc) override;
private:
int64 num_packet_streams_ = -1;
int64_t num_packet_streams_ = -1;
};
REGISTER_CALCULATOR(ClockLatencyCalculator);
absl::Status ClockLatencyCalculator::GetContract(CalculatorContract* cc) {
RET_CHECK_GT(cc->Inputs().NumEntries(), 1);
int64 num_packet_streams = cc->Inputs().NumEntries() - 1;
int64_t num_packet_streams = cc->Inputs().NumEntries() - 1;
RET_CHECK_EQ(cc->Outputs().NumEntries(), num_packet_streams);
for (int64 i = 0; i < num_packet_streams; ++i) {
for (int64_t i = 0; i < num_packet_streams; ++i) {
cc->Inputs().Index(i).Set<absl::Time>();
cc->Outputs().Index(i).Set<absl::Duration>();
}
@ -99,7 +99,7 @@ absl::Status ClockLatencyCalculator::Process(CalculatorContext* cc) {
cc->Inputs().Tag(kReferenceTag).Get<absl::Time>();
// Push Duration packets for every input stream we have.
for (int64 i = 0; i < num_packet_streams_; ++i) {
for (int64_t i = 0; i < num_packet_streams_; ++i) {
if (!cc->Inputs().Index(i).IsEmpty()) {
const absl::Time& input_stream_time =
cc->Inputs().Index(i).Get<absl::Time>();

View File

@ -33,7 +33,7 @@ typedef CollectionHasMinSizeCalculator<std::vector<int>>
TestIntCollectionHasMinSizeCalculator;
REGISTER_CALCULATOR(TestIntCollectionHasMinSizeCalculator);
void AddInputVector(const std::vector<int>& input, int64 timestamp,
void AddInputVector(const std::vector<int>& input, int64_t timestamp,
CalculatorRunner* runner) {
runner->MutableInputs()
->Tag(kIterableTag)

View File

@ -57,9 +57,10 @@ class DetectionLabelIdToTextCalculator : public CalculatorBase {
private:
// Local label map built from the calculator options' `label_map_path` or
// `label` field.
proto_ns::Map<int64, LabelMapItem> local_label_map_;
proto_ns::Map<int64_t, LabelMapItem> local_label_map_;
bool keep_label_id_;
const proto_ns::Map<int64, LabelMapItem>& GetLabelMap(CalculatorContext* cc);
const proto_ns::Map<int64_t, LabelMapItem>& GetLabelMap(
CalculatorContext* cc);
};
REGISTER_CALCULATOR(DetectionLabelIdToTextCalculator);
@ -115,7 +116,7 @@ absl::Status DetectionLabelIdToTextCalculator::Process(CalculatorContext* cc) {
output_detections.push_back(input_detection);
Detection& output_detection = output_detections.back();
bool has_text_label = false;
for (const int32 label_id : output_detection.label_id()) {
for (const int32_t label_id : output_detection.label_id()) {
if (GetLabelMap(cc).contains(label_id)) {
auto item = GetLabelMap(cc).at(label_id);
output_detection.add_label(item.name());
@ -136,7 +137,7 @@ absl::Status DetectionLabelIdToTextCalculator::Process(CalculatorContext* cc) {
return absl::OkStatus();
}
const proto_ns::Map<int64, LabelMapItem>&
const proto_ns::Map<int64_t, LabelMapItem>&
DetectionLabelIdToTextCalculator::GetLabelMap(CalculatorContext* cc) {
return !local_label_map_.empty()
? local_label_map_

View File

@ -40,7 +40,7 @@ LocationData CreateRelativeLocationData(double xmin, double ymin, double width,
}
Detection CreateDetection(const std::vector<std::string>& labels,
const std::vector<int32>& label_ids,
const std::vector<int32_t>& label_ids,
const std::vector<float>& scores,
const LocationData& location_data,
const std::string& feature_tag) {

View File

@ -39,8 +39,8 @@ constexpr char kPixelDetectionsTag[] = "PIXEL_DETECTIONS";
constexpr char kRelativeDetectionListTag[] = "RELATIVE_DETECTION_LIST";
constexpr char kRelativeDetectionsTag[] = "RELATIVE_DETECTIONS";
Detection DetectionWithBoundingBox(int32 xmin, int32 ymin, int32 width,
int32 height) {
Detection DetectionWithBoundingBox(int32_t xmin, int32_t ymin, int32_t width,
int32_t height) {
Detection detection;
LocationData* location_data = detection.mutable_location_data();
location_data->set_format(LocationData::BOUNDING_BOX);

View File

@ -26,7 +26,7 @@ constexpr char kDetectionListTag[] = "DETECTION_LIST";
// Each detection processed by DetectionUniqueIDCalculator will be assigned an
// unique id that starts from 1. If a detection already has an ID other than 0,
// the ID will be overwritten.
static int64 detection_id = 0;
static int64_t detection_id = 0;
inline int GetNextDetectionId() { return ++detection_id; }

View File

@ -56,8 +56,8 @@ MATCHER_P4(NormRectEq, x_center, y_center, width, height, "") {
testing::Value(arg.height(), testing::FloatEq(height));
}
Detection DetectionWithLocationData(int32 xmin, int32 ymin, int32 width,
int32 height) {
Detection DetectionWithLocationData(int32_t xmin, int32_t ymin, int32_t width,
int32_t height) {
Detection detection;
LocationData* location_data = detection.mutable_location_data();
location_data->set_format(LocationData::BOUNDING_BOX);

View File

@ -43,8 +43,8 @@ void VerifyRenderAnnotationColorThickness(
EXPECT_EQ(annotation.thickness(), options.thickness());
}
LocationData CreateLocationData(int32 xmin, int32 ymin, int32 width,
int32 height) {
LocationData CreateLocationData(int32_t xmin, int32_t ymin, int32_t width,
int32_t height) {
LocationData location_data;
location_data.set_format(LocationData::BOUNDING_BOX);
location_data.mutable_bounding_box()->set_xmin(xmin);
@ -66,7 +66,7 @@ LocationData CreateRelativeLocationData(double xmin, double ymin, double width,
}
Detection CreateDetection(const std::vector<std::string>& labels,
const std::vector<int32>& label_ids,
const std::vector<int32_t>& label_ids,
const std::vector<float>& scores,
const LocationData& location_data,
const std::string& feature_tag) {

View File

@ -24,7 +24,7 @@
namespace mediapipe {
typedef FilterCollectionCalculator<std::vector<uint64>>
typedef FilterCollectionCalculator<std::vector<uint64_t>>
FilterUInt64CollectionCalculator;
REGISTER_CALCULATOR(FilterUInt64CollectionCalculator);

View File

@ -163,8 +163,8 @@ absl::Status FromImageCalculator::Process(CalculatorContext* cc) {
std::unique_ptr<mediapipe::ImageFrame> output =
std::make_unique<mediapipe::ImageFrame>(
input.image_format(), input.width(), input.height(), input.step(),
const_cast<uint8*>(input.GetImageFrameSharedPtr()->PixelData()),
[packet_copy_ptr](uint8*) { delete packet_copy_ptr; });
const_cast<uint8_t*>(input.GetImageFrameSharedPtr()->PixelData()),
[packet_copy_ptr](uint8_t*) { delete packet_copy_ptr; });
cc->Outputs()
.Tag(kImageFrameTag)
.Add(output.release(), cc->InputTimestamp());

View File

@ -84,23 +84,24 @@ class PacketFrequencyCalculator : public CalculatorBase {
const Timestamp& input_timestamp);
// Adds the input timestamp in the particular stream's timestamp buffer.
absl::Status AddPacketTimestampForStream(int stream_id, int64 timestamp);
absl::Status AddPacketTimestampForStream(int stream_id, int64_t timestamp);
// For the specified input stream, clears timestamps from buffer that are
// older than the configured time_window_sec.
absl::Status ClearOldpacketTimestamps(int stream_id, int64 current_timestamp);
absl::Status ClearOldpacketTimestamps(int stream_id,
int64_t current_timestamp);
// Options for the calculator.
PacketFrequencyCalculatorOptions options_;
// Map where key is the input stream ID and value is the timestamp of the
// first packet received on that stream.
std::map<int, int64> first_timestamp_for_stream_id_usec_;
std::map<int, int64_t> first_timestamp_for_stream_id_usec_;
// Map where key is the input stream ID and value is a vector that stores
// timestamps of recently received packets on the stream. Timestamps older
// than the time_window_sec are continuously deleted for all the streams.
std::map<int, std::vector<int64>> previous_timestamps_for_stream_id_;
std::map<int, std::vector<int64_t>> previous_timestamps_for_stream_id_;
};
REGISTER_CALCULATOR(PacketFrequencyCalculator);
@ -166,7 +167,7 @@ absl::Status PacketFrequencyCalculator::Process(CalculatorContext* cc) {
}
absl::Status PacketFrequencyCalculator::AddPacketTimestampForStream(
int stream_id, int64 timestamp_usec) {
int stream_id, int64_t timestamp_usec) {
if (previous_timestamps_for_stream_id_.find(stream_id) ==
previous_timestamps_for_stream_id_.end()) {
return absl::InvalidArgumentError("Input stream id is invalid");
@ -178,19 +179,20 @@ absl::Status PacketFrequencyCalculator::AddPacketTimestampForStream(
}
absl::Status PacketFrequencyCalculator::ClearOldpacketTimestamps(
int stream_id, int64 current_timestamp_usec) {
int stream_id, int64_t current_timestamp_usec) {
if (previous_timestamps_for_stream_id_.find(stream_id) ==
previous_timestamps_for_stream_id_.end()) {
return absl::InvalidArgumentError("Input stream id is invalid");
}
auto& timestamps_buffer = previous_timestamps_for_stream_id_[stream_id];
int64 time_window_usec = options_.time_window_sec() * kSecondsToMicroseconds;
int64_t time_window_usec =
options_.time_window_sec() * kSecondsToMicroseconds;
timestamps_buffer.erase(
std::remove_if(timestamps_buffer.begin(), timestamps_buffer.end(),
[&time_window_usec,
&current_timestamp_usec](const int64 timestamp_usec) {
&current_timestamp_usec](const int64_t timestamp_usec) {
return current_timestamp_usec - timestamp_usec >
time_window_usec;
}),

View File

@ -118,24 +118,24 @@ class PacketLatencyCalculator : public CalculatorBase {
std::shared_ptr<::mediapipe::Clock> clock_;
// Clock time when the first reference packet was received.
int64 first_process_time_usec_ = -1;
int64_t first_process_time_usec_ = -1;
// Timestamp of the first reference packet received.
int64 first_reference_timestamp_usec_ = -1;
int64_t first_reference_timestamp_usec_ = -1;
// Number of packet streams.
int64 num_packet_streams_ = -1;
int64_t num_packet_streams_ = -1;
// Latency output for each packet stream.
std::vector<PacketLatency> packet_latencies_;
// Running sum and count of latencies for each packet stream. This is required
// to compute the average latency.
std::vector<int64> sum_latencies_usec_;
std::vector<int64> num_latencies_;
std::vector<int64_t> sum_latencies_usec_;
std::vector<int64_t> num_latencies_;
// Clock time when last reset was done for histogram and running average.
int64 last_reset_time_usec_ = -1;
int64_t last_reset_time_usec_ = -1;
};
REGISTER_CALCULATOR(PacketLatencyCalculator);
@ -143,9 +143,9 @@ absl::Status PacketLatencyCalculator::GetContract(CalculatorContract* cc) {
RET_CHECK_GT(cc->Inputs().NumEntries(), 1);
// Input and output streams.
int64 num_packet_streams = cc->Inputs().NumEntries() - 1;
int64_t num_packet_streams = cc->Inputs().NumEntries() - 1;
RET_CHECK_EQ(cc->Outputs().NumEntries(), num_packet_streams);
for (int64 i = 0; i < num_packet_streams; ++i) {
for (int64_t i = 0; i < num_packet_streams; ++i) {
cc->Inputs().Index(i).SetAny();
cc->Outputs().Index(i).Set<PacketLatency>();
}
@ -165,8 +165,8 @@ absl::Status PacketLatencyCalculator::GetContract(CalculatorContract* cc) {
void PacketLatencyCalculator::ResetStatistics() {
// Initialize histogram with zero counts and set running average to zero.
for (int64 i = 0; i < num_packet_streams_; ++i) {
for (int64 interval_index = 0; interval_index < options_.num_intervals();
for (int64_t i = 0; i < num_packet_streams_; ++i) {
for (int64_t interval_index = 0; interval_index < options_.num_intervals();
++interval_index) {
packet_latencies_[i].set_counts(interval_index, 0);
}
@ -196,7 +196,7 @@ absl::Status PacketLatencyCalculator::Open(CalculatorContext* cc) {
packet_latencies_.resize(num_packet_streams_);
sum_latencies_usec_.resize(num_packet_streams_);
num_latencies_.resize(num_packet_streams_);
for (int64 i = 0; i < num_packet_streams_; ++i) {
for (int64_t i = 0; i < num_packet_streams_; ++i) {
// Initialize latency histograms with zero counts.
packet_latencies_[i].set_num_intervals(options_.num_intervals());
packet_latencies_[i].set_interval_size_usec(options_.interval_size_usec());
@ -208,7 +208,7 @@ absl::Status PacketLatencyCalculator::Open(CalculatorContext* cc) {
if (labels_provided) {
packet_latencies_[i].set_label(options_.packet_labels(i));
} else {
int64 input_stream_index = cc->Inputs().TagMap()->GetId("", i).value();
int64_t input_stream_index = cc->Inputs().TagMap()->GetId("", i).value();
packet_latencies_[i].set_label(
cc->Inputs().TagMap()->Names()[input_stream_index]);
}
@ -242,7 +242,7 @@ absl::Status PacketLatencyCalculator::Process(CalculatorContext* cc) {
}
if (options_.reset_duration_usec() > 0) {
const int64 time_now_usec = absl::ToUnixMicros(clock_->TimeNow());
const int64_t time_now_usec = absl::ToUnixMicros(clock_->TimeNow());
if (time_now_usec - last_reset_time_usec_ >=
options_.reset_duration_usec()) {
ResetStatistics();
@ -251,16 +251,16 @@ absl::Status PacketLatencyCalculator::Process(CalculatorContext* cc) {
}
// Update latency info if there is any incoming packet.
for (int64 i = 0; i < num_packet_streams_; ++i) {
for (int64_t i = 0; i < num_packet_streams_; ++i) {
if (!cc->Inputs().Index(i).IsEmpty()) {
const auto& packet_timestamp_usec = cc->InputTimestamp().Value();
// Update latency statistics for this stream.
int64 current_clock_time_usec = absl::ToUnixMicros(clock_->TimeNow());
int64 current_calibrated_timestamp_usec =
int64_t current_clock_time_usec = absl::ToUnixMicros(clock_->TimeNow());
int64_t current_calibrated_timestamp_usec =
(current_clock_time_usec - first_process_time_usec_) +
first_reference_timestamp_usec_;
int64 packet_latency_usec =
int64_t packet_latency_usec =
current_calibrated_timestamp_usec - packet_timestamp_usec;
// Invalid timestamps in input signals could result in negative latencies.
@ -270,7 +270,7 @@ absl::Status PacketLatencyCalculator::Process(CalculatorContext* cc) {
// Update the latency, running average and histogram for this stream.
packet_latencies_[i].set_current_latency_usec(packet_latency_usec);
int64 interval_index =
int64_t interval_index =
packet_latency_usec / packet_latencies_[i].interval_size_usec();
if (interval_index >= packet_latencies_[i].num_intervals()) {
interval_index = packet_latencies_[i].num_intervals() - 1;

View File

@ -169,10 +169,10 @@ class PacketLatencyCalculatorTest : public ::testing::Test {
}
PacketLatency CreatePacketLatency(const double latency_usec,
const int64 num_intervals,
const int64 interval_size_usec,
const int64_t num_intervals,
const int64_t interval_size_usec,
const std::vector<int>& counts,
const int64 avg_latency_usec,
const int64_t avg_latency_usec,
const std::string& label) {
PacketLatency latency_info;
latency_info.set_current_latency_usec(latency_usec);