Internal change
PiperOrigin-RevId: 524212873
This commit is contained in:
parent
f934b220b2
commit
06bbd9c599
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
// Reflect an integer against the lower and upper bound of an interval.
|
// Reflect an integer against the lower and upper bound of an interval.
|
||||||
int64 ReflectBetween(int64 ts, int64 ts_min, int64 ts_max) {
|
int64_t ReflectBetween(int64_t ts, int64_t ts_min, int64_t ts_max) {
|
||||||
if (ts < ts_min) return 2 * ts_min - ts - 1;
|
if (ts < ts_min) return 2 * ts_min - ts - 1;
|
||||||
if (ts >= ts_max) return 2 * ts_max - ts - 1;
|
if (ts >= ts_max) return 2 * ts_max - ts - 1;
|
||||||
return ts;
|
return ts;
|
||||||
|
@ -47,7 +47,7 @@ constexpr char kOptionsTag[] = "OPTIONS";
|
||||||
// Returns a TimestampDiff (assuming microseconds) corresponding to the
|
// Returns a TimestampDiff (assuming microseconds) corresponding to the
|
||||||
// given time in seconds.
|
// given time in seconds.
|
||||||
TimestampDiff TimestampDiffFromSeconds(double seconds) {
|
TimestampDiff TimestampDiffFromSeconds(double seconds) {
|
||||||
return TimestampDiff(MathUtil::SafeRound<int64, double>(
|
return TimestampDiff(MathUtil::SafeRound<int64_t, double>(
|
||||||
seconds * Timestamp::kTimestampUnitsPerSecond));
|
seconds * Timestamp::kTimestampUnitsPerSecond));
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -117,8 +117,8 @@ absl::Status PacketResamplerCalculator::Open(CalculatorContext* cc) {
|
||||||
<< "The output frame rate must be smaller than "
|
<< "The output frame rate must be smaller than "
|
||||||
<< Timestamp::kTimestampUnitsPerSecond;
|
<< Timestamp::kTimestampUnitsPerSecond;
|
||||||
|
|
||||||
frame_time_usec_ = static_cast<int64>(1000000.0 / frame_rate_);
|
frame_time_usec_ = static_cast<int64_t>(1000000.0 / frame_rate_);
|
||||||
jitter_usec_ = static_cast<int64>(1000000.0 * jitter_ / frame_rate_);
|
jitter_usec_ = static_cast<int64_t>(1000000.0 * jitter_ / frame_rate_);
|
||||||
RET_CHECK_LE(jitter_usec_, frame_time_usec_);
|
RET_CHECK_LE(jitter_usec_, frame_time_usec_);
|
||||||
|
|
||||||
video_header_.frame_rate = frame_rate_;
|
video_header_.frame_rate = frame_rate_;
|
||||||
|
@ -198,17 +198,18 @@ PacketResamplerCalculator::GetSamplingStrategy(
|
||||||
return absl::make_unique<JitterWithoutReflectionStrategy>(this);
|
return absl::make_unique<JitterWithoutReflectionStrategy>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Timestamp PacketResamplerCalculator::PeriodIndexToTimestamp(int64 index) const {
|
Timestamp PacketResamplerCalculator::PeriodIndexToTimestamp(
|
||||||
|
int64_t index) const {
|
||||||
CHECK_EQ(jitter_, 0.0);
|
CHECK_EQ(jitter_, 0.0);
|
||||||
CHECK_NE(first_timestamp_, Timestamp::Unset());
|
CHECK_NE(first_timestamp_, Timestamp::Unset());
|
||||||
return first_timestamp_ + TimestampDiffFromSeconds(index / frame_rate_);
|
return first_timestamp_ + TimestampDiffFromSeconds(index / frame_rate_);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64 PacketResamplerCalculator::TimestampToPeriodIndex(
|
int64_t PacketResamplerCalculator::TimestampToPeriodIndex(
|
||||||
Timestamp timestamp) const {
|
Timestamp timestamp) const {
|
||||||
CHECK_EQ(jitter_, 0.0);
|
CHECK_EQ(jitter_, 0.0);
|
||||||
CHECK_NE(first_timestamp_, Timestamp::Unset());
|
CHECK_NE(first_timestamp_, Timestamp::Unset());
|
||||||
return MathUtil::SafeRound<int64, double>(
|
return MathUtil::SafeRound<int64_t, double>(
|
||||||
(timestamp - first_timestamp_).Seconds() * frame_rate_);
|
(timestamp - first_timestamp_).Seconds() * frame_rate_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,11 +290,11 @@ absl::Status LegacyJitterWithReflectionStrategy::Process(
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const int64 last_diff =
|
const int64_t last_diff =
|
||||||
(next_output_timestamp_ - calculator_->last_packet_.Timestamp())
|
(next_output_timestamp_ - calculator_->last_packet_.Timestamp())
|
||||||
.Value();
|
.Value();
|
||||||
RET_CHECK_GT(last_diff, 0);
|
RET_CHECK_GT(last_diff, 0);
|
||||||
const int64 curr_diff =
|
const int64_t curr_diff =
|
||||||
(next_output_timestamp_ - cc->InputTimestamp()).Value();
|
(next_output_timestamp_ - cc->InputTimestamp()).Value();
|
||||||
if (curr_diff > 0) {
|
if (curr_diff > 0) {
|
||||||
break;
|
break;
|
||||||
|
@ -559,11 +560,11 @@ absl::Status JitterWithoutReflectionStrategy::Process(CalculatorContext* cc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const int64 last_diff =
|
const int64_t last_diff =
|
||||||
(next_output_timestamp_ - calculator_->last_packet_.Timestamp())
|
(next_output_timestamp_ - calculator_->last_packet_.Timestamp())
|
||||||
.Value();
|
.Value();
|
||||||
RET_CHECK_GT(last_diff, 0);
|
RET_CHECK_GT(last_diff, 0);
|
||||||
const int64 curr_diff =
|
const int64_t curr_diff =
|
||||||
(next_output_timestamp_ - cc->InputTimestamp()).Value();
|
(next_output_timestamp_ - cc->InputTimestamp()).Value();
|
||||||
if (curr_diff > 0) {
|
if (curr_diff > 0) {
|
||||||
break;
|
break;
|
||||||
|
@ -631,7 +632,7 @@ absl::Status NoJitterStrategy::Process(CalculatorContext* cc) {
|
||||||
} else {
|
} else {
|
||||||
// Initialize first_timestamp_ with the first packet timestamp
|
// Initialize first_timestamp_ with the first packet timestamp
|
||||||
// aligned to the base_timestamp_.
|
// aligned to the base_timestamp_.
|
||||||
int64 first_index = MathUtil::SafeRound<int64, double>(
|
int64_t first_index = MathUtil::SafeRound<int64_t, double>(
|
||||||
(cc->InputTimestamp() - base_timestamp_).Seconds() *
|
(cc->InputTimestamp() - base_timestamp_).Seconds() *
|
||||||
calculator_->frame_rate_);
|
calculator_->frame_rate_);
|
||||||
calculator_->first_timestamp_ =
|
calculator_->first_timestamp_ =
|
||||||
|
@ -646,7 +647,7 @@ absl::Status NoJitterStrategy::Process(CalculatorContext* cc) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const Timestamp received_timestamp = cc->InputTimestamp();
|
const Timestamp received_timestamp = cc->InputTimestamp();
|
||||||
const int64 received_timestamp_idx =
|
const int64_t received_timestamp_idx =
|
||||||
calculator_->TimestampToPeriodIndex(received_timestamp);
|
calculator_->TimestampToPeriodIndex(received_timestamp);
|
||||||
// Only consider the received packet if it belongs to the current period
|
// Only consider the received packet if it belongs to the current period
|
||||||
// (== period_count_) or to a newer one (> period_count_).
|
// (== period_count_) or to a newer one (> period_count_).
|
||||||
|
|
|
@ -97,7 +97,7 @@ class PacketThinnerCalculator : public CalculatorBase {
|
||||||
cc->Inputs().Index(0).SetAny();
|
cc->Inputs().Index(0).SetAny();
|
||||||
cc->Outputs().Index(0).SetSameAs(&cc->Inputs().Index(0));
|
cc->Outputs().Index(0).SetSameAs(&cc->Inputs().Index(0));
|
||||||
if (cc->InputSidePackets().HasTag(kPeriodTag)) {
|
if (cc->InputSidePackets().HasTag(kPeriodTag)) {
|
||||||
cc->InputSidePackets().Tag(kPeriodTag).Set<int64>();
|
cc->InputSidePackets().Tag(kPeriodTag).Set<int64_t>();
|
||||||
}
|
}
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ absl::Status PacketThinnerCalculator::Open(CalculatorContext* cc) {
|
||||||
|
|
||||||
if (cc->InputSidePackets().HasTag(kPeriodTag)) {
|
if (cc->InputSidePackets().HasTag(kPeriodTag)) {
|
||||||
period_ =
|
period_ =
|
||||||
TimestampDiff(cc->InputSidePackets().Tag(kPeriodTag).Get<int64>());
|
TimestampDiff(cc->InputSidePackets().Tag(kPeriodTag).Get<int64_t>());
|
||||||
} else {
|
} else {
|
||||||
period_ = TimestampDiff(options.period());
|
period_ = TimestampDiff(options.period());
|
||||||
}
|
}
|
||||||
|
@ -300,13 +300,13 @@ Timestamp PacketThinnerCalculator::NearestSyncTimestamp(Timestamp now) const {
|
||||||
|
|
||||||
// Computation is done using int64 arithmetic. No easy way to avoid
|
// Computation is done using int64 arithmetic. No easy way to avoid
|
||||||
// since Timestamps don't support div and multiply.
|
// since Timestamps don't support div and multiply.
|
||||||
const int64 now64 = now.Value();
|
const int64_t now64 = now.Value();
|
||||||
const int64 start64 = start_time_.Value();
|
const int64_t start64 = start_time_.Value();
|
||||||
const int64 period64 = period_.Value();
|
const int64_t period64 = period_.Value();
|
||||||
CHECK_LE(0, period64);
|
CHECK_LE(0, period64);
|
||||||
|
|
||||||
// Round now64 to its closest interval (units of period64).
|
// Round now64 to its closest interval (units of period64).
|
||||||
int64 sync64 =
|
int64_t sync64 =
|
||||||
(now64 - start64 + period64 / 2) / period64 * period64 + start64;
|
(now64 - start64 + period64 / 2) / period64 * period64 + start64;
|
||||||
CHECK_LE(abs(now64 - sync64), period64 / 2)
|
CHECK_LE(abs(now64 - sync64), period64 / 2)
|
||||||
<< "start64: " << start64 << "; now64: " << now64
|
<< "start64: " << start64 << "; now64: " << now64
|
||||||
|
|
Loading…
Reference in New Issue
Block a user