No public description

PiperOrigin-RevId: 595039397
This commit is contained in:
Dmitri Gribenko 2024-01-01 23:58:56 -08:00 committed by Copybara-Service
parent e23fa531e1
commit ec43bea176
18 changed files with 103 additions and 95 deletions

View File

@ -43,9 +43,9 @@ class KinematicPathSolver {
initialized_(false), initialized_(false),
pixels_per_degree_(pixels_per_degree) {} pixels_per_degree_(pixels_per_degree) {}
// Add an observation (detection) at a position and time. // Add an observation (detection) at a position and time.
absl::Status AddObservation(int position, const uint64 time_us); absl::Status AddObservation(int position, const uint64_t time_us);
// Get the predicted position at a time. // Get the predicted position at a time.
absl::Status UpdatePrediction(const int64 time_us); absl::Status UpdatePrediction(const int64_t time_us);
// Get the state at a time, as an int. // Get the state at a time, as an int.
absl::Status GetState(int* position); absl::Status GetState(int* position);
// Get the state at a time, as a float. // Get the state at a time, as a float.
@ -63,7 +63,7 @@ class KinematicPathSolver {
bool IsMotionTooSmall(double delta_degs); bool IsMotionTooSmall(double delta_degs);
// Check if a position measurement will cause the camera to be in motion // Check if a position measurement will cause the camera to be in motion
// without updating the internal state. // without updating the internal state.
absl::Status PredictMotionState(int position, const uint64 time_us, absl::Status PredictMotionState(int position, const uint64_t time_us,
bool* state); bool* state);
// Clear any history buffer of positions that are used when // Clear any history buffer of positions that are used when
// filtering_time_window_us is set to a non-zero value. // filtering_time_window_us is set to a non-zero value.
@ -85,9 +85,9 @@ class KinematicPathSolver {
double current_position_px_; double current_position_px_;
double prior_position_px_; double prior_position_px_;
double current_velocity_deg_per_s_; double current_velocity_deg_per_s_;
uint64 current_time_ = 0; uint64_t current_time_ = 0;
// History of observations (second) and their time (first). // History of observations (second) and their time (first).
std::deque<std::pair<uint64, int>> raw_positions_at_time_; std::deque<std::pair<uint64_t, int>> raw_positions_at_time_;
// Current target position. // Current target position.
double target_position_px_; double target_position_px_;
// Defines if the camera is moving to a target (true) or reached a target // Defines if the camera is moving to a target (true) or reached a target

View File

@ -67,7 +67,7 @@ class SceneCameraMotionAnalyzer {
const KeyFrameCropOptions& key_frame_crop_options, const KeyFrameCropOptions& key_frame_crop_options,
const std::vector<KeyFrameCropResult>& key_frame_crop_results, const std::vector<KeyFrameCropResult>& key_frame_crop_results,
const int scene_frame_width, const int scene_frame_height, const int scene_frame_width, const int scene_frame_height,
const std::vector<int64>& scene_frame_timestamps, const std::vector<int64_t>& scene_frame_timestamps,
const bool has_solid_color_background, const bool has_solid_color_background,
SceneKeyFrameCropSummary* scene_summary, SceneKeyFrameCropSummary* scene_summary,
std::vector<FocusPointFrame>* focus_point_frames, std::vector<FocusPointFrame>* focus_point_frames,
@ -78,7 +78,7 @@ class SceneCameraMotionAnalyzer {
// crop window in SceneKeyFrameCropSummary in the case of steady motion. // crop window in SceneKeyFrameCropSummary in the case of steady motion.
absl::Status DecideCameraMotionType( absl::Status DecideCameraMotionType(
const KeyFrameCropOptions& key_frame_crop_options, const KeyFrameCropOptions& key_frame_crop_options,
const double scene_span_sec, const int64 end_time_us, const double scene_span_sec, const int64_t end_time_us,
SceneKeyFrameCropSummary* scene_summary, SceneKeyFrameCropSummary* scene_summary,
SceneCameraMotion* scene_camera_motion) const; SceneCameraMotion* scene_camera_motion) const;
@ -87,7 +87,7 @@ class SceneCameraMotionAnalyzer {
absl::Status PopulateFocusPointFrames( absl::Status PopulateFocusPointFrames(
const SceneKeyFrameCropSummary& scene_summary, const SceneKeyFrameCropSummary& scene_summary,
const SceneCameraMotion& scene_camera_motion, const SceneCameraMotion& scene_camera_motion,
const std::vector<int64>& scene_frame_timestamps, const std::vector<int64_t>& scene_frame_timestamps,
std::vector<FocusPointFrame>* focus_point_frames) const; std::vector<FocusPointFrame>* focus_point_frames) const;
private: private:
@ -118,7 +118,7 @@ class SceneCameraMotionAnalyzer {
absl::Status PopulateFocusPointFramesForTracking( absl::Status PopulateFocusPointFramesForTracking(
const SceneKeyFrameCropSummary& scene_summary, const SceneKeyFrameCropSummary& scene_summary,
const FocusPointFrameType focus_point_frame_type, const FocusPointFrameType focus_point_frame_type,
const std::vector<int64>& scene_frame_timestamps, const std::vector<int64_t>& scene_frame_timestamps,
std::vector<FocusPointFrame>* focus_point_frames) const; std::vector<FocusPointFrame>* focus_point_frames) const;
// Decide to use steady motion. // Decide to use steady motion.
@ -142,7 +142,7 @@ class SceneCameraMotionAnalyzer {
// Last position // Last position
SceneCameraMotion last_scene_with_salient_region_; SceneCameraMotion last_scene_with_salient_region_;
int64 time_since_last_salient_region_us_; int64_t time_since_last_salient_region_us_;
// Scene has solid color background. // Scene has solid color background.
bool has_solid_color_background_; bool has_solid_color_background_;

View File

@ -62,7 +62,7 @@ class SceneCropper {
// TODO: split this function into two separate functions. // TODO: split this function into two separate functions.
absl::Status CropFrames( absl::Status CropFrames(
const SceneKeyFrameCropSummary& scene_summary, const SceneKeyFrameCropSummary& scene_summary,
const std::vector<int64>& scene_timestamps, const std::vector<int64_t>& scene_timestamps,
const std::vector<bool>& is_key_frames, const std::vector<bool>& is_key_frames,
const std::vector<cv::Mat>& scene_frames_or_empty, const std::vector<cv::Mat>& scene_frames_or_empty,
const std::vector<FocusPointFrame>& focus_point_frames, const std::vector<FocusPointFrame>& focus_point_frames,
@ -73,7 +73,7 @@ class SceneCropper {
absl::Status ProcessKinematicPathSolver( absl::Status ProcessKinematicPathSolver(
const SceneKeyFrameCropSummary& scene_summary, const SceneKeyFrameCropSummary& scene_summary,
const std::vector<int64>& scene_timestamps, const std::vector<int64_t>& scene_timestamps,
const std::vector<bool>& is_key_frames, const std::vector<bool>& is_key_frames,
const std::vector<FocusPointFrame>& focus_point_frames, const std::vector<FocusPointFrame>& focus_point_frames,
const bool continue_last_scene, std::vector<cv::Mat>* all_xforms); const bool continue_last_scene, std::vector<cv::Mat>* all_xforms);

View File

@ -29,7 +29,7 @@ namespace autoflip {
// Packs detected features and timestamp (ms) into a KeyFrameInfo object. Scales // Packs detected features and timestamp (ms) into a KeyFrameInfo object. Scales
// features back to the original frame size if features have been detected on a // features back to the original frame size if features have been detected on a
// different frame size. // different frame size.
absl::Status PackKeyFrameInfo(const int64 frame_timestamp_ms, absl::Status PackKeyFrameInfo(const int64_t frame_timestamp_ms,
const DetectionSet& detections, const DetectionSet& detections,
const int original_frame_width, const int original_frame_width,
const int original_frame_height, const int original_frame_height,
@ -71,7 +71,7 @@ absl::Status ComputeSceneStaticBordersSize(
// interpolation functions in Lab space using input timestamps. // interpolation functions in Lab space using input timestamps.
absl::Status FindSolidBackgroundColor( absl::Status FindSolidBackgroundColor(
const std::vector<StaticFeatures>& static_features, const std::vector<StaticFeatures>& static_features,
const std::vector<int64>& static_features_timestamps, const std::vector<int64_t>& static_features_timestamps,
const double min_fraction_solid_background_color, const double min_fraction_solid_background_color,
bool* has_solid_background, bool* has_solid_background,
PiecewiseLinearFunction* background_color_l_function, PiecewiseLinearFunction* background_color_l_function,

View File

@ -16,11 +16,11 @@ limitations under the License.
#ifndef MEDIAPIPE_FRAMEWORK_FORMATS_FRAME_BUFFER_H_ #ifndef MEDIAPIPE_FRAMEWORK_FORMATS_FRAME_BUFFER_H_
#define MEDIAPIPE_FRAMEWORK_FORMATS_FRAME_BUFFER_H_ #define MEDIAPIPE_FRAMEWORK_FORMATS_FRAME_BUFFER_H_
#include <cstdint>
#include <vector> #include <vector>
#include "absl/log/absl_check.h" #include "absl/log/absl_check.h"
#include "absl/status/statusor.h" #include "absl/status/statusor.h"
#include "mediapipe/framework/port/integral_types.h"
namespace mediapipe { namespace mediapipe {
@ -76,13 +76,13 @@ class FrameBuffer {
// Plane encapsulates buffer and stride information. // Plane encapsulates buffer and stride information.
struct Plane { struct Plane {
Plane(uint8* buffer, Stride stride) : buffer_(buffer), stride_(stride) {} Plane(uint8_t* buffer, Stride stride) : buffer_(buffer), stride_(stride) {}
const uint8* buffer() const { return buffer_; } const uint8_t* buffer() const { return buffer_; }
uint8* mutable_buffer() { return buffer_; } uint8_t* mutable_buffer() { return buffer_; }
Stride stride() const { return stride_; } Stride stride() const { return stride_; }
private: private:
uint8* buffer_; uint8_t* buffer_;
Stride stride_; Stride stride_;
}; };
@ -121,9 +121,9 @@ class FrameBuffer {
// YUV data structure. // YUV data structure.
struct YuvData { struct YuvData {
const uint8* y_buffer; const uint8_t* y_buffer;
const uint8* u_buffer; const uint8_t* u_buffer;
const uint8* v_buffer; const uint8_t* v_buffer;
// Y buffer row stride in bytes. // Y buffer row stride in bytes.
int y_row_stride; int y_row_stride;
// U/V buffer row stride in bytes. // U/V buffer row stride in bytes.

View File

@ -15,6 +15,7 @@
#ifndef MEDIAPIPE_FRAMEWORK_FORMATS_IMAGE_H_ #ifndef MEDIAPIPE_FRAMEWORK_FORMATS_IMAGE_H_
#define MEDIAPIPE_FRAMEWORK_FORMATS_IMAGE_H_ #define MEDIAPIPE_FRAMEWORK_FORMATS_IMAGE_H_
#include <cstdint>
#include <utility> #include <utility>
#include "absl/synchronization/mutex.h" #include "absl/synchronization/mutex.h"
@ -207,7 +208,7 @@ inline void Image::UnlockPixels() const {}
// Image buf = ... // Image buf = ...
// { // {
// PixelLock lock(&buf); // PixelLock lock(&buf);
// uint8* buf_ptr = lock.Pixels(); // uint8_t* buf_ptr = lock.Pixels();
// ... use buf_ptr to access pixel data ... // ... use buf_ptr to access pixel data ...
// ... lock released automatically at end of scope ... // ... lock released automatically at end of scope ...
// } // }
@ -228,7 +229,7 @@ class PixelReadLock {
} }
PixelReadLock(const PixelReadLock&) = delete; PixelReadLock(const PixelReadLock&) = delete;
const uint8* Pixels() const { const uint8_t* Pixels() const {
if (frame_) return frame_->PixelData(); if (frame_) return frame_->PixelData();
return nullptr; return nullptr;
} }
@ -254,7 +255,7 @@ class PixelWriteLock {
} }
PixelWriteLock(const PixelWriteLock&) = delete; PixelWriteLock(const PixelWriteLock&) = delete;
uint8* Pixels() { uint8_t* Pixels() {
if (frame_) return frame_->MutablePixelData(); if (frame_) return frame_->MutablePixelData();
return nullptr; return nullptr;
} }

View File

@ -35,13 +35,13 @@
#ifndef MEDIAPIPE_FRAMEWORK_FORMATS_IMAGE_FRAME_H_ #ifndef MEDIAPIPE_FRAMEWORK_FORMATS_IMAGE_FRAME_H_
#define MEDIAPIPE_FRAMEWORK_FORMATS_IMAGE_FRAME_H_ #define MEDIAPIPE_FRAMEWORK_FORMATS_IMAGE_FRAME_H_
#include <cstdint>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <string> #include <string>
#include "mediapipe/framework/formats/image_format.pb.h" #include "mediapipe/framework/formats/image_format.pb.h"
#include "mediapipe/framework/port.h" #include "mediapipe/framework/port.h"
#include "mediapipe/framework/port/integral_types.h"
#include "mediapipe/framework/tool/type_util.h" #include "mediapipe/framework/tool/type_util.h"
#define IMAGE_FRAME_RAW_IMAGE MEDIAPIPE_HAS_RTTI #define IMAGE_FRAME_RAW_IMAGE MEDIAPIPE_HAS_RTTI
@ -63,7 +63,7 @@ namespace mediapipe {
// stored with row padding for alignment purposes. // stored with row padding for alignment purposes.
class ImageFrame { class ImageFrame {
public: public:
typedef std::function<void(uint8*)> Deleter; typedef std::function<void(uint8_t*)> Deleter;
// This class offers a few standard delete functions and retains // This class offers a few standard delete functions and retains
// compatibility with the previous API. // compatibility with the previous API.
@ -78,13 +78,13 @@ class ImageFrame {
// Use a default alignment boundary of 16 because Intel SSE2 instructions may // Use a default alignment boundary of 16 because Intel SSE2 instructions may
// incur performance penalty when accessing data not aligned on a 16-byte // incur performance penalty when accessing data not aligned on a 16-byte
// boundary. FFmpeg requires at least this level of alignment. // boundary. FFmpeg requires at least this level of alignment.
static const uint32 kDefaultAlignmentBoundary = 16; static const uint32_t kDefaultAlignmentBoundary = 16;
// If the pixel data of an ImageFrame will be passed to an OpenGL function // If the pixel data of an ImageFrame will be passed to an OpenGL function
// such as glTexImage2D() or glReadPixels(), use a four-byte alignment // such as glTexImage2D() or glReadPixels(), use a four-byte alignment
// boundary because that is the initial value of the OpenGL GL_PACK_ALIGNMENT // boundary because that is the initial value of the OpenGL GL_PACK_ALIGNMENT
// and GL_UNPACK_ALIGNMENT parameters. // and GL_UNPACK_ALIGNMENT parameters.
static const uint32 kGlDefaultAlignmentBoundary = 4; static const uint32_t kGlDefaultAlignmentBoundary = 4;
// Returns number of channels for an ImageFormat. // Returns number of channels for an ImageFormat.
static int NumberOfChannelsForFormat(ImageFormat::Format format); static int NumberOfChannelsForFormat(ImageFormat::Format format);
@ -104,7 +104,7 @@ class ImageFrame {
// must be a power of 2 (the number 1 is valid, and means the data will // must be a power of 2 (the number 1 is valid, and means the data will
// be stored contiguously). // be stored contiguously).
ImageFrame(ImageFormat::Format format, int width, int height, ImageFrame(ImageFormat::Format format, int width, int height,
uint32 alignment_boundary); uint32_t alignment_boundary);
// Same as above, but use kDefaultAlignmentBoundary for alignment_boundary. // Same as above, but use kDefaultAlignmentBoundary for alignment_boundary.
ImageFrame(ImageFormat::Format format, int width, int height); ImageFrame(ImageFormat::Format format, int width, int height);
@ -115,8 +115,8 @@ class ImageFrame {
// width*num_channels*depth. Both width_step and depth are in units // width*num_channels*depth. Both width_step and depth are in units
// of bytes. // of bytes.
ImageFrame(ImageFormat::Format format, int width, int height, int width_step, ImageFrame(ImageFormat::Format format, int width, int height, int width_step,
uint8* pixel_data, uint8_t* pixel_data,
Deleter deleter = std::default_delete<uint8[]>()); Deleter deleter = std::default_delete<uint8_t[]>());
ImageFrame(ImageFrame&& move_from); ImageFrame(ImageFrame&& move_from);
ImageFrame& operator=(ImageFrame&& move_from); ImageFrame& operator=(ImageFrame&& move_from);
@ -142,7 +142,7 @@ class ImageFrame {
// alignment_boundary. If IsAligned(16) is true then so are // alignment_boundary. If IsAligned(16) is true then so are
// IsAligned(8), IsAligned(4), IsAligned(2), and IsAligned(1). // IsAligned(8), IsAligned(4), IsAligned(2), and IsAligned(1).
// alignment_boundary must be 1 or a power of 2. // alignment_boundary must be 1 or a power of 2.
bool IsAligned(uint32 alignment_boundary) const; bool IsAligned(uint32_t alignment_boundary) const;
// Returns the image / video format. // Returns the image / video format.
ImageFormat::Format Format() const { return format_; } ImageFormat::Format Format() const { return format_; }
@ -167,13 +167,13 @@ class ImageFrame {
// Reset the current image frame and copy the data from image_frame into // Reset the current image frame and copy the data from image_frame into
// this image frame. The alignment_boundary must be given (and won't // this image frame. The alignment_boundary must be given (and won't
// necessarily match the alignment_boundary of the input image_frame). // necessarily match the alignment_boundary of the input image_frame).
void CopyFrom(const ImageFrame& image_frame, uint32 alignment_boundary); void CopyFrom(const ImageFrame& image_frame, uint32_t alignment_boundary);
// Get a mutable pointer to the underlying image data. The ImageFrame // Get a mutable pointer to the underlying image data. The ImageFrame
// retains ownership. // retains ownership.
uint8* MutablePixelData() { return pixel_data_.get(); } uint8_t* MutablePixelData() { return pixel_data_.get(); }
// Get a const pointer to the underlying image data. // Get a const pointer to the underlying image data.
const uint8* PixelData() const { return pixel_data_.get(); } const uint8_t* PixelData() const { return pixel_data_.get(); }
// Returns the total size of the pixel data. // Returns the total size of the pixel data.
int PixelDataSize() const { return Height() * WidthStep(); } int PixelDataSize() const { return Height() * WidthStep(); }
@ -187,41 +187,41 @@ class ImageFrame {
// ImageFrame takes ownership of pixel_data. See the Constructor // ImageFrame takes ownership of pixel_data. See the Constructor
// with the same arguments for details. // with the same arguments for details.
void AdoptPixelData(ImageFormat::Format format, int width, int height, void AdoptPixelData(ImageFormat::Format format, int width, int height,
int width_step, uint8* pixel_data, int width_step, uint8_t* pixel_data,
Deleter deleter = std::default_delete<uint8[]>()); Deleter deleter = std::default_delete<uint8_t[]>());
// Resets the ImageFrame and makes it a copy of the provided pixel // Resets the ImageFrame and makes it a copy of the provided pixel
// data, which is assumed to be stored contiguously. The ImageFrame // data, which is assumed to be stored contiguously. The ImageFrame
// will use the given alignment_boundary. // will use the given alignment_boundary.
void CopyPixelData(ImageFormat::Format format, int width, int height, void CopyPixelData(ImageFormat::Format format, int width, int height,
const uint8* pixel_data, uint32 alignment_boundary); const uint8_t* pixel_data, uint32_t alignment_boundary);
// Resets the ImageFrame and makes it a copy of the provided pixel // Resets the ImageFrame and makes it a copy of the provided pixel
// data, with given width_step. The ImageFrame // data, with given width_step. The ImageFrame
// will use the given alignment_boundary. // will use the given alignment_boundary.
void CopyPixelData(ImageFormat::Format format, int width, int height, void CopyPixelData(ImageFormat::Format format, int width, int height,
int width_step, const uint8* pixel_data, int width_step, const uint8_t* pixel_data,
uint32 alignment_boundary); uint32_t alignment_boundary);
// Allocates a frame of the specified format, width, height, and alignment, // Allocates a frame of the specified format, width, height, and alignment,
// without clearing any current pixel data. See the constructor with the same // without clearing any current pixel data. See the constructor with the same
// argument list. // argument list.
void Reset(ImageFormat::Format format, int width, int height, void Reset(ImageFormat::Format format, int width, int height,
uint32 alignment_boundary); uint32_t alignment_boundary);
// Relinquishes ownership of the pixel data. Notice that the unique_ptr // Relinquishes ownership of the pixel data. Notice that the unique_ptr
// uses a non-standard deleter. // uses a non-standard deleter.
std::unique_ptr<uint8[], Deleter> Release(); std::unique_ptr<uint8_t[], Deleter> Release();
// Copy the 8-bit ImageFrame into a contiguous, pre-allocated buffer. Note // Copy the 8-bit ImageFrame into a contiguous, pre-allocated buffer. Note
// that ImageFrame does not necessarily store its data contiguously (i.e. do // that ImageFrame does not necessarily store its data contiguously (i.e. do
// not use copy_n to move image data). // not use copy_n to move image data).
void CopyToBuffer(uint8* buffer, int buffer_size) const; void CopyToBuffer(uint8_t* buffer, int buffer_size) const;
// A version of CopyToBuffer for 16-bit pixel data. Note that buffer_size // A version of CopyToBuffer for 16-bit pixel data. Note that buffer_size
// stores the number of 16-bit elements in the buffer, not the number of // stores the number of 16-bit elements in the buffer, not the number of
// bytes. // bytes.
void CopyToBuffer(uint16* buffer, int buffer_size) const; void CopyToBuffer(uint16_t* buffer, int buffer_size) const;
// A version of CopyToBuffer for float pixel data. Note that buffer_size // A version of CopyToBuffer for float pixel data. Note that buffer_size
// stores the number of float elements in the buffer, not the number of // stores the number of float elements in the buffer, not the number of
@ -233,12 +233,12 @@ class ImageFrame {
private: private:
// Returns true if alignment_number is 1 or a power of 2. // Returns true if alignment_number is 1 or a power of 2.
static bool IsValidAlignmentNumber(uint32 alignment_boundary); static bool IsValidAlignmentNumber(uint32_t alignment_boundary);
// The internal implementation of copying data from the provided pixel data. // The internal implementation of copying data from the provided pixel data.
// If width_step is 0, then calculates width_step assuming no padding. // If width_step is 0, then calculates width_step assuming no padding.
void InternalCopyFrom(int width, int height, int width_step, int channel_size, void InternalCopyFrom(int width, int height, int width_step, int channel_size,
const uint8* pixel_data); const uint8_t* pixel_data);
// The internal implementation of copying data to the provided buffer. // The internal implementation of copying data to the provided buffer.
// If width_step is 0, then calculates width_step assuming no padding. // If width_step is 0, then calculates width_step assuming no padding.
@ -249,7 +249,7 @@ class ImageFrame {
int height_; int height_;
int width_step_; int width_step_;
std::unique_ptr<uint8[], Deleter> pixel_data_; std::unique_ptr<uint8_t[], Deleter> pixel_data_;
}; };
} // namespace mediapipe } // namespace mediapipe

View File

@ -16,6 +16,7 @@
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <cstdint>
#include <memory> #include <memory>
#include "absl/log/absl_check.h" #include "absl/log/absl_check.h"

View File

@ -215,7 +215,7 @@ Location CreateCvMaskLocation(const cv::Mat_<T>& mask) {
return Location(location_data); return Location(location_data);
} }
template Location CreateCvMaskLocation(const cv::Mat_<uint8>& mask); template Location CreateCvMaskLocation(const cv::Mat_<uint8_t>& mask);
template Location CreateCvMaskLocation(const cv::Mat_<float>& mask); template Location CreateCvMaskLocation(const cv::Mat_<float>& mask);
} // namespace mediapipe } // namespace mediapipe

View File

@ -15,6 +15,7 @@
#ifndef MEDIAPIPE_FRAMEWORK_FORMATS_YUV_IMAGE_H_ #ifndef MEDIAPIPE_FRAMEWORK_FORMATS_YUV_IMAGE_H_
#define MEDIAPIPE_FRAMEWORK_FORMATS_YUV_IMAGE_H_ #define MEDIAPIPE_FRAMEWORK_FORMATS_YUV_IMAGE_H_
#include <cstdint>
#include <functional> #include <functional>
#include <memory> #include <memory>
@ -119,13 +120,13 @@ class YUVImage {
~YUVImage() { Clear(); } ~YUVImage() { Clear(); }
// Convenience constructor // Convenience constructor
YUVImage(libyuv::FourCC fourcc, // YUVImage(libyuv::FourCC fourcc, //
std::unique_ptr<uint8[]> data_location, // std::unique_ptr<uint8_t[]> data_location, //
uint8* data0, int stride0, // uint8_t* data0, int stride0, //
uint8* data1, int stride1, // uint8_t* data1, int stride1, //
uint8* data2, int stride2, // uint8_t* data2, int stride2, //
int width, int height, int bit_depth = 8) { int width, int height, int bit_depth = 8) {
uint8* tmp = data_location.release(); uint8_t* tmp = data_location.release();
std::function<void()> deallocate = [tmp]() { delete[] tmp; }; std::function<void()> deallocate = [tmp]() { delete[] tmp; };
Initialize(fourcc, // Initialize(fourcc, //
deallocate, // deallocate, //
@ -137,14 +138,14 @@ class YUVImage {
// Convenience constructor to construct the YUVImage with data stored // Convenience constructor to construct the YUVImage with data stored
// in three unique_ptrs. // in three unique_ptrs.
YUVImage(libyuv::FourCC fourcc, // YUVImage(libyuv::FourCC fourcc, //
std::unique_ptr<uint8[]> data0, int stride0, // std::unique_ptr<uint8_t[]> data0, int stride0, //
std::unique_ptr<uint8[]> data1, int stride1, // std::unique_ptr<uint8_t[]> data1, int stride1, //
std::unique_ptr<uint8[]> data2, int stride2, // std::unique_ptr<uint8_t[]> data2, int stride2, //
int width, int height, int bit_depth = 8) { int width, int height, int bit_depth = 8) {
uint8* tmp0 = data0.release(); uint8_t* tmp0 = data0.release();
uint8* tmp1 = data1.release(); uint8_t* tmp1 = data1.release();
uint8* tmp2 = data2.release(); uint8_t* tmp2 = data2.release();
std::function<void()> deallocate = [tmp0, tmp1, tmp2]() { std::function<void()> deallocate = [tmp0, tmp1, tmp2]() {
delete[] tmp0; delete[] tmp0;
delete[] tmp1; delete[] tmp1;
@ -177,9 +178,9 @@ class YUVImage {
// pixel format it holds. // pixel format it holds.
void Initialize(libyuv::FourCC fourcc, // void Initialize(libyuv::FourCC fourcc, //
std::function<void()> deallocation_function, // std::function<void()> deallocation_function, //
uint8* data0, int stride0, // uint8_t* data0, int stride0, //
uint8* data1, int stride1, // uint8_t* data1, int stride1, //
uint8* data2, int stride2, // uint8_t* data2, int stride2, //
int width, int height, int bit_depth = 8) { int width, int height, int bit_depth = 8) {
Clear(); Clear();
deallocation_function_ = deallocation_function; deallocation_function_ = deallocation_function;
@ -214,7 +215,7 @@ class YUVImage {
// Getters. // Getters.
libyuv::FourCC fourcc() const { return fourcc_; } libyuv::FourCC fourcc() const { return fourcc_; }
const uint8* data(int index) const { return data_[index]; } const uint8_t* data(int index) const { return data_[index]; }
int stride(int index) const { return stride_[index]; } int stride(int index) const { return stride_[index]; }
int width() const { return width_; } int width() const { return width_; }
int height() const { return height_; } int height() const { return height_; }
@ -226,7 +227,7 @@ class YUVImage {
// Setters. // Setters.
void set_fourcc(libyuv::FourCC fourcc) { fourcc_ = fourcc; } void set_fourcc(libyuv::FourCC fourcc) { fourcc_ = fourcc; }
uint8* mutable_data(int index) { return data_[index]; } uint8_t* mutable_data(int index) { return data_[index]; }
void set_stride(int index, int stride) { stride_[index] = stride; } void set_stride(int index, int stride) { stride_[index] = stride; }
void set_width(int width) { width_ = width; } void set_width(int width) { width_ = width; }
void set_height(int height) { height_ = height; } void set_height(int height) { height_ = height; }
@ -241,7 +242,7 @@ class YUVImage {
std::function<void()> deallocation_function_; std::function<void()> deallocation_function_;
libyuv::FourCC fourcc_ = libyuv::FOURCC_ANY; libyuv::FourCC fourcc_ = libyuv::FOURCC_ANY;
uint8* data_[kMaxNumPlanes]; uint8_t* data_[kMaxNumPlanes];
int stride_[kMaxNumPlanes]; int stride_[kMaxNumPlanes];
int width_ = 0; int width_ = 0;
int height_ = 0; int height_ = 0;

View File

@ -18,6 +18,7 @@
#import <Accelerate/Accelerate.h> #import <Accelerate/Accelerate.h>
#include <atomic> #include <atomic>
#include <cstdint>
#import "GTMDefines.h" #import "GTMDefines.h"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
@ -48,7 +49,7 @@
std::atomic<int32_t> _framesInFlight; std::atomic<int32_t> _framesInFlight;
/// Used as a sequential timestamp for MediaPipe. /// Used as a sequential timestamp for MediaPipe.
mediapipe::Timestamp _frameTimestamp; mediapipe::Timestamp _frameTimestamp;
int64 _frameNumber; int64_t _frameNumber;
// Graph config modified to expose requested output streams. // Graph config modified to expose requested output streams.
mediapipe::CalculatorGraphConfig _config; mediapipe::CalculatorGraphConfig _config;
@ -90,8 +91,8 @@
&callbackInputName, &callbackInputName,
/*use_std_function=*/true); /*use_std_function=*/true);
// No matter what ownership qualifiers are put on the pointer, // No matter what ownership qualifiers are put on the pointer,
// NewPermanentCallback will still end up with a strong pointer to MPPGraph*. // NewPermanentCallback will still end up with a strong pointer to
// That is why we use void* instead. // MPPGraph*. That is why we use void* instead.
void* wrapperVoid = (__bridge void*)self; void* wrapperVoid = (__bridge void*)self;
_inputSidePackets[callbackInputName] = _inputSidePackets[callbackInputName] =
mediapipe::MakePacket<std::function<void(const mediapipe::Packet&)>>( mediapipe::MakePacket<std::function<void(const mediapipe::Packet&)>>(

View File

@ -14,6 +14,8 @@
#import "MPPTimestampConverter.h" #import "MPPTimestampConverter.h"
#include <cstdint>
@implementation MPPTimestampConverter { @implementation MPPTimestampConverter {
mediapipe::Timestamp _mediapipeTimestamp; mediapipe::Timestamp _mediapipeTimestamp;
mediapipe::Timestamp _lastTimestamp; mediapipe::Timestamp _lastTimestamp;
@ -37,7 +39,7 @@
- (mediapipe::Timestamp)timestampForMediaTime:(CMTime)mediaTime { - (mediapipe::Timestamp)timestampForMediaTime:(CMTime)mediaTime {
Float64 sampleSeconds = Float64 sampleSeconds =
CMTIME_IS_VALID(mediaTime) ? CMTimeGetSeconds(mediaTime) : 0; CMTIME_IS_VALID(mediaTime) ? CMTimeGetSeconds(mediaTime) : 0;
const int64 sampleUsec = const int64_t sampleUsec =
sampleSeconds * mediapipe::Timestamp::kTimestampUnitsPerSecond; sampleSeconds * mediapipe::Timestamp::kTimestampUnitsPerSecond;
_mediapipeTimestamp = mediapipe::Timestamp(sampleUsec) + _timestampOffset; _mediapipeTimestamp = mediapipe::Timestamp(sampleUsec) + _timestampOffset;
if (_mediapipeTimestamp <= _lastTimestamp) { if (_mediapipeTimestamp <= _lastTimestamp) {

View File

@ -14,6 +14,8 @@
#include "mediapipe/objc/util.h" #include "mediapipe/objc/util.h"
#include <cstdint>
#include "absl/base/macros.h" #include "absl/base/macros.h"
#include "absl/log/absl_check.h" #include "absl/log/absl_check.h"
#include "absl/log/absl_log.h" #include "absl/log/absl_log.h"
@ -639,7 +641,7 @@ std::unique_ptr<mediapipe::ImageFrame> CreateImageFrameForCVPixelBuffer(
} else { } else {
frame = absl::make_unique<mediapipe::ImageFrame>( frame = absl::make_unique<mediapipe::ImageFrame>(
image_format, width, height, bytes_per_row, image_format, width, height, bytes_per_row,
reinterpret_cast<uint8*>(base_address), [image_buffer](uint8* x) { reinterpret_cast<uint8_t*>(base_address), [image_buffer](uint8_t* x) {
CVPixelBufferUnlockBaseAddress(image_buffer, CVPixelBufferUnlockBaseAddress(image_buffer,
kCVPixelBufferLock_ReadOnly); kCVPixelBufferLock_ReadOnly);
CVPixelBufferRelease(image_buffer); CVPixelBufferRelease(image_buffer);

View File

@ -90,7 +90,7 @@ class BasePacketProcessor {
// CorrectPtsForRollover(2^33 - 1) -> 2^33 - 1 // CorrectPtsForRollover(2^33 - 1) -> 2^33 - 1
// CorrectPtsForRollover(0) -> 2^33 // PTS in media rolls over, corrected. // CorrectPtsForRollover(0) -> 2^33 // PTS in media rolls over, corrected.
// CorrectPtsForRollover(1) -> 2^33 + 1 // CorrectPtsForRollover(1) -> 2^33 + 1
int64 CorrectPtsForRollover(int64 media_pts); int64_t CorrectPtsForRollover(int64_t media_pts);
AVCodecContext* avcodec_ctx_ = nullptr; AVCodecContext* avcodec_ctx_ = nullptr;
const AVCodec* avcodec_ = nullptr; const AVCodec* avcodec_ = nullptr;
@ -113,7 +113,7 @@ class BasePacketProcessor {
AVRational source_frame_rate_; AVRational source_frame_rate_;
// The number of frames that were successfully processed. // The number of frames that were successfully processed.
int64 num_frames_processed_ = 0; int64_t num_frames_processed_ = 0;
int bytes_per_sample_ = 0; int bytes_per_sample_ = 0;
@ -121,7 +121,7 @@ class BasePacketProcessor {
bool last_frame_time_regression_detected_ = false; bool last_frame_time_regression_detected_ = false;
// The last rollover corrected PTS returned by CorrectPtsForRollover. // The last rollover corrected PTS returned by CorrectPtsForRollover.
int64 rollover_corrected_last_pts_ = AV_NOPTS_VALUE; int64_t rollover_corrected_last_pts_ = AV_NOPTS_VALUE;
// The buffer of current frames. // The buffer of current frames.
std::deque<Packet> buffer_; std::deque<Packet> buffer_;
@ -141,16 +141,16 @@ class AudioPacketProcessor : public BasePacketProcessor {
private: private:
// Appends audio in buffer(s) to the output buffer (buffer_). // Appends audio in buffer(s) to the output buffer (buffer_).
absl::Status AddAudioDataToBuffer(const Timestamp output_timestamp, absl::Status AddAudioDataToBuffer(const Timestamp output_timestamp,
uint8* const* raw_audio, uint8_t* const* raw_audio,
int buf_size_bytes); int buf_size_bytes);
// Converts a number of samples into an approximate stream timestamp value. // Converts a number of samples into an approximate stream timestamp value.
int64 SampleNumberToTimestamp(const int64 sample_number); int64_t SampleNumberToTimestamp(const int64_t sample_number);
int64 TimestampToSampleNumber(const int64 timestamp); int64_t TimestampToSampleNumber(const int64_t timestamp);
// Converts a timestamp/sample number to microseconds. // Converts a timestamp/sample number to microseconds.
int64 TimestampToMicroseconds(const int64 timestamp); int64_t TimestampToMicroseconds(const int64_t timestamp);
int64 SampleNumberToMicroseconds(const int64 sample_number); int64_t SampleNumberToMicroseconds(const int64_t sample_number);
// Returns an error if the sample format in avformat_ctx_.sample_format // Returns an error if the sample format in avformat_ctx_.sample_format
// is not supported. // is not supported.
@ -161,7 +161,7 @@ class AudioPacketProcessor : public BasePacketProcessor {
absl::Status ProcessDecodedFrame(const AVPacket& packet) override; absl::Status ProcessDecodedFrame(const AVPacket& packet) override;
// Corrects PTS for rollover if correction is enabled. // Corrects PTS for rollover if correction is enabled.
int64 MaybeCorrectPtsForRollover(int64 media_pts); int64_t MaybeCorrectPtsForRollover(int64_t media_pts);
// Number of channels to output. This value might be different from // Number of channels to output. This value might be different from
// the actual number of channels for the current AVPacket, found in // the actual number of channels for the current AVPacket, found in
@ -171,7 +171,7 @@ class AudioPacketProcessor : public BasePacketProcessor {
// Sample rate of the data to output. This value might be different // Sample rate of the data to output. This value might be different
// from the actual sample rate for the current AVPacket, found in // from the actual sample rate for the current AVPacket, found in
// avcodec_ctx_->sample_rate. // avcodec_ctx_->sample_rate.
int64 sample_rate_ = -1; int64_t sample_rate_ = -1;
// The time base of audio samples (i.e. the reciprocal of the sample rate). // The time base of audio samples (i.e. the reciprocal of the sample rate).
AVRational sample_time_base_; AVRational sample_time_base_;
@ -180,7 +180,7 @@ class AudioPacketProcessor : public BasePacketProcessor {
Timestamp last_timestamp_; Timestamp last_timestamp_;
// The expected sample number based on counting samples. // The expected sample number based on counting samples.
int64 expected_sample_number_ = 0; int64_t expected_sample_number_ = 0;
// Options for the processor. // Options for the processor.
AudioStreamOptions options_; AudioStreamOptions options_;

View File

@ -74,14 +74,14 @@ void YUVImageToImageFrameFromFormat(const YUVImage& yuv_image,
// values used are those from ITU-R BT.601 (which are the same as ITU-R // values used are those from ITU-R BT.601 (which are the same as ITU-R
// BT.709). The conversion values are taken from wikipedia and cross // BT.709). The conversion values are taken from wikipedia and cross
// checked with other sources. // checked with other sources.
void SrgbToMpegYCbCr(const uint8 r, const uint8 g, const uint8 b, // void SrgbToMpegYCbCr(const uint8_t r, const uint8_t g, const uint8_t b, //
uint8* y, uint8* cb, uint8* cr); uint8_t* y, uint8_t* cb, uint8_t* cr);
// Convert MPEG YCbCr values into sRGB values. See the SrgbToMpegYCbCr() // Convert MPEG YCbCr values into sRGB values. See the SrgbToMpegYCbCr()
// for more notes. Many MPEG YCbCr values do not correspond directly // for more notes. Many MPEG YCbCr values do not correspond directly
// to an sRGB value. If the value is invalid it will be clipped to the // to an sRGB value. If the value is invalid it will be clipped to the
// closest valid value on a per channel basis. // closest valid value on a per channel basis.
void MpegYCbCrToSrgb(const uint8 y, const uint8 cb, const uint8 cr, // void MpegYCbCrToSrgb(const uint8_t y, const uint8_t cb, const uint8_t cr, //
uint8* r, uint8* g, uint8* b); uint8_t* r, uint8_t* g, uint8_t* b);
// Conversion functions to and from srgb and linear RGB in 16 bits-per-pixel // Conversion functions to and from srgb and linear RGB in 16 bits-per-pixel
// channel. // channel.

View File

@ -27,7 +27,7 @@ namespace mediapipe {
// both expected to contain one label per line. // both expected to contain one label per line.
// Returns an error e.g. if there's a mismatch between the number of labels and // Returns an error e.g. if there's a mismatch between the number of labels and
// display names. // display names.
absl::StatusOr<proto_ns::Map<int64, ::mediapipe::LabelMapItem>> absl::StatusOr<proto_ns::Map<int64_t, ::mediapipe::LabelMapItem>>
BuildLabelMapFromFiles(absl::string_view labels_file_contents, BuildLabelMapFromFiles(absl::string_view labels_file_contents,
absl::string_view display_names_file); absl::string_view display_names_file);

View File

@ -292,7 +292,7 @@ class TimeSeriesCalculatorTest : public ::testing::Test {
// Overload to allow explicit conversion from int64 to Timestamp // Overload to allow explicit conversion from int64 to Timestamp
template <typename T> template <typename T>
void AppendInputPacket(const T* payload, const int64 timestamp, void AppendInputPacket(const T* payload, const int64_t timestamp,
const size_t input_index = 0) { const size_t input_index = 0) {
AppendInputPacket(payload, Timestamp(timestamp), input_index); AppendInputPacket(payload, Timestamp(timestamp), input_index);
} }
@ -305,7 +305,7 @@ class TimeSeriesCalculatorTest : public ::testing::Test {
} }
template <typename T> template <typename T>
void AppendInputPacket(const T* payload, const int64 timestamp, void AppendInputPacket(const T* payload, const int64_t timestamp,
const std::string& input_tag) { const std::string& input_tag) {
AppendInputPacket(payload, Timestamp(timestamp), input_tag); AppendInputPacket(payload, Timestamp(timestamp), input_tag);
} }
@ -450,7 +450,7 @@ class MultiStreamTimeSeriesCalculatorTest
// Overload to allow explicit conversion from int64 to Timestamp // Overload to allow explicit conversion from int64 to Timestamp
void AppendInputPacket(const std::vector<Matrix>* input_vector, void AppendInputPacket(const std::vector<Matrix>* input_vector,
const int64 timestamp) { const int64_t timestamp) {
AppendInputPacket(input_vector, Timestamp(timestamp)); AppendInputPacket(input_vector, Timestamp(timestamp));
} }

View File

@ -39,7 +39,7 @@ namespace time_series_util {
// function. // function.
bool LogWarningIfTimestampIsInconsistent(const Timestamp& current_timestamp, bool LogWarningIfTimestampIsInconsistent(const Timestamp& current_timestamp,
const Timestamp& initial_timestamp, const Timestamp& initial_timestamp,
int64 cumulative_samples, int64_t cumulative_samples,
double sample_rate); double sample_rate);
// Returns absl::Status::OK if the header is valid. Otherwise, returns a // Returns absl::Status::OK if the header is valid. Otherwise, returns a
@ -109,11 +109,11 @@ void SetExtensionInHeader(const TimeSeriesHeaderExtensionClass& extension,
} }
// Converts from a time_in_seconds to an integer number of samples. // Converts from a time_in_seconds to an integer number of samples.
int64 SecondsToSamples(double time_in_seconds, double sample_rate); int64_t SecondsToSamples(double time_in_seconds, double sample_rate);
// Converts from an integer number of samples to a time duration in seconds // Converts from an integer number of samples to a time duration in seconds
// spanned by the samples. // spanned by the samples.
double SamplesToSeconds(int64 num_samples, double sample_rate); double SamplesToSeconds(int64_t num_samples, double sample_rate);
} // namespace time_series_util } // namespace time_series_util
} // namespace mediapipe } // namespace mediapipe