chromium/media/gpu/chromeos/mailbox_frame_registry.h

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_GPU_CHROMEOS_MAILBOX_FRAME_REGISTRY_H_
#define MEDIA_GPU_CHROMEOS_MAILBOX_FRAME_REGISTRY_H_

#include "base/containers/small_map.h"
#include "base/memory/scoped_refptr.h"
#include "base/synchronization/lock.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "media/gpu/chromeos/frame_resource.h"

namespace media {

// This class is used for storing and accessing a frame using a gpu::Mailbox as
// a key. An instance retains a reference to any frame that is currently
// registered and releases the frame when UnregisterFrame() is called, or when
// the MailboxFrameRegistry is destroyed.
//
// This class is reference counted because it needs to be used by the
// VideoDecoderPipeline to register output frames, by the
// StableVideoDecoderService to access them, and by the individual frames'
// release callbacks to unregister themselves. VideoDecoderPipeline is
// asynchronously destroyed. Frames may be unregistered after its destruction.
// Use of reference counting allows for safe unregistration of frames.
//
// All public methods of this class are thread-safe. A MailboxFrameRegistry can
// be constructed and destroyed on any sequence.
class MailboxFrameRegistry final
    : public base::RefCountedThreadSafe<MailboxFrameRegistry> {};

}  // namespace media

#endif  // MEDIA_GPU_CHROMEOS_MAILBOX_FRAME_REGISTRY_H_