Skip to content

Commit

Permalink
Fix max timestamp DCHECK
Browse files Browse the repository at this point in the history
See attached bug for details.

Bug: 1329394
Change-Id: Ie61ecbcf5e30220c7bdaf7ff6b4f75b6ecd333fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3722083
Reviewed-by: Eugene Zemtsov <eugene@chromium.org>
Auto-Submit: Thomas Guilbert <tguilbert@chromium.org>
Commit-Queue: Eugene Zemtsov <eugene@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1018894}
  • Loading branch information
tguilbert-google authored and Chromium LUCI CQ committed Jun 28, 2022
1 parent d82742a commit 3b7e95f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
16 changes: 15 additions & 1 deletion media/audio/audio_opus_encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,17 @@ void AudioOpusEncoder::Flush(EncoderStatusCB done_cb) {
void AudioOpusEncoder::OnFifoOutput(AudioBus* audio_bus) {
audio_bus->ToInterleaved<Float32SampleTypeTraits>(audio_bus->frames(),
buffer_.data());
// We already reported an error. Don't attempt to encode any further inputs.
if (!current_done_cb_)
return;

std::unique_ptr<uint8_t[]> encoded_data(new uint8_t[kOpusMaxDataBytes]);
auto result = opus_encode_float(opus_encoder_.get(), buffer_.data(),
converted_params_.frames_per_buffer(),
encoded_data.get(), kOpusMaxDataBytes);

if (result < 0 && current_done_cb_) {
if (result < 0) {
DCHECK(current_done_cb_);
std::move(current_done_cb_)
.Run(EncoderStatus(EncoderStatus::Codes::kEncoderFailedEncode,
opus_strerror(result)));
Expand All @@ -262,6 +266,16 @@ void AudioOpusEncoder::OnFifoOutput(AudioBus* audio_bus) {
auto duration = timestamp_tracker_->GetFrameDuration(
converted_params_.frames_per_buffer());

// `timestamp_tracker_` will return base::TimeDelta() if the timestamps
// overflow.
if (duration.is_zero()) {
DCHECK(current_done_cb_);
std::move(current_done_cb_)
.Run(EncoderStatus(EncoderStatus::Codes::kEncoderFailedEncode,
"Invalid computed duration."));
return;
}

EncodedAudioBuffer encoded_buffer(converted_params_,
std::move(encoded_data),
encoded_data_size, ts, duration);
Expand Down
9 changes: 8 additions & 1 deletion media/base/audio_timestamp_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,15 @@ base::TimeDelta AudioTimestampHelper::GetTimestamp() const {

base::TimeDelta AudioTimestampHelper::GetFrameDuration(int frame_count) const {
DCHECK_GE(frame_count, 0);
base::TimeDelta current_timestamp = GetTimestamp();
base::TimeDelta end_timestamp = ComputeTimestamp(frame_count_ + frame_count);
return end_timestamp - GetTimestamp();

if ((current_timestamp.is_min() && end_timestamp.is_min()) ||
(current_timestamp.is_max() && end_timestamp.is_max())) {
return base::TimeDelta();
}

return end_timestamp - current_timestamp;
}

int64_t AudioTimestampHelper::GetFramesToTarget(base::TimeDelta target) const {
Expand Down

0 comments on commit 3b7e95f

Please sign in to comment.