-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup GPU memory buffer manager for Video capture in Linux
Create the GPU memory buffer manager from the viz::Gpu and set it to the V4L2 video capture GPU memory buffer manager. Bug: 1425770 Change-Id: Ic47afc63bbfb0ae841ad3204a34b868a8c6cfcdc Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4392949 Reviewed-by: Henrik Boström <hbos@chromium.org> Commit-Queue: Ilya Nikolaevskiy <ilnik@chromium.org> Reviewed-by: Ilya Nikolaevskiy <ilnik@chromium.org> Reviewed-by: Markus Handell <handellm@google.com> Cr-Commit-Position: refs/heads/main@{#1150230}
- Loading branch information
Showing
4 changed files
with
165 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
media/capture/video/linux/video_capture_gpu_memory_buffer_manager.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "media/capture/video/linux/video_capture_gpu_memory_buffer_manager.h" | ||
|
||
namespace media { | ||
|
||
VideoCaptureGpuMemoryBufferManager::VideoCaptureGpuMemoryBufferManager() | ||
: gpu_buffer_manager_(nullptr) {} | ||
|
||
VideoCaptureGpuMemoryBufferManager::~VideoCaptureGpuMemoryBufferManager() = | ||
default; | ||
|
||
// static | ||
VideoCaptureGpuMemoryBufferManager& | ||
VideoCaptureGpuMemoryBufferManager::GetInstance() { | ||
static base::NoDestructor<VideoCaptureGpuMemoryBufferManager> instance; | ||
return *instance; | ||
} | ||
|
||
void VideoCaptureGpuMemoryBufferManager::SetGpuMemoryBufferManager( | ||
gpu::GpuMemoryBufferManager* gbm) { | ||
base::AutoLock lock(lock_); | ||
gpu_buffer_manager_ = gbm; | ||
} | ||
|
||
gpu::GpuMemoryBufferManager* | ||
VideoCaptureGpuMemoryBufferManager::GetGpuMemoryBufferManager() { | ||
base::AutoLock lock(lock_); | ||
return gpu_buffer_manager_; | ||
} | ||
|
||
void VideoCaptureGpuMemoryBufferManager::OnContextLost() { | ||
base::AutoLock lock(lock_); | ||
for (auto& observer : observers_) { | ||
observer.OnContextLost(); | ||
} | ||
} | ||
|
||
void VideoCaptureGpuMemoryBufferManager::AddObserver( | ||
VideoCaptureGpuContextLostObserver* observer) { | ||
base::AutoLock lock(lock_); | ||
if (observers_.HasObserver(observer)) { | ||
return; | ||
} | ||
|
||
observers_.AddObserver(observer); | ||
} | ||
|
||
void VideoCaptureGpuMemoryBufferManager::RemoveObserver( | ||
VideoCaptureGpuContextLostObserver* to_remove) { | ||
base::AutoLock lock(lock_); | ||
observers_.RemoveObserver(to_remove); | ||
} | ||
|
||
} // namespace media |
81 changes: 81 additions & 0 deletions
81
media/capture/video/linux/video_capture_gpu_memory_buffer_manager.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2023 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_CAPTURE_VIDEO_LINUX_VIDEO_CAPTURE_GPU_MEMORY_BUFFER_MANAGER_H_ | ||
#define MEDIA_CAPTURE_VIDEO_LINUX_VIDEO_CAPTURE_GPU_MEMORY_BUFFER_MANAGER_H_ | ||
|
||
#include "base/no_destructor.h" | ||
#include "base/observer_list.h" | ||
#include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | ||
#include "media/capture/capture_export.h" | ||
|
||
namespace media { | ||
|
||
class VideoCaptureGpuContextLostObserver { | ||
public: | ||
virtual void OnContextLost() = 0; | ||
|
||
protected: | ||
virtual ~VideoCaptureGpuContextLostObserver() = default; | ||
}; | ||
|
||
// GPU memory buffer manager for Linux Video Capture. | ||
// This class provides the access to `gpu::GpuMemoryBufferManager` for the | ||
// `V4L2GpuMemoryBufferTracker`. It listens the GPU context lost event and | ||
// broadcast it to trackers. | ||
class CAPTURE_EXPORT VideoCaptureGpuMemoryBufferManager final | ||
: public VideoCaptureGpuContextLostObserver { | ||
public: | ||
static VideoCaptureGpuMemoryBufferManager& GetInstance(); | ||
|
||
VideoCaptureGpuMemoryBufferManager( | ||
const VideoCaptureGpuMemoryBufferManager&) = delete; | ||
VideoCaptureGpuMemoryBufferManager& operator=( | ||
const VideoCaptureGpuMemoryBufferManager&) = delete; | ||
|
||
// Set gpu::GpuMemoryBufferManager by | ||
// `VideoCaptureServiceImpl::VizGpuContextProvider` from the main thead of | ||
// utility process. It will be set with | ||
// `viz::Gpu::GetGpuMemoryBufferManager()` when calling | ||
// `VideoCaptureServiceImpl::VizGpuContextProvider::StartContextProviderIfNeeded()` | ||
// success or set to nullptr if failed. | ||
void SetGpuMemoryBufferManager(gpu::GpuMemoryBufferManager*); | ||
|
||
// This method is called by `V4L2GpuMemoryBufferTracker::Init()` from the | ||
// single thread task runner created in the | ||
// `VideoCaptureDeviceLinux::VideoCaptureDeviceLinux()`. It will be called | ||
// when VideoCaptureBufferPoolImpl want to create new tracker for the v4l2 | ||
// camera capture data. It will return nullptr when | ||
// `VideoCaptureServiceImpl::VizGpuContextProvider::StartContextProviderIfNeeded()` | ||
// failed. | ||
gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager(); | ||
|
||
// VideoCaptureGpuContextLostObserver implementation. | ||
void OnContextLost() override; | ||
|
||
void AddObserver(VideoCaptureGpuContextLostObserver*); | ||
void RemoveObserver(VideoCaptureGpuContextLostObserver*); | ||
|
||
private: | ||
friend class base::NoDestructor<VideoCaptureGpuMemoryBufferManager>; | ||
|
||
VideoCaptureGpuMemoryBufferManager(); | ||
~VideoCaptureGpuMemoryBufferManager() override; | ||
|
||
mutable base::Lock lock_; | ||
// The |gpu_buffer_manager_| is nullptr before set by the | ||
// `VideoCaptureServiceImpl::VizGpuContextProvider::StartContextProviderIfNeeded()` | ||
// which is called with the memory buffer manager that viz::Gpu owns. | ||
raw_ptr<gpu::GpuMemoryBufferManager> gpu_buffer_manager_ GUARDED_BY(lock_); | ||
|
||
// Protects observer list. The observer list will be operated from the | ||
// |v4l2_task_runner| of V4L2CaptureDelegate and the |main_task_runner_| of | ||
// VideoCaptureServiceImpl::VizGpuContextProvider. | ||
base::ObserverList<VideoCaptureGpuContextLostObserver>::Unchecked observers_ | ||
GUARDED_BY(lock_); | ||
}; | ||
|
||
} // namespace media | ||
|
||
#endif // MEDIA_CAPTURE_VIDEO_LINUX_VIDEO_CAPTURE_GPU_MEMORY_BUFFER_MANAGER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters