diff options
Diffstat (limited to 'chromium/media/base/video_frame.h')
-rw-r--r-- | chromium/media/base/video_frame.h | 56 |
1 files changed, 34 insertions, 22 deletions
diff --git a/chromium/media/base/video_frame.h b/chromium/media/base/video_frame.h index ed16de268c5..8c6d8738915 100644 --- a/chromium/media/base/video_frame.h +++ b/chromium/media/base/video_frame.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -18,8 +18,8 @@ #include "base/hash/md5.h" #include "base/memory/free_deleter.h" #include "base/memory/raw_ptr.h" +#include "base/memory/read_only_shared_memory_region.h" #include "base/memory/ref_counted.h" -#include "base/memory/unsafe_shared_memory_region.h" #include "base/synchronization/lock.h" #include "base/thread_annotations.h" #include "base/time/time.h" @@ -71,6 +71,8 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { kAPlane = 3, }; + // These values are persisted to logs. Entries should not be renumbered and + // numeric values should never be reused. // Defines the pixel storage type. Differentiates between directly accessible // |data_| and pixels that are only indirectly accessible and not via mappable // memory. @@ -81,7 +83,7 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { STORAGE_OPAQUE = 1, // We don't know how VideoFrame's pixels are stored. STORAGE_UNOWNED_MEMORY = 2, // External, non owned data pointers. STORAGE_OWNED_MEMORY = 3, // VideoFrame has allocated its own data buffer. - STORAGE_SHMEM = 4, // Backed by unsafe (writable) shared memory. + STORAGE_SHMEM = 4, // Backed by read-only shared memory. #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) // TODO(mcasas): Consider turning this type into STORAGE_NATIVE // based on the idea of using this same enum value for both DMA @@ -89,11 +91,8 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { // STORAGE_UNOWNED_MEMORY) and handle it appropriately in all cases. STORAGE_DMABUFS = 5, // Each plane is stored into a DmaBuf. #endif - // Backed by a mojo shared buffer. This should only be used by the - // MojoSharedBufferVideoFrame subclass. - STORAGE_MOJO_SHARED_BUFFER = 6, - STORAGE_GPU_MEMORY_BUFFER = 7, - STORAGE_LAST = STORAGE_GPU_MEMORY_BUFFER, + STORAGE_GPU_MEMORY_BUFFER = 6, + STORAGE_MAX = STORAGE_GPU_MEMORY_BUFFER, }; // CB to be called on the mailbox backing this frame and its GpuMemoryBuffers @@ -417,23 +416,23 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { // Returns a human readable string of StorageType. static std::string StorageTypeToString(VideoFrame::StorageType storage_type); - // A video frame wrapping external data may be backed by an unsafe shared + // A video frame wrapping external data may be backed by a read-only shared // memory region. These methods are used to appropriately transform a // VideoFrame created with WrapExternalData, WrapExternalYuvaData, etc. The - // storage type of the Video Frame will be changed to STORAGE_SHM. Once the - // backing of a VideoFrame is set, it cannot be changed. + // storage type of the Video Frame will be changed to STORAGE_READ_ONLY_SHMEM. + // Once the backing of a VideoFrame is set, it cannot be changed. // // The region is NOT owned by the video frame. Both the region and its // associated mapping must outlive this instance. - void BackWithSharedMemory(const base::UnsafeSharedMemoryRegion* region); + void BackWithSharedMemory(const base::ReadOnlySharedMemoryRegion* region); // As above, but the VideoFrame owns the shared memory region as well as the // mapping. They will be destroyed with their VideoFrame. - void BackWithOwnedSharedMemory(base::UnsafeSharedMemoryRegion region, - base::WritableSharedMemoryMapping mapping); + void BackWithOwnedSharedMemory(base::ReadOnlySharedMemoryRegion region, + base::ReadOnlySharedMemoryMapping mapping); // Valid for shared memory backed VideoFrames. - const base::UnsafeSharedMemoryRegion* shm_region() { + const base::ReadOnlySharedMemoryRegion* shm_region() const { DCHECK(IsValidSharedMemoryFrame()); DCHECK(storage_type_ == STORAGE_SHMEM); return shm_region_; @@ -482,6 +481,16 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { VideoPixelFormat format() const { return layout_.format(); } StorageType storage_type() const { return storage_type_; } + // Returns true if the video frame's contents should be accessed by sampling + // its one texture using an external sampler. Returns false if the video + // frame's planes should be accessed separately or if it's unknown whether an + // external sampler should be used. + // + // If this method returns true, VideoPixelFormatToGfxBufferFormat(format()) is + // guaranteed to not return nullopt. + // TODO(andrescj): enforce this with a test. + bool RequiresExternalSampler() const; + // The full dimensions of the video frame data. const gfx::Size& coded_size() const { return layout_.coded_size(); } // A subsection of [0, 0, coded_size().width(), coded_size.height()]. This @@ -517,7 +526,7 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { DCHECK(IsMappable()); return data_[plane]; } - uint8_t* data(size_t plane) { + uint8_t* writable_data(size_t plane) { DCHECK(IsValidPlane(format(), plane)); DCHECK(IsMappable()); return data_[plane]; @@ -532,7 +541,7 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { // plane buffer specified by visible_rect().origin(). Memory is owned by // VideoFrame object and must not be freed by the caller. const uint8_t* visible_data(size_t plane) const; - uint8_t* visible_data(size_t plane); + uint8_t* GetWritableVisibleData(size_t plane); // Returns a mailbox holder for a given texture. // Only valid to call if this is a NATIVE_TEXTURE frame. Before using the @@ -702,6 +711,9 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { // associated regions are valid. bool IsValidSharedMemoryFrame() const; + template <typename T> + T GetVisibleDataInternal(T data, size_t plane) const; + // VideFrameLayout (includes format, coded_size, and strides). const VideoFrameLayout layout_; @@ -733,12 +745,12 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { // Shared memory handle, if this frame is STORAGE_SHMEM. The region pointed // to is unowned. - raw_ptr<const base::UnsafeSharedMemoryRegion> shm_region_ = nullptr; + raw_ptr<const base::ReadOnlySharedMemoryRegion> shm_region_ = nullptr; - // Used if this is a STORAGE_SHMEM frame with owned shared memory. In that - // case, shm_region_ will refer to this region. - base::UnsafeSharedMemoryRegion owned_shm_region_; - base::WritableSharedMemoryMapping owned_shm_mapping_; + // Used if this is a STORAGE_SHMEM frame with owned shared memory. + // In that case, shm_region_ will refer to this region. + base::ReadOnlySharedMemoryRegion owned_shm_region_; + base::ReadOnlySharedMemoryMapping owned_shm_mapping_; // GPU memory buffer, if this frame is STORAGE_GPU_MEMORY_BUFFER. std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_; |