From 22186299c485135e9298c7cdba52580bf9dadee2 Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Thu, 6 Apr 2023 00:19:23 -0700 Subject: [PATCH] Internal change PiperOrigin-RevId: 522263621 --- .../util/clock_latency_calculator.cc | 8 ++--- ...collection_has_min_size_calculator_test.cc | 2 +- .../detection_label_id_to_text_calculator.cc | 9 ++--- ...ction_letterbox_removal_calculator_test.cc | 2 +- ...etection_transformation_calculator_test.cc | 4 +-- .../util/detection_unique_id_calculator.cc | 2 +- .../detections_to_rects_calculator_test.cc | 4 +-- ...tections_to_render_data_calculator_test.cc | 6 ++-- .../util/filter_collection_calculator.cc | 2 +- .../calculators/util/from_image_calculator.cc | 4 +-- .../util/packet_frequency_calculator.cc | 18 +++++----- .../util/packet_latency_calculator.cc | 36 +++++++++---------- .../util/packet_latency_calculator_test.cc | 6 ++-- 13 files changed, 53 insertions(+), 50 deletions(-) diff --git a/mediapipe/calculators/util/clock_latency_calculator.cc b/mediapipe/calculators/util/clock_latency_calculator.cc index 5c5711731..beaa41e66 100644 --- a/mediapipe/calculators/util/clock_latency_calculator.cc +++ b/mediapipe/calculators/util/clock_latency_calculator.cc @@ -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(); cc->Outputs().Index(i).Set(); } @@ -99,7 +99,7 @@ absl::Status ClockLatencyCalculator::Process(CalculatorContext* cc) { cc->Inputs().Tag(kReferenceTag).Get(); // 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(); diff --git a/mediapipe/calculators/util/collection_has_min_size_calculator_test.cc b/mediapipe/calculators/util/collection_has_min_size_calculator_test.cc index 62eb1d8ae..71cba9430 100644 --- a/mediapipe/calculators/util/collection_has_min_size_calculator_test.cc +++ b/mediapipe/calculators/util/collection_has_min_size_calculator_test.cc @@ -33,7 +33,7 @@ typedef CollectionHasMinSizeCalculator> TestIntCollectionHasMinSizeCalculator; REGISTER_CALCULATOR(TestIntCollectionHasMinSizeCalculator); -void AddInputVector(const std::vector& input, int64 timestamp, +void AddInputVector(const std::vector& input, int64_t timestamp, CalculatorRunner* runner) { runner->MutableInputs() ->Tag(kIterableTag) diff --git a/mediapipe/calculators/util/detection_label_id_to_text_calculator.cc b/mediapipe/calculators/util/detection_label_id_to_text_calculator.cc index 0b8dde20d..0c1d6892e 100644 --- a/mediapipe/calculators/util/detection_label_id_to_text_calculator.cc +++ b/mediapipe/calculators/util/detection_label_id_to_text_calculator.cc @@ -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 local_label_map_; + proto_ns::Map local_label_map_; bool keep_label_id_; - const proto_ns::Map& GetLabelMap(CalculatorContext* cc); + const proto_ns::Map& 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& +const proto_ns::Map& DetectionLabelIdToTextCalculator::GetLabelMap(CalculatorContext* cc) { return !local_label_map_.empty() ? local_label_map_ diff --git a/mediapipe/calculators/util/detection_letterbox_removal_calculator_test.cc b/mediapipe/calculators/util/detection_letterbox_removal_calculator_test.cc index c4f084363..75dd93cc3 100644 --- a/mediapipe/calculators/util/detection_letterbox_removal_calculator_test.cc +++ b/mediapipe/calculators/util/detection_letterbox_removal_calculator_test.cc @@ -40,7 +40,7 @@ LocationData CreateRelativeLocationData(double xmin, double ymin, double width, } Detection CreateDetection(const std::vector& labels, - const std::vector& label_ids, + const std::vector& label_ids, const std::vector& scores, const LocationData& location_data, const std::string& feature_tag) { diff --git a/mediapipe/calculators/util/detection_transformation_calculator_test.cc b/mediapipe/calculators/util/detection_transformation_calculator_test.cc index e280b5153..30d1bc64b 100644 --- a/mediapipe/calculators/util/detection_transformation_calculator_test.cc +++ b/mediapipe/calculators/util/detection_transformation_calculator_test.cc @@ -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); diff --git a/mediapipe/calculators/util/detection_unique_id_calculator.cc b/mediapipe/calculators/util/detection_unique_id_calculator.cc index ac8889ffb..d5b1cffa3 100644 --- a/mediapipe/calculators/util/detection_unique_id_calculator.cc +++ b/mediapipe/calculators/util/detection_unique_id_calculator.cc @@ -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; } diff --git a/mediapipe/calculators/util/detections_to_rects_calculator_test.cc b/mediapipe/calculators/util/detections_to_rects_calculator_test.cc index 63de60a60..95e18e90c 100644 --- a/mediapipe/calculators/util/detections_to_rects_calculator_test.cc +++ b/mediapipe/calculators/util/detections_to_rects_calculator_test.cc @@ -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); diff --git a/mediapipe/calculators/util/detections_to_render_data_calculator_test.cc b/mediapipe/calculators/util/detections_to_render_data_calculator_test.cc index 0d0da2350..6da8c449a 100644 --- a/mediapipe/calculators/util/detections_to_render_data_calculator_test.cc +++ b/mediapipe/calculators/util/detections_to_render_data_calculator_test.cc @@ -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& labels, - const std::vector& label_ids, + const std::vector& label_ids, const std::vector& scores, const LocationData& location_data, const std::string& feature_tag) { diff --git a/mediapipe/calculators/util/filter_collection_calculator.cc b/mediapipe/calculators/util/filter_collection_calculator.cc index ab361f450..2cf41ead8 100644 --- a/mediapipe/calculators/util/filter_collection_calculator.cc +++ b/mediapipe/calculators/util/filter_collection_calculator.cc @@ -24,7 +24,7 @@ namespace mediapipe { -typedef FilterCollectionCalculator> +typedef FilterCollectionCalculator> FilterUInt64CollectionCalculator; REGISTER_CALCULATOR(FilterUInt64CollectionCalculator); diff --git a/mediapipe/calculators/util/from_image_calculator.cc b/mediapipe/calculators/util/from_image_calculator.cc index 0ddb342eb..706f8727b 100644 --- a/mediapipe/calculators/util/from_image_calculator.cc +++ b/mediapipe/calculators/util/from_image_calculator.cc @@ -163,8 +163,8 @@ absl::Status FromImageCalculator::Process(CalculatorContext* cc) { std::unique_ptr output = std::make_unique( input.image_format(), input.width(), input.height(), input.step(), - const_cast(input.GetImageFrameSharedPtr()->PixelData()), - [packet_copy_ptr](uint8*) { delete packet_copy_ptr; }); + const_cast(input.GetImageFrameSharedPtr()->PixelData()), + [packet_copy_ptr](uint8_t*) { delete packet_copy_ptr; }); cc->Outputs() .Tag(kImageFrameTag) .Add(output.release(), cc->InputTimestamp()); diff --git a/mediapipe/calculators/util/packet_frequency_calculator.cc b/mediapipe/calculators/util/packet_frequency_calculator.cc index 19ffae70e..f9c28f5ff 100644 --- a/mediapipe/calculators/util/packet_frequency_calculator.cc +++ b/mediapipe/calculators/util/packet_frequency_calculator.cc @@ -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 first_timestamp_for_stream_id_usec_; + std::map 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> previous_timestamps_for_stream_id_; + std::map> 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, - ¤t_timestamp_usec](const int64 timestamp_usec) { + ¤t_timestamp_usec](const int64_t timestamp_usec) { return current_timestamp_usec - timestamp_usec > time_window_usec; }), diff --git a/mediapipe/calculators/util/packet_latency_calculator.cc b/mediapipe/calculators/util/packet_latency_calculator.cc index 0e5b2e885..6509f016f 100644 --- a/mediapipe/calculators/util/packet_latency_calculator.cc +++ b/mediapipe/calculators/util/packet_latency_calculator.cc @@ -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 packet_latencies_; // Running sum and count of latencies for each packet stream. This is required // to compute the average latency. - std::vector sum_latencies_usec_; - std::vector num_latencies_; + std::vector sum_latencies_usec_; + std::vector 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(); } @@ -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; diff --git a/mediapipe/calculators/util/packet_latency_calculator_test.cc b/mediapipe/calculators/util/packet_latency_calculator_test.cc index 6f03f2e75..d323a14f9 100644 --- a/mediapipe/calculators/util/packet_latency_calculator_test.cc +++ b/mediapipe/calculators/util/packet_latency_calculator_test.cc @@ -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& 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);