0

media/gpu/chromeos/frame_resource: Add tracking token

This is intended to be used as a substitute for the
GenericSharedMemoryId that is returned by GetSharedMemoryId(). For new
frames, the UnguessableToken is generated. When creating a wrapping
frame, the original UnguessableToken is reused.

The tracking token is stored in the VideoFrameMetadata.

For NativePixmapFrameResource, it is created at construction time. When
a frame is wrapped, the metadata is copied to the new wrapping frame.
When a user calls set_metadata(), the original tracking token is
persisted.

For VideoFrameResource, the tracking token is passed through from the
underlying VideoFrame's VideoFrameMetadata.

Bug: b:372695223
Change-Id: I1eb674ed33cc11b6572f13c58a6858b02077c5cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5924234
Reviewed-by: Andres Calderon Jaramillo <andrescj@chromium.org>
Commit-Queue: Nathan Hebert <nhebert@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1374758}
This commit is contained in:
Nathan Hebert
2024-10-28 18:38:28 +00:00
committed by Chromium LUCI CQ
parent e7573dfbff
commit 9cd5bf3d97
4 changed files with 25 additions and 4 deletions

@ -17,6 +17,12 @@ FrameResource::ID GetNextID() {
FrameResource::FrameResource() : unique_id_(GetNextID()) {}
const base::UnguessableToken& FrameResource::tracking_token() const {
CHECK(metadata().tracking_token.has_value());
CHECK(!metadata().tracking_token->is_empty());
return *metadata().tracking_token;
}
VideoFrameResource* FrameResource::AsVideoFrameResource() {
return nullptr;
}

@ -7,6 +7,7 @@
#include "base/memory/scoped_refptr.h"
#include "base/time/time.h"
#include "base/unguessable_token.h"
#include "media/base/video_frame.h"
#include "media/base/video_frame_layout.h"
#include "media/base/video_frame_metadata.h"
@ -138,6 +139,10 @@ class FrameResource : public base::RefCountedThreadSafe<FrameResource> {
virtual VideoFrameMetadata& metadata() = 0;
virtual void set_metadata(const VideoFrameMetadata& metadata) = 0;
// An UnguessableToken that identifies unique frames regardless of wrapping.
// The returned UnguessableToken is guaranteed to be non-empty.
const base::UnguessableToken& tracking_token() const;
virtual base::TimeDelta timestamp() const = 0;
virtual void set_timestamp(base::TimeDelta timestamp) = 0;

@ -140,8 +140,8 @@ scoped_refptr<NativePixmapFrameResource> NativePixmapFrameResource::Create(
// method, CreateVideoFrame().
return base::WrapRefCounted(new NativePixmapFrameResource(
layout, visible_rect, natural_size, timestamp, *buffer_format,
GetNextSharedMemoryId(), /*buffer_usage=*/std::nullopt,
std::move(handle)));
GetNextSharedMemoryId(), base::UnguessableToken::Create(),
/*buffer_usage=*/std::nullopt, std::move(handle)));
}
scoped_refptr<NativePixmapFrameResource> NativePixmapFrameResource::Create(
@ -198,7 +198,7 @@ scoped_refptr<NativePixmapFrameResource> NativePixmapFrameResource::Create(
return base::WrapRefCounted(new NativePixmapFrameResource(
*layout, visible_rect, natural_size, timestamp, GetNextSharedMemoryId(),
buffer_usage, std::move(pixmap)));
base::UnguessableToken::Create(), buffer_usage, std::move(pixmap)));
}
NativePixmapFrameResource::NativePixmapFrameResource(
@ -208,6 +208,7 @@ NativePixmapFrameResource::NativePixmapFrameResource(
base::TimeDelta timestamp,
gfx::BufferFormat buffer_format,
gfx::GenericSharedMemoryId id,
const base::UnguessableToken& tracking_token,
std::optional<gfx::BufferUsage> buffer_usage,
gfx::NativePixmapHandle handle)
: NativePixmapFrameResource(
@ -216,6 +217,7 @@ NativePixmapFrameResource::NativePixmapFrameResource(
natural_size,
timestamp,
id,
tracking_token,
buffer_usage,
base::MakeRefCounted<gfx::NativePixmapDmaBuf>(layout.coded_size(),
buffer_format,
@ -227,6 +229,7 @@ NativePixmapFrameResource::NativePixmapFrameResource(
const gfx::Size& natural_size,
base::TimeDelta timestamp,
gfx::GenericSharedMemoryId id,
const base::UnguessableToken& tracking_token,
std::optional<gfx::BufferUsage> buffer_usage,
scoped_refptr<const gfx::NativePixmapDmaBuf> pixmap)
: pixmap_(std::move(pixmap)),
@ -237,6 +240,8 @@ NativePixmapFrameResource::NativePixmapFrameResource(
natural_size_(natural_size),
timestamp_(timestamp) {
metadata().is_webgpu_compatible = pixmap_->SupportsZeroCopyWebGPUImport();
CHECK(!tracking_token.is_empty());
metadata().tracking_token = tracking_token;
}
NativePixmapFrameResource::~NativePixmapFrameResource() {
@ -381,7 +386,10 @@ VideoFrameMetadata& NativePixmapFrameResource::metadata() {
void NativePixmapFrameResource::set_metadata(
const VideoFrameMetadata& metadata) {
// This keeps the original tracking token in |metadata_|.
base::UnguessableToken original_tracking_token = tracking_token();
metadata_ = metadata;
metadata_.tracking_token = original_tracking_token;
}
base::TimeDelta NativePixmapFrameResource::timestamp() const {
@ -416,7 +424,7 @@ scoped_refptr<FrameResource> NativePixmapFrameResource::CreateWrappingFrame(
auto wrapping_frame = base::WrapRefCounted<NativePixmapFrameResource>(
new NativePixmapFrameResource(layout(), visible_rect, natural_size,
timestamp(), GetSharedMemoryId(),
buffer_usage_, pixmap_));
tracking_token(), buffer_usage_, pixmap_));
// All other metadata is copied to the "wrapping" frame.
wrapping_frame->metadata().MergeMetadataFrom(metadata());

@ -126,6 +126,7 @@ class NativePixmapFrameResource : public FrameResource {
base::TimeDelta timestamp,
gfx::BufferFormat buffer_format,
gfx::GenericSharedMemoryId id,
const base::UnguessableToken& token,
std::optional<gfx::BufferUsage> buffer_usage,
gfx::NativePixmapHandle handle);
@ -135,6 +136,7 @@ class NativePixmapFrameResource : public FrameResource {
const gfx::Size& natural_size,
base::TimeDelta timestamp,
gfx::GenericSharedMemoryId id,
const base::UnguessableToken& token,
std::optional<gfx::BufferUsage> buffer_usage,
scoped_refptr<const gfx::NativePixmapDmaBuf> pixmap);