Project import generated by Copybara.

GitOrigin-RevId: d073f8e21be2fcc0e503cb97c6695078b6b75310
This commit is contained in:
MediaPipe Team
2021-02-27 03:30:05 -05:00
committed by chuoling
parent 39309bedba
commit 350fbb2100
755 changed files with 16391 additions and 11075 deletions
+2 -3
View File
@@ -78,7 +78,6 @@ cc_library(
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/strings",
"//mediapipe/framework/port:integral_types",
"//mediapipe/framework:port",
"//mediapipe/framework/port:status",
"//mediapipe/framework/port:statusor",
] + select({
@@ -168,13 +167,14 @@ cc_library(
],
deps = [
"//mediapipe/framework/port:ret_check",
"//mediapipe/framework/port:singleton",
"//mediapipe/framework/port:status",
"//mediapipe/framework/port:statusor",
"//mediapipe/framework/port:file_helpers",
"@com_google_absl//absl/strings",
] + select({
"//conditions:default": [
"//mediapipe/framework/deps:file_path",
"//mediapipe/framework/port:file_helpers",
"@com_google_absl//absl/flags:flag",
],
"//mediapipe:android": [
@@ -184,7 +184,6 @@ cc_library(
"//mediapipe:ios": [],
"//mediapipe:macos": [
"//mediapipe/framework/deps:file_path",
"//mediapipe/framework/port:file_helpers",
"@com_google_absl//absl/flags:flag",
],
}),
+13 -5
View File
@@ -95,16 +95,23 @@ bool AssetManager::InitializeFromActivity(JNIEnv* env, jobject activity,
return InitializeFromContext(env, activity, cache_dir_path);
}
bool AssetManager::FileExists(const std::string& filename) {
bool AssetManager::FileExists(const std::string& filename, bool* is_dir) {
if (!asset_manager_) {
LOG(ERROR) << "Asset manager was not initialized from JNI";
return false;
}
auto safe_set_is_dir = [is_dir](bool is_dir_value) {
if (is_dir) {
*is_dir = is_dir_value;
}
};
AAsset* asset =
AAssetManager_open(asset_manager_, filename.c_str(), AASSET_MODE_RANDOM);
if (asset != nullptr) {
AAsset_close(asset);
safe_set_is_dir(false);
return true;
}
@@ -117,6 +124,7 @@ bool AssetManager::FileExists(const std::string& filename) {
// unusable (i.e. not considered a valid path).
bool dir_exists = AAssetDir_getNextFileName(asset_dir) != nullptr;
AAssetDir_close(asset_dir);
safe_set_is_dir(dir_exists);
return dir_exists;
}
@@ -143,7 +151,7 @@ bool AssetManager::ReadFile(const std::string& filename, std::string* output) {
return true;
}
mediapipe::StatusOr<std::string> AssetManager::CachedFileFromAsset(
absl::StatusOr<std::string> AssetManager::CachedFileFromAsset(
const std::string& asset_path) {
RET_CHECK(cache_dir_path_.size()) << "asset manager not initialized";
@@ -170,8 +178,8 @@ mediapipe::StatusOr<std::string> AssetManager::CachedFileFromAsset(
return file_path;
}
mediapipe::Status AssetManager::ReadContentUri(const std::string& content_uri,
std::string* output) {
absl::Status AssetManager::ReadContentUri(const std::string& content_uri,
std::string* output) {
RET_CHECK(mediapipe::java::HasJavaVM()) << "JVM instance not set";
JNIEnv* env = mediapipe::java::GetJNIEnv();
RET_CHECK(env != nullptr) << "Unable to retrieve JNIEnv";
@@ -242,7 +250,7 @@ mediapipe::Status AssetManager::ReadContentUri(const std::string& content_uri,
reinterpret_cast<jbyte*>(&output->at(0)));
RET_CHECK(!ExceptionPrintClear(env)) << "failed to copy array data";
return mediapipe::OkStatus();
return absl::OkStatus();
}
} // namespace mediapipe
+7 -5
View File
@@ -65,16 +65,18 @@ class AssetManager {
bool InitializeFromContext(JNIEnv* env, jobject context,
const std::string& cache_dir_path);
// Checks if a file exists. Returns true on success, false otherwise.
bool FileExists(const std::string& filename);
// Checks if a file exists. Returns true on success, false otherwise. If it
// does exist, then 'is_dir' will be set to indicate whether the file is a
// directory.
bool FileExists(const std::string& filename, bool* is_dir = nullptr);
// Reads a file into output. Returns true on success, false otherwise.
bool ReadFile(const std::string& filename, std::string* output);
// Reads the raw bytes referred to by the supplied content URI. Returns true
// on success, false otherwise.
mediapipe::Status ReadContentUri(const std::string& content_uri,
std::string* output);
absl::Status ReadContentUri(const std::string& content_uri,
std::string* output);
// Returns the path to the Android cache directory. Will be empty if
// InitializeFromActivity has not been called.
@@ -83,7 +85,7 @@ class AssetManager {
// Caches the contents of the given asset as a file, and returns a path to
// that file. This can be used to pass an asset to APIs that require a path
// to a filesystem file.
::mediapipe::StatusOr<std::string> CachedFileFromAsset(
absl::StatusOr<std::string> CachedFileFromAsset(
const std::string& asset_path);
private:
+1
View File
@@ -28,6 +28,7 @@ cc_library(
],
visibility = ["//visibility:public"],
deps = [
"//mediapipe/framework/port:file_helpers",
"//mediapipe/framework/port:logging",
"//mediapipe/framework/port:status",
"@com_google_absl//absl/base",
+16 -19
View File
@@ -25,10 +25,10 @@ static_assert(sizeof(off_t) == 8, "Large file support is required");
namespace mediapipe {
namespace file {
mediapipe::Status RecursivelyCreateDir(absl::string_view path,
const file::Options& options) {
absl::Status RecursivelyCreateDir(absl::string_view path,
const file::Options& options) {
if (path.empty()) {
return mediapipe::OkStatus();
return absl::OkStatus();
}
std::vector<std::string> path_comp = absl::StrSplit(path, '/');
@@ -45,44 +45,41 @@ mediapipe::Status RecursivelyCreateDir(absl::string_view path,
if (S_ISDIR(stat_buf.st_mode)) {
continue;
}
return mediapipe::Status(mediapipe::StatusCode::kInternal,
"Could not stat " + std::string(crpath));
return absl::Status(absl::StatusCode::kInternal,
"Could not stat " + std::string(crpath));
} else {
int mkval = mkdir(crpath, options.permissions());
if (mkval == -1) {
return mediapipe::Status(mediapipe::StatusCode::kInternal,
"Could not create " + std::string(crpath));
return absl::Status(absl::StatusCode::kInternal,
"Could not create " + std::string(crpath));
}
}
}
return mediapipe::OkStatus();
return absl::OkStatus();
}
mediapipe::Status Exists(absl::string_view path, const file::Options& ignored) {
absl::Status Exists(absl::string_view path, const file::Options& ignored) {
struct stat64 stat_buf;
int statval = lstat64(std::string(path).c_str(), &stat_buf);
if (statval == 0) {
return mediapipe::OkStatus();
return absl::OkStatus();
} else {
return mediapipe::Status(mediapipe::StatusCode::kNotFound,
"Could not stat file.");
return absl::Status(absl::StatusCode::kNotFound, "Could not stat file.");
}
}
mediapipe::Status IsDirectory(absl::string_view path,
const file::Options& /*ignored*/) {
absl::Status IsDirectory(absl::string_view path,
const file::Options& /*ignored*/) {
struct stat64 stat_buf;
int statval = lstat64(std::string(path).c_str(), &stat_buf);
bool is_dir = (statval == 0 && S_ISREG(stat_buf.st_mode));
if (is_dir) {
return mediapipe::OkStatus();
return absl::OkStatus();
} else if (statval != 0) {
return mediapipe::Status(mediapipe::StatusCode::kNotFound,
"File does not exists");
return absl::Status(absl::StatusCode::kNotFound, "File does not exists");
} else {
return mediapipe::Status(mediapipe::StatusCode::kNotFound,
"Not a directory");
return absl::Status(absl::StatusCode::kNotFound, "Not a directory");
}
}
@@ -22,13 +22,12 @@
namespace mediapipe {
namespace file {
mediapipe::Status RecursivelyCreateDir(absl::string_view path,
const file::Options& options);
absl::Status RecursivelyCreateDir(absl::string_view path,
const file::Options& options);
mediapipe::Status Exists(absl::string_view path, const file::Options& options);
absl::Status Exists(absl::string_view path, const file::Options& options);
mediapipe::Status IsDirectory(absl::string_view path,
const file::Options& options);
absl::Status IsDirectory(absl::string_view path, const file::Options& options);
} // namespace file.
} // namespace mediapipe
+16 -43
View File
@@ -21,6 +21,7 @@
#include <cstdint>
#include "mediapipe/framework/port/file_helpers.h"
#include "mediapipe/framework/port/status.h"
namespace mediapipe {
@@ -42,16 +43,15 @@ class FdCloser {
} // namespace
// Read contents of a file to a std::string.
mediapipe::Status GetContents(int fd, std::string* output) {
absl::Status GetContents(int fd, std::string* output) {
// Determine the length of the file.
struct stat buf;
if (fstat(fd, &buf) != 0) {
return mediapipe::Status(mediapipe::StatusCode::kUnknown,
"Failed to get file status");
return absl::Status(absl::StatusCode::kUnknown,
"Failed to get file status");
}
if (buf.st_size < 0 || buf.st_size > SIZE_MAX) {
return mediapipe::Status(mediapipe::StatusCode::kInternal,
"Invalid file size");
return absl::Status(absl::StatusCode::kInternal, "Invalid file size");
}
size_t length = buf.st_size;
@@ -61,62 +61,35 @@ mediapipe::Status GetContents(int fd, std::string* output) {
while (length != 0) {
const ssize_t nread = read(fd, output_ptr, length);
if (nread <= 0) {
return mediapipe::Status(mediapipe::StatusCode::kUnknown,
"Failed to read file");
return absl::Status(absl::StatusCode::kUnknown, "Failed to read file");
}
output_ptr += nread;
length -= nread;
}
return mediapipe::OkStatus();
return absl::OkStatus();
}
// Read contents of a file to a std::string.
mediapipe::Status GetContents(absl::string_view file_name, std::string* output,
const file::Options& /*options*/) {
absl::Status GetContents(absl::string_view file_name, std::string* output,
const file::Options& /*options*/) {
int fd = open(std::string(file_name).c_str(), O_RDONLY);
if (fd < 0) {
return mediapipe::Status(mediapipe::StatusCode::kUnknown,
"Failed to open file: " + std::string(file_name));
return absl::Status(absl::StatusCode::kUnknown,
"Failed to open file: " + std::string(file_name));
}
FdCloser closer(fd);
return GetContents(fd, output);
}
mediapipe::Status GetContents(absl::string_view file_name,
std::string* output) {
absl::Status GetContents(absl::string_view file_name, std::string* output) {
return GetContents(file_name, output, file::Defaults());
}
mediapipe::Status SetContents(absl::string_view file_name,
absl::string_view content,
const file::Options& options) {
// Mode -rw-r--r--
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
int fd =
open(std::string(file_name).c_str(), O_WRONLY | O_CREAT | O_TRUNC, mode);
if (fd < 0) {
return mediapipe::Status(mediapipe::StatusCode::kUnknown,
"Failed to open file: " + std::string(file_name));
}
int bytes_written = 0;
if (content.size() > 0) {
bytes_written = write(fd, content.data(), content.size());
}
close(fd);
if (bytes_written == content.size()) {
return mediapipe::OkStatus();
} else {
return mediapipe::Status(mediapipe::StatusCode::kUnknown,
"Failed to write file");
}
}
mediapipe::Status SetContents(absl::string_view file_name,
absl::string_view content) {
return SetContents(file_name, content, file::Defaults());
absl::Status SetContents(absl::string_view file_name, absl::string_view content,
const file::Options& options) {
// Options are currently ignored.
return SetContents(file_name, content);
}
} // namespace file
+8 -9
View File
@@ -25,23 +25,22 @@ namespace mediapipe {
namespace file {
// Read contents of a file to a std::string.
mediapipe::Status GetContents(absl::string_view file_name, std::string* output,
const file::Options& options);
absl::Status GetContents(absl::string_view file_name, std::string* output,
const file::Options& options);
// Read contents of a file to a std::string with default file options.
mediapipe::Status GetContents(absl::string_view file_name, std::string* output);
absl::Status GetContents(absl::string_view file_name, std::string* output);
// Read contents of a file to a std::string from an open file descriptor.
mediapipe::Status GetContents(int fd, std::string* output);
absl::Status GetContents(int fd, std::string* output);
// Write std::string to file.
mediapipe::Status SetContents(absl::string_view file_name,
absl::string_view content,
const file::Options& options);
absl::Status SetContents(absl::string_view file_name, absl::string_view content,
const file::Options& options);
// Write std::string to file with default file options.
mediapipe::Status SetContents(absl::string_view file_name,
absl::string_view content);
absl::Status SetContents(absl::string_view file_name,
absl::string_view content);
} // namespace file
} // namespace mediapipe
+52 -55
View File
@@ -152,8 +152,7 @@ std::string AvErrorToString(int error) {
}
// Send a packet to the decoder.
mediapipe::Status SendPacket(const AVPacket& packet,
AVCodecContext* avcodec_ctx) {
absl::Status SendPacket(const AVPacket& packet, AVCodecContext* avcodec_ctx) {
const int error = avcodec_send_packet(avcodec_ctx, &packet);
if (error != 0 && error != AVERROR_EOF) {
// Not consider AVERROR_EOF as an error because it can happen when more
@@ -162,12 +161,12 @@ mediapipe::Status SendPacket(const AVPacket& packet,
" (", AvErrorToString(error),
"). Packet size: ", packet.size));
}
return mediapipe::OkStatus();
return absl::OkStatus();
}
// Receive a decoded frame from the decoder.
mediapipe::Status ReceiveFrame(AVCodecContext* avcodec_ctx, AVFrame* frame,
bool* received) {
absl::Status ReceiveFrame(AVCodecContext* avcodec_ctx, AVFrame* frame,
bool* received) {
const int error = avcodec_receive_frame(avcodec_ctx, frame);
*received = error == 0;
if (error != 0 && error != AVERROR_EOF && error != AVERROR(EAGAIN)) {
@@ -177,13 +176,12 @@ mediapipe::Status ReceiveFrame(AVCodecContext* avcodec_ctx, AVFrame* frame,
return UnknownError(absl::StrCat(" Failed to receive frame: error=", error,
" (", AvErrorToString(error), ")."));
}
return mediapipe::OkStatus();
return absl::OkStatus();
}
mediapipe::Status LogStatus(const mediapipe::Status& status,
const AVCodecContext& avcodec_ctx,
const AVPacket& packet,
bool always_return_ok_status) {
absl::Status LogStatus(const absl::Status& status,
const AVCodecContext& avcodec_ctx,
const AVPacket& packet, bool always_return_ok_status) {
if (status.ok()) {
return status;
}
@@ -199,7 +197,7 @@ mediapipe::Status LogStatus(const mediapipe::Status& status,
if (always_return_ok_status) {
LOG(WARNING) << status.message();
return mediapipe::OkStatus();
return absl::OkStatus();
} else {
return status;
}
@@ -228,16 +226,16 @@ BasePacketProcessor::~BasePacketProcessor() { Close(); }
bool BasePacketProcessor::HasData() { return !buffer_.empty(); }
mediapipe::Status BasePacketProcessor::GetData(Packet* packet) {
absl::Status BasePacketProcessor::GetData(Packet* packet) {
CHECK(packet);
CHECK(!buffer_.empty());
*packet = buffer_.front();
buffer_.pop_front();
return mediapipe::OkStatus();
return absl::OkStatus();
}
mediapipe::Status BasePacketProcessor::Flush() {
absl::Status BasePacketProcessor::Flush() {
int64 last_num_frames_processed;
do {
std::unique_ptr<AVPacket, AVPacketDeleter> av_packet(new AVPacket());
@@ -254,7 +252,7 @@ mediapipe::Status BasePacketProcessor::Flush() {
} while (last_num_frames_processed != num_frames_processed_);
flushed_ = true;
return mediapipe::OkStatus();
return absl::OkStatus();
}
void BasePacketProcessor::Close() {
@@ -273,8 +271,8 @@ void BasePacketProcessor::Close() {
}
}
mediapipe::Status BasePacketProcessor::Decode(const AVPacket& packet,
bool ignore_decode_failures) {
absl::Status BasePacketProcessor::Decode(const AVPacket& packet,
bool ignore_decode_failures) {
MP_RETURN_IF_ERROR(LogStatus(SendPacket(packet, avcodec_ctx_), *avcodec_ctx_,
packet, ignore_decode_failures));
while (true) {
@@ -290,7 +288,7 @@ mediapipe::Status BasePacketProcessor::Decode(const AVPacket& packet,
break;
}
}
return mediapipe::OkStatus();
return absl::OkStatus();
}
int64 BasePacketProcessor::CorrectPtsForRollover(int64 media_pts) {
@@ -340,11 +338,11 @@ AudioPacketProcessor::AudioPacketProcessor(const AudioStreamOptions& options)
DCHECK(absl::little_endian::IsLittleEndian());
}
mediapipe::Status AudioPacketProcessor::Open(int id, AVStream* stream) {
absl::Status AudioPacketProcessor::Open(int id, AVStream* stream) {
id_ = id;
avcodec_ = avcodec_find_decoder(stream->codecpar->codec_id);
if (!avcodec_) {
return mediapipe::InvalidArgumentError("Failed to find codec");
return absl::InvalidArgumentError("Failed to find codec");
}
avcodec_ctx_ = avcodec_alloc_context3(avcodec_);
avcodec_parameters_to_context(avcodec_ctx_, stream->codecpar);
@@ -377,17 +375,17 @@ mediapipe::Status AudioPacketProcessor::Open(int id, AVStream* stream) {
id_, num_channels_, sample_rate_, source_time_base_.num,
source_time_base_.den);
return mediapipe::OkStatus();
return absl::OkStatus();
}
mediapipe::Status AudioPacketProcessor::ValidateSampleFormat() {
absl::Status AudioPacketProcessor::ValidateSampleFormat() {
switch (avcodec_ctx_->sample_fmt) {
case AV_SAMPLE_FMT_S16:
case AV_SAMPLE_FMT_S16P:
case AV_SAMPLE_FMT_S32:
case AV_SAMPLE_FMT_FLT:
case AV_SAMPLE_FMT_FLTP:
return mediapipe::OkStatus();
return absl::OkStatus();
default:
return mediapipe::UnimplementedErrorBuilder(MEDIAPIPE_LOC)
<< "sample_fmt = " << avcodec_ctx_->sample_fmt;
@@ -411,7 +409,7 @@ int64 AudioPacketProcessor::SampleNumberToMicroseconds(
return av_rescale_q(sample_number, sample_time_base_, {1, 1000000});
}
mediapipe::Status AudioPacketProcessor::ProcessPacket(AVPacket* packet) {
absl::Status AudioPacketProcessor::ProcessPacket(AVPacket* packet) {
CHECK(packet);
if (flushed_) {
return UnknownError(
@@ -424,8 +422,7 @@ mediapipe::Status AudioPacketProcessor::ProcessPacket(AVPacket* packet) {
return Decode(*packet, options_.ignore_decode_failures());
}
mediapipe::Status AudioPacketProcessor::ProcessDecodedFrame(
const AVPacket& packet) {
absl::Status AudioPacketProcessor::ProcessDecodedFrame(const AVPacket& packet) {
RET_CHECK_EQ(decoded_frame_->channels, num_channels_);
int buf_size_bytes = av_samples_get_buffer_size(nullptr, num_channels_,
decoded_frame_->nb_samples,
@@ -450,7 +447,8 @@ mediapipe::Status AudioPacketProcessor::ProcessDecodedFrame(
SampleNumberToMicroseconds(expected_sample_number_);
const int64 actual_us = TimestampToMicroseconds(pts);
if (absl::Microseconds(std::abs(expected_us - actual_us)) >
absl::Seconds(FLAGS_media_decoder_allowed_audio_gap_merge)) {
absl::Seconds(
absl::GetFlag(FLAGS_media_decoder_allowed_audio_gap_merge))) {
LOG(ERROR) << "The expected time based on how many samples we have seen ("
<< expected_us
<< " microseconds) no longer matches the time based "
@@ -458,8 +456,8 @@ mediapipe::Status AudioPacketProcessor::ProcessDecodedFrame(
<< actual_us
<< " microseconds). The difference is more than "
"--media_decoder_allowed_audio_gap_merge ("
<< absl::FormatDuration(absl::Seconds(
FLAGS_media_decoder_allowed_audio_gap_merge))
<< absl::FormatDuration(absl::Seconds(absl::GetFlag(
FLAGS_media_decoder_allowed_audio_gap_merge)))
<< " microseconds). Resetting the timestamps to track what "
"the audio stream is telling us.";
expected_sample_number_ = TimestampToSampleNumber(pts);
@@ -472,14 +470,14 @@ mediapipe::Status AudioPacketProcessor::ProcessDecodedFrame(
data_ptr, buf_size_bytes));
++num_frames_processed_;
return mediapipe::OkStatus();
return absl::OkStatus();
}
mediapipe::Status AudioPacketProcessor::AddAudioDataToBuffer(
absl::Status AudioPacketProcessor::AddAudioDataToBuffer(
const Timestamp output_timestamp, uint8* const* raw_audio,
int buf_size_bytes) {
if (buf_size_bytes == 0) {
return mediapipe::OkStatus();
return absl::OkStatus();
}
if (buf_size_bytes % (num_channels_ * bytes_per_sample_) != 0) {
@@ -568,15 +566,14 @@ mediapipe::Status AudioPacketProcessor::AddAudioDataToBuffer(
}
expected_sample_number_ += num_samples;
return mediapipe::OkStatus();
return absl::OkStatus();
}
mediapipe::Status AudioPacketProcessor::FillHeader(
TimeSeriesHeader* header) const {
absl::Status AudioPacketProcessor::FillHeader(TimeSeriesHeader* header) const {
CHECK(header);
header->set_sample_rate(sample_rate_);
header->set_num_channels(num_channels_);
return mediapipe::OkStatus();
return absl::OkStatus();
}
int64 AudioPacketProcessor::MaybeCorrectPtsForRollover(int64 media_pts) {
@@ -588,18 +585,18 @@ int64 AudioPacketProcessor::MaybeCorrectPtsForRollover(int64 media_pts) {
AudioDecoder::AudioDecoder() { av_register_all(); }
AudioDecoder::~AudioDecoder() {
mediapipe::Status status = Close();
absl::Status status = Close();
if (!status.ok()) {
LOG(ERROR) << "Encountered error while closing media file: "
<< status.message();
}
}
mediapipe::Status AudioDecoder::Initialize(
absl::Status AudioDecoder::Initialize(
const std::string& input_file,
const mediapipe::AudioDecoderOptions options) {
if (options.audio_stream().empty()) {
return mediapipe::InvalidArgumentError(
return absl::InvalidArgumentError(
"At least one audio_stream must be defined in AudioDecoderOptions");
}
std::map<int, int> stream_index_to_audio_options_index;
@@ -611,7 +608,7 @@ mediapipe::Status AudioDecoder::Initialize(
}
Cleanup<std::function<void()>> decoder_closer([this]() {
mediapipe::Status status = Close();
absl::Status status = Close();
if (!status.ok()) {
LOG(ERROR) << "Encountered error while closing media file: "
<< status.message();
@@ -620,12 +617,12 @@ mediapipe::Status AudioDecoder::Initialize(
avformat_ctx_ = avformat_alloc_context();
if (avformat_open_input(&avformat_ctx_, input_file.c_str(), NULL, NULL) < 0) {
return mediapipe::InvalidArgumentError(
return absl::InvalidArgumentError(
absl::StrCat("Could not open file: ", input_file));
}
if (avformat_find_stream_info(avformat_ctx_, NULL) < 0) {
return mediapipe::InvalidArgumentError(absl::StrCat(
return absl::InvalidArgumentError(absl::StrCat(
"Could not find stream information of file: ", input_file));
}
@@ -686,10 +683,10 @@ mediapipe::Status AudioDecoder::Initialize(
is_first_packet_.resize(avformat_ctx_->nb_streams, true);
decoder_closer.release();
return mediapipe::OkStatus();
return absl::OkStatus();
}
mediapipe::Status AudioDecoder::GetData(int* options_index, Packet* data) {
absl::Status AudioDecoder::GetData(int* options_index, Packet* data) {
while (true) {
for (auto& item : audio_processor_) {
while (item.second && item.second->HasData()) {
@@ -697,7 +694,7 @@ mediapipe::Status AudioDecoder::GetData(int* options_index, Packet* data) {
is_first_packet_[item.first] = false;
*options_index =
FindOrDie(stream_id_to_audio_options_index_, item.first);
mediapipe::Status status = item.second->GetData(data);
absl::Status status = item.second->GetData(data);
// Ignore packets which are out of the requested timestamp range.
if (start_time_ != Timestamp::Unset()) {
if (is_first_packet && data->Timestamp() > start_time_) {
@@ -735,10 +732,10 @@ mediapipe::Status AudioDecoder::GetData(int* options_index, Packet* data) {
}
MP_RETURN_IF_ERROR(ProcessPacket());
}
return mediapipe::OkStatus();
return absl::OkStatus();
}
mediapipe::Status AudioDecoder::Close() {
absl::Status AudioDecoder::Close() {
for (auto& item : audio_processor_) {
if (item.second) {
item.second->Close();
@@ -749,10 +746,10 @@ mediapipe::Status AudioDecoder::Close() {
if (avformat_ctx_) {
avformat_close_input(&avformat_ctx_);
}
return mediapipe::OkStatus();
return absl::OkStatus();
}
mediapipe::Status AudioDecoder::FillAudioHeader(
absl::Status AudioDecoder::FillAudioHeader(
const AudioStreamOptions& stream_option, TimeSeriesHeader* header) const {
const std::unique_ptr<AudioPacketProcessor>* processor_ptr_ = FindOrNull(
audio_processor_,
@@ -760,10 +757,10 @@ mediapipe::Status AudioDecoder::FillAudioHeader(
RET_CHECK(processor_ptr_ && *processor_ptr_) << "audio stream is not open.";
MP_RETURN_IF_ERROR((*processor_ptr_)->FillHeader(header));
return mediapipe::OkStatus();
return absl::OkStatus();
}
mediapipe::Status AudioDecoder::ProcessPacket() {
absl::Status AudioDecoder::ProcessPacket() {
std::unique_ptr<AVPacket, AVPacketDeleter> av_packet(new AVPacket());
av_init_packet(av_packet.get());
av_packet->size = 0;
@@ -785,14 +782,14 @@ mediapipe::Status AudioDecoder::ProcessPacket() {
} else {
VLOG(3) << "Ignoring packet for stream " << stream_id;
}
return mediapipe::OkStatus();
return absl::OkStatus();
}
VLOG(1) << "Demuxing returned error (or EOF): " << AvErrorToString(ret);
if (ret == AVERROR(EAGAIN)) {
// EAGAIN is used to signify that the av_packet should be skipped
// (maybe the demuxer is trying to re-sync). This definitely
// occurs in the FLV and MpegT demuxers.
return mediapipe::OkStatus();
return absl::OkStatus();
}
// Unrecoverable demuxing error with details in avformat_ctx_->pb->error.
@@ -819,8 +816,8 @@ mediapipe::Status AudioDecoder::ProcessPacket() {
"Failed to read a frame: retval = $0 ($1)", ret, AvErrorToString(ret));
}
mediapipe::Status AudioDecoder::Flush() {
std::vector<mediapipe::Status> statuses;
absl::Status AudioDecoder::Flush() {
std::vector<absl::Status> statuses;
for (auto& item : audio_processor_) {
if (item.second) {
statuses.push_back(item.second->Flush());
+23 -23
View File
@@ -50,10 +50,10 @@ class BasePacketProcessor {
virtual ~BasePacketProcessor();
// Opens the codec.
virtual mediapipe::Status Open(int id, AVStream* stream) = 0;
virtual absl::Status Open(int id, AVStream* stream) = 0;
// Processes a packet of data. Caller retains ownership of packet.
virtual mediapipe::Status ProcessPacket(AVPacket* packet) = 0;
virtual absl::Status ProcessPacket(AVPacket* packet) = 0;
// Returns true if the processor has data immediately available
// (without providing more data with ProcessPacket()).
@@ -61,11 +61,11 @@ class BasePacketProcessor {
// Fills packet with the next frame of data. Returns an empty packet
// if there is nothing to return.
mediapipe::Status GetData(Packet* packet);
absl::Status GetData(Packet* packet);
// Once no more AVPackets are available in the file, each stream must
// be flushed to get any remaining frames which the codec is buffering.
mediapipe::Status Flush();
absl::Status Flush();
// Closes the Processor, this does not close the file. You may not
// call ProcessPacket() after calling Close(). Close() may be called
@@ -74,11 +74,11 @@ class BasePacketProcessor {
protected:
// Decodes frames in a packet.
virtual mediapipe::Status Decode(const AVPacket& packet,
bool ignore_decode_failures);
virtual absl::Status Decode(const AVPacket& packet,
bool ignore_decode_failures);
// Processes a decoded frame.
virtual mediapipe::Status ProcessDecodedFrame(const AVPacket& packet) = 0;
virtual absl::Status ProcessDecodedFrame(const AVPacket& packet) = 0;
// Corrects the given PTS for MPEG PTS rollover. Assumed to be called with
// the PTS of each frame in decode order. We detect a rollover whenever the
@@ -132,17 +132,17 @@ class AudioPacketProcessor : public BasePacketProcessor {
public:
explicit AudioPacketProcessor(const AudioStreamOptions& options);
mediapipe::Status Open(int id, AVStream* stream) override;
absl::Status Open(int id, AVStream* stream) override;
mediapipe::Status ProcessPacket(AVPacket* packet) override;
absl::Status ProcessPacket(AVPacket* packet) override;
mediapipe::Status FillHeader(TimeSeriesHeader* header) const;
absl::Status FillHeader(TimeSeriesHeader* header) const;
private:
// Appends audio in buffer(s) to the output buffer (buffer_).
mediapipe::Status AddAudioDataToBuffer(const Timestamp output_timestamp,
uint8* const* raw_audio,
int buf_size_bytes);
absl::Status AddAudioDataToBuffer(const Timestamp output_timestamp,
uint8* const* raw_audio,
int buf_size_bytes);
// Converts a number of samples into an approximate stream timestamp value.
int64 SampleNumberToTimestamp(const int64 sample_number);
@@ -154,11 +154,11 @@ class AudioPacketProcessor : public BasePacketProcessor {
// Returns an error if the sample format in avformat_ctx_.sample_format
// is not supported.
mediapipe::Status ValidateSampleFormat();
absl::Status ValidateSampleFormat();
// Processes a decoded audio frame. audio_frame_ must have been filled
// with the frame before calling this function.
mediapipe::Status ProcessDecodedFrame(const AVPacket& packet) override;
absl::Status ProcessDecodedFrame(const AVPacket& packet) override;
// Corrects PTS for rollover if correction is enabled.
int64 MaybeCorrectPtsForRollover(int64 media_pts);
@@ -194,19 +194,19 @@ class AudioDecoder {
AudioDecoder();
~AudioDecoder();
mediapipe::Status Initialize(const std::string& input_file,
const mediapipe::AudioDecoderOptions options);
absl::Status Initialize(const std::string& input_file,
const mediapipe::AudioDecoderOptions options);
mediapipe::Status GetData(int* options_index, Packet* data);
absl::Status GetData(int* options_index, Packet* data);
mediapipe::Status Close();
absl::Status Close();
mediapipe::Status FillAudioHeader(const AudioStreamOptions& stream_option,
TimeSeriesHeader* header) const;
absl::Status FillAudioHeader(const AudioStreamOptions& stream_option,
TimeSeriesHeader* header) const;
private:
mediapipe::Status ProcessPacket();
mediapipe::Status Flush();
absl::Status ProcessPacket();
absl::Status Flush();
std::map<int, int> stream_id_to_audio_options_index_;
std::map<int, int> stream_index_to_stream_id_;
+7 -7
View File
@@ -38,18 +38,18 @@ namespace {
constexpr uint32 kBufferLength = 64;
mediapipe::StatusOr<std::string> GetFilePath(int cpu) {
absl::StatusOr<std::string> GetFilePath(int cpu) {
return absl::Substitute(
"/sys/devices/system/cpu/cpu$0/cpufreq/cpuinfo_max_freq", cpu);
}
mediapipe::StatusOr<uint64> GetCpuMaxFrequency(int cpu) {
absl::StatusOr<uint64> GetCpuMaxFrequency(int cpu) {
auto path_or_status = GetFilePath(cpu);
if (!path_or_status.ok()) {
return path_or_status.status();
}
std::ifstream file;
file.open(path_or_status.ValueOrDie());
file.open(path_or_status.value());
if (file.is_open()) {
char buffer[kBufferLength];
file.getline(buffer, kBufferLength);
@@ -58,12 +58,12 @@ mediapipe::StatusOr<uint64> GetCpuMaxFrequency(int cpu) {
if (absl::SimpleAtoi(buffer, &frequency)) {
return frequency;
} else {
return mediapipe::InvalidArgumentError(
return absl::InvalidArgumentError(
absl::StrCat("Invalid frequency: ", buffer));
}
} else {
return mediapipe::NotFoundError(
absl::StrCat("Couldn't read ", path_or_status.ValueOrDie()));
return absl::NotFoundError(
absl::StrCat("Couldn't read ", path_or_status.value()));
}
}
@@ -72,7 +72,7 @@ std::set<int> InferLowerOrHigherCoreIds(bool lower) {
for (int cpu = 0; cpu < NumCPUCores(); ++cpu) {
auto freq_or_status = GetCpuMaxFrequency(cpu);
if (freq_or_status.ok()) {
cpu_freq_pairs.push_back({cpu, freq_or_status.ValueOrDie()});
cpu_freq_pairs.push_back({cpu, freq_or_status.value()});
}
}
if (cpu_freq_pairs.empty()) {
+6 -6
View File
@@ -19,8 +19,8 @@
namespace mediapipe {
mediapipe::Status CopyInputHeadersToOutputs(const InputStreamSet& inputs,
const OutputStreamSet& outputs) {
absl::Status CopyInputHeadersToOutputs(const InputStreamSet& inputs,
const OutputStreamSet& outputs) {
for (auto id = inputs.BeginId(); id < inputs.EndId(); ++id) {
std::pair<std::string, int> tag_index = inputs.TagAndIndexFromId(id);
auto output_id = outputs.GetId(tag_index.first, tag_index.second);
@@ -29,11 +29,11 @@ mediapipe::Status CopyInputHeadersToOutputs(const InputStreamSet& inputs,
}
}
return mediapipe::OkStatus();
return absl::OkStatus();
}
mediapipe::Status CopyInputHeadersToOutputs(const InputStreamShardSet& inputs,
OutputStreamShardSet* outputs) {
absl::Status CopyInputHeadersToOutputs(const InputStreamShardSet& inputs,
OutputStreamShardSet* outputs) {
for (auto id = inputs.BeginId(); id < inputs.EndId(); ++id) {
std::pair<std::string, int> tag_index = inputs.TagAndIndexFromId(id);
auto output_id = outputs->GetId(tag_index.first, tag_index.second);
@@ -42,7 +42,7 @@ mediapipe::Status CopyInputHeadersToOutputs(const InputStreamShardSet& inputs,
}
}
return mediapipe::OkStatus();
return absl::OkStatus();
}
} // namespace mediapipe
+4 -4
View File
@@ -22,11 +22,11 @@ namespace mediapipe {
// Copies headers from |inputs| into |outputs| respectively. The size of
// |inputs| and |outputs| must be equal.
mediapipe::Status CopyInputHeadersToOutputs(const InputStreamSet& inputs,
const OutputStreamSet& outputs);
absl::Status CopyInputHeadersToOutputs(const InputStreamSet& inputs,
const OutputStreamSet& outputs);
mediapipe::Status CopyInputHeadersToOutputs(const InputStreamShardSet& inputs,
OutputStreamShardSet* outputs);
absl::Status CopyInputHeadersToOutputs(const InputStreamShardSet& inputs,
OutputStreamShardSet* outputs);
} // namespace mediapipe
+4 -5
View File
@@ -27,14 +27,13 @@ ABSL_FLAG(
namespace mediapipe {
mediapipe::StatusOr<std::string> PathToResourceAsFile(const std::string& path) {
return mediapipe::file::JoinPath(FLAGS_resource_root_dir.CurrentValue(),
absl::StatusOr<std::string> PathToResourceAsFile(const std::string& path) {
return mediapipe::file::JoinPath(absl::GetFlag(FLAGS_resource_root_dir),
path);
}
mediapipe::Status GetResourceContents(const std::string& path,
std::string* output,
bool read_as_binary) {
absl::Status GetResourceContents(const std::string& path, std::string* output,
bool read_as_binary) {
return mediapipe::file::GetContents(path, output, read_as_binary);
}
+3 -4
View File
@@ -39,13 +39,12 @@ namespace mediapipe {
// accepts file paths. Code that can access data as a stream or as a buffer
// should read from an asset directly on Android; an API for this will be
// provided later. TODO.
mediapipe::StatusOr<std::string> PathToResourceAsFile(const std::string& path);
absl::StatusOr<std::string> PathToResourceAsFile(const std::string& path);
// Reads the entire contents of a resource. The search path is as in
// PathToResourceAsFile.
mediapipe::Status GetResourceContents(const std::string& path,
std::string* output,
bool read_as_binary = true);
absl::Status GetResourceContents(const std::string& path, std::string* output,
bool read_as_binary = true);
} // namespace mediapipe
+20 -9
View File
@@ -15,6 +15,7 @@
#include <vector>
#include "absl/strings/match.h"
#include "mediapipe/framework/port/file_helpers.h"
#include "mediapipe/framework/port/ret_check.h"
#include "mediapipe/framework/port/singleton.h"
#include "mediapipe/util/android/asset_manager_util.h"
@@ -24,13 +25,13 @@
namespace mediapipe {
namespace {
mediapipe::StatusOr<std::string> PathToResourceAsFileInternal(
absl::StatusOr<std::string> PathToResourceAsFileInternal(
const std::string& path) {
return Singleton<AssetManager>::get()->CachedFileFromAsset(path);
}
} // namespace
mediapipe::StatusOr<std::string> PathToResourceAsFile(const std::string& path) {
absl::StatusOr<std::string> PathToResourceAsFile(const std::string& path) {
// Return full path.
if (absl::StartsWith(path, "/")) {
return path;
@@ -51,14 +52,24 @@ mediapipe::StatusOr<std::string> PathToResourceAsFile(const std::string& path) {
CHECK_NE(last_slash_idx, std::string::npos); // Make sure it's a path.
auto base_name = path.substr(last_slash_idx + 1);
auto status_or_path = PathToResourceAsFileInternal(base_name);
if (status_or_path.ok()) LOG(INFO) << "Successfully loaded: " << base_name;
return status_or_path;
if (status_or_path.ok()) {
LOG(INFO) << "Successfully loaded: " << base_name;
return status_or_path;
}
}
// Try the test environment.
absl::string_view workspace = "mediapipe";
auto test_path = file::JoinPath(std::getenv("TEST_SRCDIR"), workspace, path);
if (file::Exists(test_path).ok()) {
return test_path;
}
return path;
}
mediapipe::Status GetResourceContents(const std::string& path,
std::string* output,
bool read_as_binary) {
absl::Status GetResourceContents(const std::string& path, std::string* output,
bool read_as_binary) {
if (!read_as_binary) {
LOG(WARNING)
<< "Setting \"read_as_binary\" to false is a no-op on Android.";
@@ -70,12 +81,12 @@ mediapipe::Status GetResourceContents(const std::string& path,
if (absl::StartsWith(path, "content://")) {
MP_RETURN_IF_ERROR(
Singleton<AssetManager>::get()->ReadContentUri(path, output));
return mediapipe::OkStatus();
return absl::OkStatus();
}
RET_CHECK(Singleton<AssetManager>::get()->ReadFile(path, output))
<< "could not read asset: " << path;
return mediapipe::OkStatus();
return absl::OkStatus();
}
} // namespace mediapipe
+25 -8
View File
@@ -18,13 +18,14 @@
#include <sstream>
#include "absl/strings/match.h"
#include "mediapipe/framework/port/file_helpers.h"
#include "mediapipe/framework/port/ret_check.h"
#include "mediapipe/util/resource_util.h"
namespace mediapipe {
namespace {
mediapipe::StatusOr<std::string> PathToResourceAsFileInternal(
absl::StatusOr<std::string> PathToResourceAsFileInternal(
const std::string& path) {
NSString* ns_path = [NSString stringWithUTF8String:path.c_str()];
Class mediapipeGraphClass = NSClassFromString(@"MPPGraph");
@@ -39,7 +40,7 @@ mediapipe::StatusOr<std::string> PathToResourceAsFileInternal(
}
} // namespace
mediapipe::StatusOr<std::string> PathToResourceAsFile(const std::string& path) {
absl::StatusOr<std::string> PathToResourceAsFile(const std::string& path) {
// Return full path.
if (absl::StartsWith(path, "/")) {
return path;
@@ -60,14 +61,30 @@ mediapipe::StatusOr<std::string> PathToResourceAsFile(const std::string& path) {
CHECK_NE(last_slash_idx, std::string::npos); // Make sure it's a path.
auto base_name = path.substr(last_slash_idx + 1);
auto status_or_path = PathToResourceAsFileInternal(base_name);
if (status_or_path.ok()) LOG(INFO) << "Successfully loaded: " << base_name;
return status_or_path;
if (status_or_path.ok()) {
LOG(INFO) << "Successfully loaded: " << base_name;
return status_or_path;
}
}
// Try the test environment.
{
absl::string_view workspace = "mediapipe";
auto test_path =
file::JoinPath(std::getenv("TEST_SRCDIR"), workspace, path);
if ([[NSFileManager defaultManager]
fileExistsAtPath:[NSString
stringWithUTF8String:test_path.c_str()]]) {
LOG(INFO) << "Successfully loaded: " << test_path;
return test_path;
}
}
return path;
}
mediapipe::Status GetResourceContents(const std::string& path,
std::string* output,
bool read_as_binary) {
absl::Status GetResourceContents(const std::string& path, std::string* output,
bool read_as_binary) {
if (!read_as_binary) {
LOG(WARNING) << "Setting \"read_as_binary\" to false is a no-op on ios.";
}
@@ -77,7 +94,7 @@ mediapipe::Status GetResourceContents(const std::string& path,
std::stringstream buffer;
buffer << input_file.rdbuf();
buffer.str().swap(*output);
return mediapipe::OkStatus();
return absl::OkStatus();
}
} // namespace mediapipe
+18
View File
@@ -548,3 +548,21 @@ where the STFT is computed over audio at some other rate.
|`PREFIX/feature/packet_rate`|context float|`set_feature_packet_rate` / `SetFeaturePacketRate`|The number of packets per second.|
|`PREFIX/feature/audio_sample_rate`|context float|`set_feature_audio_sample_rate` / `SetFeatureAudioSampleRate`|The sample rate of the original audio for derived features.|
### Keys related to text, captions, and ASR
Text features may be timed with the media such as captions or automatic
speech recognition results, or may be descriptions. This collection of keys
should be used for many, very short text features. For a few, longer segments
please use the Segment keys in the context as described above. As always,
prefixes can be used to store different types of text such as automated and
ground truth transcripts.
| key | type | python call / c++ call | description |
|-----|------|------------------------|-------------|
|`text/language`|context bytes|`set_text_langage` / `SetTextLanguage`|The language for the corresponding text.|
|`text/context/content`|context bytes|`set_text_context_content` / `SetTextContextContent`|Storage for large blocks of text in the context.|
|`text/content`|feature list bytes|`add_text_content` / `AddTextContent`|One (or a few) text tokens that occur at one timestamp.|
|`text/timestamp`|feature list int|`add_text_timestamp` / `AddTextTimestamp`|When a text token occurs in microseconds.|
|`text/duration`|feature list int|`add_text_duration` / `SetTextDuration`|The duration in microseconds for the corresponding text tokens.|
|`text/confidence`|feature list float|`add_text_confidence` / `AddTextConfidence`|How likely the text is correct.|
|`text/embedding`|feautre list float list|`add_text_embedding` / `AddTextEmbedding`|A floating point vector for the corresponding text token.|
|`text/token/id`|feature list int|`add_text_token_id` / `AddTextTokenId`|An integer id for the corresponding text token.|
+18 -17
View File
@@ -85,10 +85,10 @@ float TimestampsToRate(int64 first_timestamp, int64 second_timestamp) {
// "segment/start/index" and "segment/end/index" by finding the closest
// timestamps in the "image/timestamp" FeatureList if image timestamps are
// present.
::mediapipe::Status ReconcileAnnotationIndicesByImageTimestamps(
absl::Status ReconcileAnnotationIndicesByImageTimestamps(
tensorflow::SequenceExample* sequence) {
if (GetImageTimestampSize(*sequence) == 0) {
return ::mediapipe::OkStatus();
return absl::OkStatus();
}
int index;
@@ -118,15 +118,15 @@ float TimestampsToRate(int64 first_timestamp, int64 second_timestamp) {
}
SetSegmentEndIndex(end_indices, sequence);
}
return ::mediapipe::OkStatus();
return absl::OkStatus();
}
// Sets the values of "image/format", "image/channels", "image/height",
// "image/width", and "image/frame_rate" based image metadata and timestamps.
::mediapipe::Status ReconcileMetadataImages(
const std::string& prefix, tensorflow::SequenceExample* sequence) {
absl::Status ReconcileMetadataImages(const std::string& prefix,
tensorflow::SequenceExample* sequence) {
if (GetImageEncodedSize(prefix, *sequence) == 0) {
return ::mediapipe::OkStatus();
return absl::OkStatus();
}
std::string format;
int height, width, channels;
@@ -144,7 +144,7 @@ float TimestampsToRate(int64 first_timestamp, int64 second_timestamp) {
GetImageTimestampAt(prefix, *sequence, 1));
SetImageFrameRate(prefix, rate, sequence);
}
return ::mediapipe::OkStatus();
return absl::OkStatus();
}
// Sets the values of "feature/${TAG}/dimensions", and
@@ -152,7 +152,7 @@ float TimestampsToRate(int64 first_timestamp, int64 second_timestamp) {
// dimensions are already present as a context feature, this method verifies
// the number of elements in the feature. Otherwise, it will write the
// dimensions as a 1D vector with the number of elements.
::mediapipe::Status ReconcileMetadataFeatureFloats(
absl::Status ReconcileMetadataFeatureFloats(
tensorflow::SequenceExample* sequence) {
// Loop through all keys and see if they contain "/feature/floats"
// If so, check dimensions and set rate.
@@ -182,7 +182,7 @@ float TimestampsToRate(int64 first_timestamp, int64 second_timestamp) {
}
}
}
return ::mediapipe::OkStatus();
return absl::OkStatus();
}
// Go through all bounding box annotations and move the annotation to the
@@ -190,7 +190,7 @@ float TimestampsToRate(int64 first_timestamp, int64 second_timestamp) {
// nothing. If two or more annotations are closest to the same frame, then only
// the closest annotation is saved. This matches the behavior of downsampling
// images streams in time.
::mediapipe::Status ReconcileMetadataBoxAnnotations(
absl::Status ReconcileMetadataBoxAnnotations(
const std::string& prefix, tensorflow::SequenceExample* sequence) {
int num_bboxes = GetBBoxTimestampSize(prefix, *sequence);
int num_frames = GetImageTimestampSize(*sequence);
@@ -355,10 +355,10 @@ float TimestampsToRate(int64 first_timestamp, int64 second_timestamp) {
}
}
}
return ::mediapipe::OkStatus();
return absl::OkStatus();
}
::mediapipe::Status ReconcileMetadataRegionAnnotations(
absl::Status ReconcileMetadataRegionAnnotations(
tensorflow::SequenceExample* sequence) {
// Copy keys for fixed iteration order while updating feature_lists.
std::vector<const std::string*> key_ptrs;
@@ -376,7 +376,7 @@ float TimestampsToRate(int64 first_timestamp, int64 second_timestamp) {
RET_CHECK_OK(ReconcileMetadataBoxAnnotations(prefix, sequence));
}
}
return ::mediapipe::OkStatus();
return absl::OkStatus();
}
} // namespace
@@ -393,6 +393,7 @@ std::vector<::mediapipe::Location> GetBBoxAt(
const auto& ymins = GetBBoxYMinAt(prefix, sequence, index);
const auto& xmaxs = GetBBoxXMaxAt(prefix, sequence, index);
const auto& ymaxs = GetBBoxYMaxAt(prefix, sequence, index);
bboxes.reserve(xmins.size());
for (int i = 0; i < xmins.size(); ++i) {
bboxes.push_back(::mediapipe::Location::CreateRelativeBBoxLocation(
xmins[i], ymins[i], xmaxs[i] - xmins[i], ymaxs[i] - ymins[i]));
@@ -537,9 +538,9 @@ void AddAudioAsFeature(const std::string& prefix,
.Swap(value_list);
}
::mediapipe::Status ReconcileMetadata(bool reconcile_bbox_annotations,
bool reconcile_region_annotations,
tensorflow::SequenceExample* sequence) {
absl::Status ReconcileMetadata(bool reconcile_bbox_annotations,
bool reconcile_region_annotations,
tensorflow::SequenceExample* sequence) {
RET_CHECK_OK(ReconcileAnnotationIndicesByImageTimestamps(sequence));
RET_CHECK_OK(ReconcileMetadataImages("", sequence));
RET_CHECK_OK(ReconcileMetadataImages(kForwardFlowPrefix, sequence));
@@ -553,7 +554,7 @@ void AddAudioAsFeature(const std::string& prefix,
RET_CHECK_OK(ReconcileMetadataRegionAnnotations(sequence));
}
// audio is always reconciled in the framework.
return ::mediapipe::OkStatus();
return absl::OkStatus();
}
} // namespace mediasequence
+33 -3
View File
@@ -614,6 +614,36 @@ PREFIXED_IMAGE(ForwardFlow, kForwardFlowPrefix);
PREFIXED_IMAGE(ClassSegmentation, kClassSegmentationPrefix);
PREFIXED_IMAGE(InstanceSegmentation, kInstanceSegmentationPrefix);
// ************************** TEXT ****************************************
// Context keys:
// Which language text tokens are likely to be in.
const char kTextLanguageKey[] = "text/language";
// A large block of text that applies to the media.
const char kTextContextContentKey[] = "text/context/content";
// Feature list keys:
// The text contents for a given time.
const char kTextContentKey[] = "text/content";
// The start time for the text becoming relevant.
const char kTextTimestampKey[] = "text/timestamp";
// The duration where the text is relevant.
const char kTextDurationKey[] = "text/duration";
// The confidence that this is the correct text.
const char kTextConfidenceKey[] = "text/confidence";
// A floating point embedding corresponding to the text.
const char kTextEmbeddingKey[] = "text/embedding";
// An integer id corresponding to the text.
const char kTextTokenIdKey[] = "text/token/id";
BYTES_CONTEXT_FEATURE(TextLanguage, kTextLanguageKey);
BYTES_CONTEXT_FEATURE(TextContextContent, kTextContextContentKey);
BYTES_FEATURE_LIST(TextContent, kTextContentKey);
INT64_FEATURE_LIST(TextTimestamp, kTextTimestampKey);
INT64_FEATURE_LIST(TextDuration, kTextDurationKey);
FLOAT_FEATURE_LIST(TextConfidence, kTextConfidenceKey);
VECTOR_FLOAT_FEATURE_LIST(TextEmbedding, kTextEmbeddingKey);
INT64_FEATURE_LIST(TextTokenId, kTextTokenIdKey);
// *********************** FEATURES *************************************
// Context keys:
// The dimensions of the feature.
@@ -691,9 +721,9 @@ PREFIXED_FLOAT_CONTEXT_FEATURE(FeatureAudioSampleRate,
// code verifies the number of elements matches the dimensions.
// Reconciling bounding box annotations is optional because will remove
// annotations if the sequence rate is lower than the annotation rate.
::mediapipe::Status ReconcileMetadata(bool reconcile_bbox_annotations,
bool reconcile_region_annotations,
tensorflow::SequenceExample* sequence);
absl::Status ReconcileMetadata(bool reconcile_bbox_annotations,
bool reconcile_region_annotations,
tensorflow::SequenceExample* sequence);
} // namespace mediasequence
} // namespace mediapipe
+52 -17
View File
@@ -149,13 +149,12 @@ identify common storage patterns (e.g. storing an image along with the height
and width) under different names (e.g. storing a left and right image in a
stereo pair.) An example creating functions such as
add_left_image_encoded that adds a string under the key "LEFT/image/encoded"
add_left_image_encoded = functools.partial(add_image_encoded, prefix="LEFT")
add_left_image_encoded = msu.function_with_default(add_image_encoded, "LEFT")
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import functools
import numpy as np
from mediapipe.util.sequence import media_sequence_util
msu = media_sequence_util
@@ -463,39 +462,39 @@ def _create_region_with_prefix(name, prefix):
# pylint: enable=undefined-variable
msu.add_functions_to_module({
"get_" + name + "_at":
functools.partial(get_prefixed_bbox_at, prefix=prefix),
msu.function_with_default(get_prefixed_bbox_at, prefix),
"add_" + name:
functools.partial(add_prefixed_bbox, prefix=prefix),
msu.function_with_default(add_prefixed_bbox, prefix),
"get_" + name + "_size":
functools.partial(get_prefixed_bbox_size, prefix=prefix),
msu.function_with_default(get_prefixed_bbox_size, prefix),
"has_" + name:
functools.partial(has_prefixed_bbox, prefix=prefix),
msu.function_with_default(has_prefixed_bbox, prefix),
"clear_" + name:
functools.partial(clear_prefixed_bbox, prefix=prefix),
msu.function_with_default(clear_prefixed_bbox, prefix),
}, module_dict=globals())
msu.add_functions_to_module({
"get_" + name + "_point_at":
functools.partial(get_prefixed_point_at, prefix=prefix),
msu.function_with_default(get_prefixed_point_at, prefix),
"add_" + name + "_point":
functools.partial(add_prefixed_point, prefix=prefix),
msu.function_with_default(add_prefixed_point, prefix),
"get_" + name + "_point_size":
functools.partial(get_prefixed_point_size, prefix=prefix),
msu.function_with_default(get_prefixed_point_size, prefix),
"has_" + name + "_point":
functools.partial(has_prefixed_point, prefix=prefix),
msu.function_with_default(has_prefixed_point, prefix),
"clear_" + name + "_point":
functools.partial(clear_prefixed_point, prefix=prefix),
msu.function_with_default(clear_prefixed_point, prefix),
}, module_dict=globals())
msu.add_functions_to_module({
"get_" + name + "_3d_point_at":
functools.partial(get_prefixed_3d_point_at, prefix=prefix),
msu.function_with_default(get_prefixed_3d_point_at, prefix),
"add_" + name + "_3d_point":
functools.partial(add_prefixed_3d_point, prefix=prefix),
msu.function_with_default(add_prefixed_3d_point, prefix),
"get_" + name + "_3d_point_size":
functools.partial(get_prefixed_3d_point_size, prefix=prefix),
msu.function_with_default(get_prefixed_3d_point_size, prefix),
"has_" + name + "_3d_point":
functools.partial(has_prefixed_3d_point, prefix=prefix),
msu.function_with_default(has_prefixed_3d_point, prefix),
"clear_" + name + "_3d_point":
functools.partial(clear_prefixed_3d_point, prefix=prefix),
msu.function_with_default(clear_prefixed_3d_point, prefix),
}, module_dict=globals())
@@ -580,6 +579,42 @@ _create_image_with_prefix("forward_flow", FORWARD_FLOW_PREFIX)
_create_image_with_prefix("class_segmentation", CLASS_SEGMENTATION_PREFIX)
_create_image_with_prefix("instance_segmentation", INSTANCE_SEGMENTATION_PREFIX)
################################## TEXT #################################
# Which language text tokens are likely to be in.
TEXT_LANGUAGE_KEY = "text/language"
# A large block of text that applies to the media.
TEXT_CONTEXT_CONTENT_KEY = "text/context/content"
# The text contents for a given time.
TEXT_CONTENT_KEY = "text/content"
# The start time for the text becoming relevant.
TEXT_TIMESTAMP_KEY = "text/timestamp"
# The duration where the text is relevant.
TEXT_DURATION_KEY = "text/duration"
# The confidence that this is the correct text.
TEXT_CONFIDENCE_KEY = "text/confidence"
# A floating point embedding corresponding to the text.
TEXT_EMBEDDING_KEY = "text/embedding"
# An integer id corresponding to the text.
TEXT_TOKEN_ID_KEY = "text/token/id"
msu.create_bytes_context_feature(
"text_language", TEXT_LANGUAGE_KEY, module_dict=globals())
msu.create_bytes_context_feature(
"text_context_content", TEXT_CONTEXT_CONTENT_KEY, module_dict=globals())
msu.create_bytes_feature_list(
"text_content", TEXT_CONTENT_KEY, module_dict=globals())
msu.create_int_feature_list(
"text_timestamp", TEXT_TIMESTAMP_KEY, module_dict=globals())
msu.create_int_feature_list(
"text_duration", TEXT_DURATION_KEY, module_dict=globals())
msu.create_float_feature_list(
"text_confidence", TEXT_CONFIDENCE_KEY, module_dict=globals())
msu.create_float_list_feature_list(
"text_embedding", TEXT_EMBEDDING_KEY, module_dict=globals())
msu.create_int_feature_list(
"text_token_id", TEXT_TOKEN_ID_KEY, module_dict=globals())
################################## FEATURES #################################
# The dimensions of the feature.
FEATURE_DIMENSIONS_KEY = "feature/dimensions"
@@ -640,6 +640,90 @@ TEST(MediaSequenceTest, RoundTripOpticalFlowTimestamp) {
ASSERT_EQ(GetForwardFlowTimestampSize(sequence), 0);
}
TEST(MediaSequenceTest, RoundTripTextLanguage) {
tensorflow::SequenceExample sequence;
ASSERT_FALSE(HasTextLanguage(sequence));
SetTextLanguage("test", &sequence);
ASSERT_TRUE(HasTextLanguage(sequence));
ASSERT_EQ("test", GetTextLanguage(sequence));
ClearTextLanguage(&sequence);
ASSERT_FALSE(HasTextLanguage(sequence));
}
TEST(MediaSequenceTest, RoundTripTextContextContent) {
tensorflow::SequenceExample sequence;
ASSERT_FALSE(HasTextContextContent(sequence));
SetTextContextContent("test", &sequence);
ASSERT_TRUE(HasTextContextContent(sequence));
ASSERT_EQ("test", GetTextContextContent(sequence));
ClearTextContextContent(&sequence);
ASSERT_FALSE(HasTextContextContent(sequence));
}
TEST(MediaSequenceTest, RoundTripTextContent) {
tensorflow::SequenceExample sequence;
std::vector<std::string> text = {"test", "again"};
for (int i = 0; i < text.size(); ++i) {
AddTextContent(text[i], &sequence);
ASSERT_EQ(GetTextContentSize(sequence), i + 1);
ASSERT_EQ(GetTextContentAt(sequence, i), text[i]);
}
ClearTextContent(&sequence);
ASSERT_EQ(GetTextContentSize(sequence), 0);
}
TEST(MediaSequenceTest, RoundTripTextDuration) {
tensorflow::SequenceExample sequence;
std::vector<int64> timestamps = {4, 7};
for (int i = 0; i < timestamps.size(); ++i) {
AddTextTimestamp(timestamps[i], &sequence);
ASSERT_EQ(GetTextTimestampSize(sequence), i + 1);
ASSERT_EQ(GetTextTimestampAt(sequence, i), timestamps[i]);
}
ClearTextTimestamp(&sequence);
ASSERT_EQ(GetTextTimestampSize(sequence), 0);
}
TEST(MediaSequenceTest, RoundTripTextConfidence) {
tensorflow::SequenceExample sequence;
std::vector<float> confidence = {0.25, 1.0};
for (int i = 0; i < confidence.size(); ++i) {
AddTextConfidence(confidence[i], &sequence);
ASSERT_EQ(GetTextConfidenceSize(sequence), i + 1);
ASSERT_EQ(GetTextConfidenceAt(sequence, i), confidence[i]);
}
ClearTextConfidence(&sequence);
ASSERT_EQ(GetTextConfidenceSize(sequence), 0);
}
TEST(MediaSequenceTest, RoundTripTextEmbedding) {
tensorflow::SequenceExample sequence;
int num_features = 3;
int num_floats_in_feature = 4;
for (int i = 0; i < num_features; ++i) {
std::vector<float> vf(num_floats_in_feature, 2 << i);
AddTextEmbedding(vf, &sequence);
ASSERT_EQ(GetTextEmbeddingSize(sequence), i + 1);
for (float value : GetTextEmbeddingAt(sequence, i)) {
ASSERT_EQ(value, 2 << i);
}
}
ClearTextEmbedding(&sequence);
ASSERT_EQ(GetTextEmbeddingSize(sequence), 0);
}
TEST(MediaSequenceTest, RoundTripTextTokenId) {
tensorflow::SequenceExample sequence;
std::vector<int64> ids = {4, 7};
for (int i = 0; i < ids.size(); ++i) {
AddTextTokenId(ids[i], &sequence);
ASSERT_EQ(GetTextTokenIdSize(sequence), i + 1);
ASSERT_EQ(GetTextTokenIdAt(sequence, i), ids[i]);
}
ClearTextTokenId(&sequence);
ASSERT_EQ(GetTextTokenIdSize(sequence), 0);
}
TEST(MediaSequenceTest, ReconcileMetadataOnEmptySequence) {
tensorflow::SequenceExample sequence;
MP_ASSERT_OK(ReconcileMetadata(true, false, &sequence));
@@ -123,6 +123,14 @@ class MediaSequenceTest(tf.test.TestCase):
ms.add_bbox_embedding_floats((0.47, 0.49), example)
ms.add_bbox_embedding_encoded((b"text", b"stings"), example)
ms.add_bbox_embedding_confidence((0.47, 0.49), example)
ms.set_text_language(b"test", example)
ms.set_text_context_content(b"text", example)
ms.add_text_content(b"one", example)
ms.add_text_timestamp(47, example)
ms.add_text_confidence(0.47, example)
ms.add_text_duration(47, example)
ms.add_text_token_id(47, example)
ms.add_text_embedding((0.47, 0.49), example)
def test_bbox_round_trip(self):
example = tf.train.SequenceExample()
@@ -149,6 +157,18 @@ class MediaSequenceTest(tf.test.TestCase):
ms.clear_bbox_point(example)
self.assertEqual(0, ms.get_bbox_point_size(example))
def test_prefixed_point_round_trip(self):
example = tf.train.SequenceExample()
points = np.array([[0.1, 0.2],
[0.5, 0.6]])
ms.add_bbox_point(points, example, "test")
ms.add_bbox_point(points, example, "test")
self.assertEqual(2, ms.get_bbox_point_size(example, "test"))
self.assertAllClose(points, ms.get_bbox_point_at(0, example, "test"))
self.assertTrue(ms.has_bbox_point(example, "test"))
ms.clear_bbox_point(example, "test")
self.assertEqual(0, ms.get_bbox_point_size(example, "test"))
def test_3d_point_round_trip(self):
example = tf.train.SequenceExample()
points = np.array([[0.1, 0.2, 0.3],
@@ -22,10 +22,16 @@ from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import types
import tensorflow.compat.v1 as tf
def function_with_default(f, default):
"""Creates a new function with a default last parameter."""
return types.FunctionType(f.__code__, f.__globals__, f.__name__,
(default,), f.__closure__)
def add_functions_to_module(function_dict, module_dict=None):
"""Adds functions to another module.
+1 -1
View File
@@ -201,7 +201,7 @@ Status TensorsToDetections(const ::tensorflow::Tensor& num_detections,
}
detections->emplace_back(detection);
}
return mediapipe::OkStatus();
return absl::OkStatus();
}
} // namespace mediapipe
+15 -13
View File
@@ -28,21 +28,23 @@ Detection TensorToDetection(
const ::tensorflow::TTypes<const float>::Vec& box, float score,
const ::absl::variant<int, std::string>& class_label);
mediapipe::Status TensorsToDetections(
const ::tensorflow::Tensor& num_detections,
const ::tensorflow::Tensor& boxes, const ::tensorflow::Tensor& scores,
const ::tensorflow::Tensor& classes,
const std::map<int, std::string>& label_map,
std::vector<Detection>* detections);
absl::Status TensorsToDetections(const ::tensorflow::Tensor& num_detections,
const ::tensorflow::Tensor& boxes,
const ::tensorflow::Tensor& scores,
const ::tensorflow::Tensor& classes,
const std::map<int, std::string>& label_map,
std::vector<Detection>* detections);
// Use this version if keypoints or masks are available.
mediapipe::Status TensorsToDetections(
const ::tensorflow::Tensor& num_detections,
const ::tensorflow::Tensor& boxes, const ::tensorflow::Tensor& scores,
const ::tensorflow::Tensor& classes, const ::tensorflow::Tensor& keypoints,
const ::tensorflow::Tensor& masks, float mask_threshold,
const std::map<int, std::string>& label_map,
std::vector<Detection>* detections);
absl::Status TensorsToDetections(const ::tensorflow::Tensor& num_detections,
const ::tensorflow::Tensor& boxes,
const ::tensorflow::Tensor& scores,
const ::tensorflow::Tensor& classes,
const ::tensorflow::Tensor& keypoints,
const ::tensorflow::Tensor& masks,
float mask_threshold,
const std::map<int, std::string>& label_map,
std::vector<Detection>* detections);
} // namespace mediapipe
#endif // MEDIAPIPE_TENSORFLOW_UTIL_TENSOR_TO_DETECTION_H_
+1 -1
View File
@@ -104,7 +104,7 @@ cc_library(
srcs = ["tflite_model_loader.cc"],
hdrs = ["tflite_model_loader.h"],
deps = [
"//mediapipe/framework:packet",
"//mediapipe/framework/api2:packet",
"//mediapipe/framework/port:ret_check",
"//mediapipe/framework/port:status",
"//mediapipe/framework/port:statusor",
+12 -12
View File
@@ -83,7 +83,7 @@ ObjectDef GetSSBOObjectDef(int channels) {
} // namespace
mediapipe::Status TFLiteGPURunner::InitializeWithModel(
absl::Status TFLiteGPURunner::InitializeWithModel(
const tflite::FlatBufferModel& flatbuffer,
const tflite::OpResolver& op_resolver) {
// GraphFloat32 is created twice because, when OpenCL and OpenGL backends are
@@ -111,23 +111,23 @@ mediapipe::Status TFLiteGPURunner::InitializeWithModel(
return absl::OkStatus();
}
mediapipe::StatusOr<int64_t> TFLiteGPURunner::GetInputElements(int id) {
absl::StatusOr<int64_t> TFLiteGPURunner::GetInputElements(int id) {
if (id >= input_shapes_.size()) {
return mediapipe::InternalError("Wrong input tensor id.");
return absl::InternalError("Wrong input tensor id.");
} else {
return input_shapes_[id].DimensionsProduct();
}
}
mediapipe::StatusOr<int64_t> TFLiteGPURunner::GetOutputElements(int id) {
absl::StatusOr<int64_t> TFLiteGPURunner::GetOutputElements(int id) {
if (id >= output_shapes_.size()) {
return mediapipe::InternalError("Wrong output tensor id.");
return absl::InternalError("Wrong output tensor id.");
} else {
return output_shapes_[id].DimensionsProduct();
}
}
mediapipe::Status TFLiteGPURunner::Build() {
absl::Status TFLiteGPURunner::Build() {
// 1. Prepare inference builder.
std::unique_ptr<InferenceBuilder> builder;
// By default, we try CL first & fall back to GL if that fails.
@@ -164,23 +164,23 @@ mediapipe::Status TFLiteGPURunner::Build() {
return builder->Build(&runner_);
}
mediapipe::Status TFLiteGPURunner::BindSSBOToInputTensor(GLuint ssbo_id,
int input_id) {
absl::Status TFLiteGPURunner::BindSSBOToInputTensor(GLuint ssbo_id,
int input_id) {
OpenGlBuffer buffer;
buffer.id = ssbo_id;
return runner_->SetInputObject(input_id, std::move(buffer));
}
mediapipe::Status TFLiteGPURunner::BindSSBOToOutputTensor(GLuint ssbo_id,
int output_id) {
absl::Status TFLiteGPURunner::BindSSBOToOutputTensor(GLuint ssbo_id,
int output_id) {
OpenGlBuffer buffer;
buffer.id = ssbo_id;
return runner_->SetOutputObject(output_id, std::move(buffer));
}
mediapipe::Status TFLiteGPURunner::Invoke() { return runner_->Run(); }
absl::Status TFLiteGPURunner::Invoke() { return runner_->Run(); }
mediapipe::Status TFLiteGPURunner::InitializeOpenGL(
absl::Status TFLiteGPURunner::InitializeOpenGL(
std::unique_ptr<InferenceBuilder>* builder) {
gl::InferenceEnvironmentOptions env_options;
gl::InferenceEnvironmentProperties properties;
+10 -13
View File
@@ -53,24 +53,23 @@ class TFLiteGPURunner {
explicit TFLiteGPURunner(const InferenceOptions& options)
: options_(options) {}
mediapipe::Status InitializeWithModel(
const tflite::FlatBufferModel& flatbuffer,
const tflite::OpResolver& op_resolver);
absl::Status InitializeWithModel(const tflite::FlatBufferModel& flatbuffer,
const tflite::OpResolver& op_resolver);
void ForceOpenGL() { opengl_is_forced_ = true; }
void ForceOpenCL() { opencl_is_forced_ = true; }
mediapipe::Status BindSSBOToInputTensor(GLuint ssbo_id, int input_id);
mediapipe::Status BindSSBOToOutputTensor(GLuint ssbo_id, int output_id);
absl::Status BindSSBOToInputTensor(GLuint ssbo_id, int input_id);
absl::Status BindSSBOToOutputTensor(GLuint ssbo_id, int output_id);
int inputs_size() const { return input_shapes_.size(); }
int outputs_size() const { return output_shapes_.size(); }
mediapipe::StatusOr<int64_t> GetInputElements(int id);
mediapipe::StatusOr<int64_t> GetOutputElements(int id);
absl::StatusOr<int64_t> GetInputElements(int id);
absl::StatusOr<int64_t> GetOutputElements(int id);
mediapipe::Status Build();
mediapipe::Status Invoke();
absl::Status Build();
absl::Status Invoke();
std::vector<BHWC> GetInputShapes() { return input_shapes_; }
std::vector<BHWC> GetOutputShapes() { return output_shapes_; }
@@ -93,10 +92,8 @@ class TFLiteGPURunner {
#endif
private:
mediapipe::Status InitializeOpenGL(
std::unique_ptr<InferenceBuilder>* builder);
mediapipe::Status InitializeOpenCL(
std::unique_ptr<InferenceBuilder>* builder);
absl::Status InitializeOpenGL(std::unique_ptr<InferenceBuilder>* builder);
absl::Status InitializeOpenCL(std::unique_ptr<InferenceBuilder>* builder);
InferenceOptions options_;
std::unique_ptr<gl::InferenceEnvironment> gl_environment_;
+3 -3
View File
@@ -19,7 +19,7 @@
namespace mediapipe {
mediapipe::StatusOr<Packet> TfLiteModelLoader::LoadFromPath(
absl::StatusOr<api2::Packet<TfLiteModelPtr>> TfLiteModelLoader::LoadFromPath(
const std::string& path) {
std::string model_path = path;
@@ -27,8 +27,8 @@ mediapipe::StatusOr<Packet> TfLiteModelLoader::LoadFromPath(
auto model = tflite::FlatBufferModel::BuildFromFile(model_path.c_str());
RET_CHECK(model) << "Failed to load model from path " << model_path;
return MakePacket<TfLiteModelPtr>(TfLiteModelPtr(
model.release(), [](tflite::FlatBufferModel* model) { delete model; }));
return api2::MakePacket<TfLiteModelPtr>(
model.release(), [](tflite::FlatBufferModel* model) { delete model; });
}
} // namespace mediapipe
+3 -2
View File
@@ -15,7 +15,7 @@
#ifndef MEDIAPIPE_UTIL_TFLITE_TFLITE_MODEL_LOADER_H_
#define MEDIAPIPE_UTIL_TFLITE_TFLITE_MODEL_LOADER_H_
#include "mediapipe/framework/packet.h"
#include "mediapipe/framework/api2/packet.h"
#include "mediapipe/framework/port/status.h"
#include "mediapipe/framework/port/statusor.h"
#include "tensorflow/lite/model.h"
@@ -30,7 +30,8 @@ class TfLiteModelLoader {
public:
// Returns a Packet containing a TfLiteModelPtr, pointing to a model loaded
// from the specified file path.
static mediapipe::StatusOr<Packet> LoadFromPath(const std::string& path);
static absl::StatusOr<api2::Packet<TfLiteModelPtr>> LoadFromPath(
const std::string& path);
};
} // namespace mediapipe
+1 -1
View File
@@ -308,7 +308,7 @@ class TimeSeriesCalculatorTest : public ::testing::Test {
AppendInputPacket(payload, Timestamp(timestamp), input_tag);
}
mediapipe::Status RunGraph() { return runner_->Run(); }
absl::Status RunGraph() { return runner_->Run(); }
bool HasInputHeader(const size_t input_index = 0) const {
return input(input_index)
+8 -8
View File
@@ -62,10 +62,10 @@ bool LogWarningIfTimestampIsInconsistent(const Timestamp& current_timestamp,
}
}
mediapipe::Status IsTimeSeriesHeaderValid(const TimeSeriesHeader& header) {
absl::Status IsTimeSeriesHeaderValid(const TimeSeriesHeader& header) {
if (header.has_sample_rate() && header.sample_rate() >= 0 &&
header.has_num_channels() && header.num_channels() >= 0) {
return mediapipe::OkStatus();
return absl::OkStatus();
} else {
std::string error_message =
"TimeSeriesHeader is missing necessary fields: "
@@ -77,8 +77,8 @@ mediapipe::Status IsTimeSeriesHeaderValid(const TimeSeriesHeader& header) {
}
}
mediapipe::Status FillTimeSeriesHeaderIfValid(const Packet& header_packet,
TimeSeriesHeader* header) {
absl::Status FillTimeSeriesHeaderIfValid(const Packet& header_packet,
TimeSeriesHeader* header) {
CHECK(header);
if (header_packet.IsEmpty()) {
return tool::StatusFail("No header found.");
@@ -90,7 +90,7 @@ mediapipe::Status FillTimeSeriesHeaderIfValid(const Packet& header_packet,
return IsTimeSeriesHeaderValid(*header);
}
mediapipe::Status FillMultiStreamTimeSeriesHeaderIfValid(
absl::Status FillMultiStreamTimeSeriesHeaderIfValid(
const Packet& header_packet, MultiStreamTimeSeriesHeader* header) {
CHECK(header);
if (header_packet.IsEmpty()) {
@@ -107,8 +107,8 @@ mediapipe::Status FillMultiStreamTimeSeriesHeaderIfValid(
return IsTimeSeriesHeaderValid(header->time_series_header());
}
mediapipe::Status IsMatrixShapeConsistentWithHeader(
const Matrix& matrix, const TimeSeriesHeader& header) {
absl::Status IsMatrixShapeConsistentWithHeader(const Matrix& matrix,
const TimeSeriesHeader& header) {
if (header.has_num_samples() && matrix.cols() != header.num_samples()) {
return tool::StatusInvalid(absl::StrCat(
"Matrix size is inconsistent with header. Expected ",
@@ -119,7 +119,7 @@ mediapipe::Status IsMatrixShapeConsistentWithHeader(
"Matrix size is inconsistent with header. Expected ",
header.num_channels(), " rows, but found ", matrix.rows()));
}
return mediapipe::OkStatus();
return absl::OkStatus();
}
int64 SecondsToSamples(double time_in_seconds, double sample_rate) {
+14 -14
View File
@@ -43,27 +43,27 @@ bool LogWarningIfTimestampIsInconsistent(const Timestamp& current_timestamp,
int64 cumulative_samples,
double sample_rate);
// Returns mediapipe::status::OK if the header is valid. Otherwise, returns a
// Returns absl::Status::OK if the header is valid. Otherwise, returns a
// Status object with an error message.
mediapipe::Status IsTimeSeriesHeaderValid(const TimeSeriesHeader& header);
absl::Status IsTimeSeriesHeaderValid(const TimeSeriesHeader& header);
// Fills header and returns mediapipe::status::OK if the header is non-empty and
// Fills header and returns absl::Status::OK if the header is non-empty and
// valid. Otherwise, returns a Status object with an error message.
mediapipe::Status FillTimeSeriesHeaderIfValid(const Packet& header_packet,
TimeSeriesHeader* header);
absl::Status FillTimeSeriesHeaderIfValid(const Packet& header_packet,
TimeSeriesHeader* header);
// Fills header and returns mediapipe::status::OK if the header contains a
// Fills header and returns absl::Status::OK if the header contains a
// non-empty and valid TimeSeriesHeader. Otherwise, returns a Status object with
// an error message.
mediapipe::Status FillMultiStreamTimeSeriesHeaderIfValid(
absl::Status FillMultiStreamTimeSeriesHeaderIfValid(
const Packet& header_packet, MultiStreamTimeSeriesHeader* header);
// Returnsmediapipe::Status::OK iff options contains an extension of type
// Returnsabsl::Status::OK iff options contains an extension of type
// OptionsClass.
template <typename OptionsClass>
mediapipe::Status HasOptionsExtension(const CalculatorOptions& options) {
absl::Status HasOptionsExtension(const CalculatorOptions& options) {
if (options.HasExtension(OptionsClass::ext)) {
return mediapipe::OkStatus();
return absl::OkStatus();
}
std::string error_message = "Options proto does not contain extension ";
absl::StrAppend(&error_message,
@@ -72,16 +72,16 @@ mediapipe::Status HasOptionsExtension(const CalculatorOptions& options) {
// Avoid lite proto APIs on mobile targets.
absl::StrAppend(&error_message, " : ", options.DebugString());
#endif
return mediapipe::InvalidArgumentError(error_message);
return absl::InvalidArgumentError(error_message);
}
// Returnsmediapipe::Status::OK if the shape of 'matrix' is consistent
// Returnsabsl::Status::OK if the shape of 'matrix' is consistent
// with the num_samples and num_channels fields present in 'header'.
// The corresponding matrix dimensions of unset header fields are
// ignored, so e.g. an empty header (which is not valid according to
// FillTimeSeriesHeaderIfValid) is considered consistent with any matrix.
mediapipe::Status IsMatrixShapeConsistentWithHeader(
const Matrix& matrix, const TimeSeriesHeader& header);
absl::Status IsMatrixShapeConsistentWithHeader(const Matrix& matrix,
const TimeSeriesHeader& header);
template <typename OptionsClass>
void FillOptionsExtensionOrDie(const CalculatorOptions& options,
+1
View File
@@ -319,6 +319,7 @@ cc_library(
"//mediapipe/framework/port:logging",
"//mediapipe/framework/port:vector",
"@com_google_absl//absl/container:node_hash_map",
"@com_google_absl//absl/container:node_hash_set",
"@com_google_absl//absl/strings",
],
)
+1 -1
View File
@@ -667,7 +667,7 @@ bool BoxTracker::WaitForChunkFile(int id, int checkpoint,
}
}
usleep(wait_time_msec * 1000);
absl::SleepFor(absl::Milliseconds(wait_time_msec));
total_wait_msec += wait_time_msec;
struct stat tmp;
@@ -5120,6 +5120,7 @@ bool MotionEstimation::MixtureHomographyFromFeature(
MixtureHomography norm_model;
// Initialize with identity.
norm_model.mutable_model()->Reserve(num_mixtures);
for (int k = 0; k < num_mixtures; ++k) {
norm_model.add_model();
}
@@ -15,14 +15,10 @@
// Guard to ensure clients do not link against both,
// single and parallel version.
#ifdef PARALLEL_INVOKER_ACTIVE
int LinkageAgainstBothSingleAndParallelStabilizationVersionsDetected() {
return 0;
}
int LinkageAgainstBothSingleAndParallelTrackingVersionsDetected() { return 0; }
#endif // PARALLEL_INVOKER_ACTIVE
#ifdef PARALLEL_INVOKER_INACTIVE
int LinkageAgainstBothSingleAndParallelStabilizationVersionsDetected() {
return 1;
}
int LinkageAgainstBothSingleAndParallelTrackingVersionsDetected() { return 1; }
#endif // PARALLEL_INVOKER_INACTIVE
+2 -1
View File
@@ -21,6 +21,7 @@
#include <numeric>
#include "absl/container/node_hash_map.h"
#include "absl/container/node_hash_set.h"
#include "absl/strings/str_cat.h"
#include "mediapipe/framework/port/integral_types.h"
#include "mediapipe/util/tracking/measure_time.h"
@@ -580,7 +581,7 @@ void LongFeatureStream::AddFeatures(const RegionFlowFeatureList& feature_list,
}
// Record id of each track that is present in the current feature_list.
std::unordered_set<int> present_tracks;
absl::node_hash_set<int> present_tracks;
for (auto feature : feature_list.feature()) { // Copy feature.
if (feature.track_id() < 0) {
LOG_IF(WARNING, []() {
@@ -115,7 +115,7 @@ void RegionFlowComputationTest::MakeMovie(
// First generate random positions.
int seed = 900913; // google.
if (FLAGS_time_seed) {
if (absl::GetFlag(FLAGS_time_seed)) {
seed = ToUnixMillis(absl::Now()) % (1 << 16);
LOG(INFO) << "Using time seed: " << seed;
}
+2 -1
View File
@@ -1652,7 +1652,8 @@ bool MotionBox::GetVectorsAndWeights(
vectors->push_back(&motion_vectors[k]);
auto is_close_to_test_vector = [test_vector](const Vector2_f v) -> bool {
auto is_close_to_test_vector = [test_vector,
kSqProximity](const Vector2_f v) -> bool {
return (v - test_vector.pos).Norm2() < kSqProximity;
};