Skip to content

Commit

Permalink
media/gpu/vea_perf_tests: Fix the issue of wrong encode_time metrics
Browse files Browse the repository at this point in the history
crrev.com/c/2670241 sets the timestamp of a video frame as if it is
produced at a specified frame rate. On the other hand, encode_time
metrics in video_encode_accelerator_perf_tests encompasses from a
VideoFrame being received to when the bitstream is finalized. The
latter is further computed from the UNIX origin time. encode_time
becomes quite large value wrongly.
This CL fixes the issue by recording the encode frame input time and
passing BitstreamProcessor the time with BitstreamBufferRef.

Bug: None
Test: video_encode_accelerator_tests on trogdor
Change-Id: I59b72b3c20dc07ab1138a490772dd20a376cb3c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3487288
Reviewed-by: Miguel Casas-Sanchez <mcasas@chromium.org>
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#988372}
  • Loading branch information
Hirokazu Honda authored and Chromium LUCI CQ committed Apr 4, 2022
1 parent f2b68e0 commit 869c592
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
5 changes: 4 additions & 1 deletion media/gpu/test/bitstream_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ BitstreamProcessor::BitstreamRef::Create(
scoped_refptr<DecoderBuffer> buffer,
const BitstreamBufferMetadata& metadata,
int32_t id,
base::TimeTicks source_timestamp,
base::OnceClosure release_cb) {
return new BitstreamRef(std::move(buffer), metadata, id,
return new BitstreamRef(std::move(buffer), metadata, id, source_timestamp,
std::move(release_cb));
}

BitstreamProcessor::BitstreamRef::BitstreamRef(
scoped_refptr<DecoderBuffer> buffer,
const BitstreamBufferMetadata& metadata,
int32_t id,
base::TimeTicks source_timestamp,
base::OnceClosure release_cb)
: buffer(std::move(buffer)),
metadata(metadata),
id(id),
source_timestamp(source_timestamp),
release_cb(std::move(release_cb)) {}

BitstreamProcessor::BitstreamRef::~BitstreamRef() {
Expand Down
6 changes: 6 additions & 0 deletions media/gpu/test/bitstream_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "base/callback_forward.h"
#include "base/memory/ref_counted.h"
#include "base/time/time.h"
#include "media/video/video_encode_accelerator.h"

namespace media {
Expand All @@ -21,6 +22,7 @@ class BitstreamProcessor {
scoped_refptr<DecoderBuffer> buffer,
const BitstreamBufferMetadata& metadata,
int32_t id,
base::TimeTicks source_timestamp,
base::OnceClosure release_cb);
BitstreamRef() = delete;
BitstreamRef(const BitstreamRef&) = delete;
Expand All @@ -29,12 +31,16 @@ class BitstreamProcessor {
const scoped_refptr<DecoderBuffer> buffer;
const BitstreamBufferMetadata metadata;
const int32_t id;
// |source_timestamp| is the timestamp when the VideoFrame for this
// bitstream is received to an encoder.
const base::TimeTicks source_timestamp;

private:
friend class base::RefCountedThreadSafe<BitstreamRef>;
BitstreamRef(scoped_refptr<DecoderBuffer> buffer,
const BitstreamBufferMetadata& metadata,
int32_t id,
base::TimeTicks source_timestamp,
base::OnceClosure release_cb);
~BitstreamRef();

Expand Down
9 changes: 8 additions & 1 deletion media/gpu/test/video_encoder/video_encoder_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,12 @@ VideoEncoderClient::CreateBitstreamRef(
if (!decoder_buffer)
return nullptr;
decoder_buffer->set_timestamp(base::Microseconds(frame_index_));
auto source_timestamp_it = source_timestamps_.find(metadata.timestamp);
LOG_ASSERT(source_timestamp_it != source_timestamps_.end());

return BitstreamProcessor::BitstreamRef::Create(
std::move(decoder_buffer), metadata, bitstream_buffer_id,
source_timestamp_it->second,
BindToCurrentLoop(
base::BindOnce(&VideoEncoderClient::BitstreamBufferProcessed,
weak_this_, bitstream_buffer_id)));
Expand Down Expand Up @@ -420,10 +423,13 @@ void VideoEncoderClient::BitstreamBufferReady(
current_top_spatial_index_ =
metadata.vp9->spatial_layer_resolutions.size() - 1;
}
if (metadata.vp9->spatial_idx == current_top_spatial_index_)
if (metadata.vp9->spatial_idx == current_top_spatial_index_) {
frame_index_++;
CHECK_EQ(source_timestamps_.erase(metadata.timestamp), 1u);
}
} else {
frame_index_++;
CHECK_EQ(source_timestamps_.erase(metadata.timestamp), 1u);
}
FlushDoneTaskIfNeeded();
}
Expand Down Expand Up @@ -541,6 +547,7 @@ void VideoEncoderClient::EncodeNextFrameTask() {
base::TimeDelta>,
weak_this_, encoder_client_task_runner_,
&VideoEncoderClient::EncodeDoneTask, video_frame->timestamp()));
source_timestamps_[video_frame->timestamp()] = base::TimeTicks::Now();

encoder_->Encode(video_frame, force_keyframe_);

Expand Down
4 changes: 4 additions & 0 deletions media/gpu/test/video_encoder/video_encoder_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ class VideoEncoderClient : public VideoEncodeAccelerator::Client {
// The current top spatial layer index.
uint8_t current_top_spatial_index_ = 0;

// A map from an input VideoFrame timestamp to the time when it is enqueued
// into |encoder_|.
std::map<base::TimeDelta, base::TimeTicks> source_timestamps_;

// Force a key frame on next Encode(), only accessed on the
// |encoder_client_thread_|.
bool force_keyframe_ = false;
Expand Down
5 changes: 4 additions & 1 deletion media/gpu/video_encode_accelerator_perf_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,11 @@ void PerformanceEvaluator::ProcessBitstream(
delivery_time.InMillisecondsF());
prev_bitstream_delivery_time_ = now;

// TODO(hiroh): |encode_time| on upper spatial layer in SVC encoding becomes
// larger because the bitstram is produced after lower spatial layers are
// produced. |encode_time| should be aggregated per spatial layer.
base::TimeDelta encode_time =
now.since_origin() - bitstream->metadata.timestamp;
base::TimeTicks::Now() - bitstream->source_timestamp;
perf_metrics_.bitstream_encode_times_.push_back(
encode_time.InMillisecondsF());
}
Expand Down

0 comments on commit 869c592

Please sign in to comment.