#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/platform/video_capture/video_capture_impl.h"
#include <GLES2/gl2extchromium.h>
#include <stddef.h>
#include <algorithm>
#include <memory>
#include <utility>
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/task/bind_post_task.h"
#include "base/task/sequenced_task_runner.h"
#include "base/token.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "gpu/command_buffer/client/client_shared_image.h"
#include "gpu/command_buffer/client/shared_image_interface.h"
#include "gpu/command_buffer/common/shared_image_usage.h"
#include "gpu/ipc/common/gpu_memory_buffer_support.h"
#include "media/base/limits.h"
#include "media/base/video_frame.h"
#include "media/capture/mojom/video_capture_buffer.mojom-blink.h"
#include "media/capture/mojom/video_capture_types.mojom-blink.h"
#include "media/capture/video_capture_types.h"
#include "media/video/gpu_video_accelerator_factories.h"
#include "third_party/blink/public/common/thread_safe_browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/thread_safe_ref_counted.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
#if BUILDFLAG(IS_MAC)
#include "media/base/mac/video_frame_mac.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "gpu/command_buffer/common/shared_image_capabilities.h"
#endif
namespace blink {
constexpr int kMaxFirstFrameLogs = …;
BASE_FEATURE(…);
VideoFrameBufferHandleType;
struct GpuMemoryBufferResources { … };
struct VideoCaptureImpl::BufferContext
: public ThreadSafeRefCounted<BufferContext> { … };
struct VideoCaptureImpl::VideoFrameInitData { … };
std::optional<VideoCaptureImpl::VideoFrameInitData>
VideoCaptureImpl::CreateVideoFrameInitData(
media::mojom::blink::ReadyBufferPtr ready_buffer) { … }
bool VideoCaptureImpl::BindVideoFrameOnMediaTaskRunner(
media::GpuVideoAcceleratorFactories* gpu_factories,
VideoFrameInitData& video_frame_init_data,
base::OnceCallback<void()> on_gmb_not_supported) { … }
struct VideoCaptureImpl::ClientInfo { … };
VideoCaptureImpl::VideoCaptureImpl(
media::VideoCaptureSessionId session_id,
scoped_refptr<base::SequencedTaskRunner> main_task_runner,
const BrowserInterfaceBrokerProxy& browser_interface_broker)
: … { … }
void VideoCaptureImpl::OnGpuContextLost(
base::WeakPtr<VideoCaptureImpl> video_capture_impl) { … }
void VideoCaptureImpl::SetGpuFactoriesHandleOnIOTaskRunner(
media::GpuVideoAcceleratorFactories* gpu_factories) { … }
VideoCaptureImpl::~VideoCaptureImpl() { … }
void VideoCaptureImpl::SuspendCapture(bool suspend) { … }
void VideoCaptureImpl::StartCapture(
int client_id,
const media::VideoCaptureParams& params,
const VideoCaptureStateUpdateCB& state_update_cb,
const VideoCaptureDeliverFrameCB& deliver_frame_cb,
const VideoCaptureSubCaptureTargetVersionCB& sub_capture_target_version_cb,
const VideoCaptureNotifyFrameDroppedCB& frame_dropped_cb) { … }
void VideoCaptureImpl::StopCapture(int client_id) { … }
void VideoCaptureImpl::RequestRefreshFrame() { … }
void VideoCaptureImpl::GetDeviceSupportedFormats(
VideoCaptureDeviceFormatsCallback callback) { … }
void VideoCaptureImpl::GetDeviceFormatsInUse(
VideoCaptureDeviceFormatsCallback callback) { … }
void VideoCaptureImpl::OnLog(const String& message) { … }
void VideoCaptureImpl::SetGpuMemoryBufferSupportForTesting(
std::unique_ptr<gpu::GpuMemoryBufferSupport> gpu_memory_buffer_support) { … }
void VideoCaptureImpl::OnStateChanged(
media::mojom::blink::VideoCaptureResultPtr result) { … }
void VideoCaptureImpl::OnNewBuffer(
int32_t buffer_id,
media::mojom::blink::VideoBufferHandlePtr buffer_handle) { … }
void VideoCaptureImpl::OnBufferReady(
media::mojom::blink::ReadyBufferPtr buffer) { … }
void VideoCaptureImpl::OnVideoFrameReady(
base::TimeTicks reference_time,
VideoFrameInitData video_frame_init_data) { … }
void VideoCaptureImpl::OnBufferDestroyed(int32_t buffer_id) { … }
void VideoCaptureImpl::OnFrameDropped(
media::VideoCaptureFrameDropReason reason) { … }
void VideoCaptureImpl::OnNewSubCaptureTargetVersion(
uint32_t sub_capture_target_version) { … }
constexpr base::TimeDelta VideoCaptureImpl::kCaptureStartTimeout;
void VideoCaptureImpl::OnAllClientsFinishedConsumingFrame(
int buffer_id,
scoped_refptr<BufferContext> buffer_context) { … }
void VideoCaptureImpl::StopDevice() { … }
void VideoCaptureImpl::RestartCapture() { … }
void VideoCaptureImpl::StartCaptureInternal() { … }
void VideoCaptureImpl::OnStartTimedout() { … }
void VideoCaptureImpl::OnDeviceSupportedFormats(
VideoCaptureDeviceFormatsCallback callback,
const Vector<media::VideoCaptureFormat>& supported_formats) { … }
void VideoCaptureImpl::OnDeviceFormatsInUse(
VideoCaptureDeviceFormatsCallback callback,
const Vector<media::VideoCaptureFormat>& formats_in_use) { … }
bool VideoCaptureImpl::RemoveClient(int client_id, ClientInfoMap* clients) { … }
media::mojom::blink::VideoCaptureHost* VideoCaptureImpl::GetVideoCaptureHost() { … }
void VideoCaptureImpl::RecordStartOutcomeUMA(
media::VideoCaptureError error_code) { … }
void VideoCaptureImpl::DidFinishConsumingFrame(
BufferFinishedCallback callback_to_io_thread) { … }
void VideoCaptureImpl::ProcessFeedback(
const media::VideoCaptureFeedback& feedback) { … }
void VideoCaptureImpl::OnGmbNotSupported() { … }
void VideoCaptureImpl::RequirePremappedFrames() { … }
media::VideoCaptureFeedback VideoCaptureImpl::DefaultFeedback() { … }
base::WeakPtr<VideoCaptureImpl> VideoCaptureImpl::GetWeakPtr() { … }
}