From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../examples/unityplugin/video_observer.cc | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 third_party/libwebrtc/examples/unityplugin/video_observer.cc (limited to 'third_party/libwebrtc/examples/unityplugin/video_observer.cc') diff --git a/third_party/libwebrtc/examples/unityplugin/video_observer.cc b/third_party/libwebrtc/examples/unityplugin/video_observer.cc new file mode 100644 index 0000000000..7e33b08e27 --- /dev/null +++ b/third_party/libwebrtc/examples/unityplugin/video_observer.cc @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "examples/unityplugin/video_observer.h" + +void VideoObserver::SetVideoCallback(I420FRAMEREADY_CALLBACK callback) { + std::lock_guard lock(mutex); + OnI420FrameReady = callback; +} + +void VideoObserver::OnFrame(const webrtc::VideoFrame& frame) { + std::unique_lock lock(mutex); + if (!OnI420FrameReady) + return; + + rtc::scoped_refptr buffer( + frame.video_frame_buffer()); + + if (buffer->type() != webrtc::VideoFrameBuffer::Type::kI420A) { + rtc::scoped_refptr i420_buffer = + buffer->ToI420(); + OnI420FrameReady(i420_buffer->DataY(), i420_buffer->DataU(), + i420_buffer->DataV(), nullptr, i420_buffer->StrideY(), + i420_buffer->StrideU(), i420_buffer->StrideV(), 0, + frame.width(), frame.height()); + + } else { + // The buffer has alpha channel. + const webrtc::I420ABufferInterface* i420a_buffer = buffer->GetI420A(); + + OnI420FrameReady(i420a_buffer->DataY(), i420a_buffer->DataU(), + i420a_buffer->DataV(), i420a_buffer->DataA(), + i420a_buffer->StrideY(), i420a_buffer->StrideU(), + i420a_buffer->StrideV(), i420a_buffer->StrideA(), + frame.width(), frame.height()); + } +} -- cgit v1.2.3