blob: 7e33b08e27b0706e85ccece546e4e6ab6d72a2b8 [file] [log] [blame]
gyzhoub38f3862017-07-25 16:04:31 -07001/*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "examples/unityplugin/video_observer.h"
gyzhoub38f3862017-07-25 16:04:31 -070012
13void VideoObserver::SetVideoCallback(I420FRAMEREADY_CALLBACK callback) {
14 std::lock_guard<std::mutex> lock(mutex);
15 OnI420FrameReady = callback;
16}
17
18void VideoObserver::OnFrame(const webrtc::VideoFrame& frame) {
19 std::unique_lock<std::mutex> lock(mutex);
Qiang Chen43fb9122017-12-20 10:47:36 -080020 if (!OnI420FrameReady)
21 return;
22
23 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer(
24 frame.video_frame_buffer());
25
26 if (buffer->type() != webrtc::VideoFrameBuffer::Type::kI420A) {
27 rtc::scoped_refptr<webrtc::I420BufferInterface> i420_buffer =
28 buffer->ToI420();
29 OnI420FrameReady(i420_buffer->DataY(), i420_buffer->DataU(),
30 i420_buffer->DataV(), nullptr, i420_buffer->StrideY(),
31 i420_buffer->StrideU(), i420_buffer->StrideV(), 0,
32 frame.width(), frame.height());
33
34 } else {
35 // The buffer has alpha channel.
Ilya Nikolaevskiya8507e32019-05-03 11:39:26 +020036 const webrtc::I420ABufferInterface* i420a_buffer = buffer->GetI420A();
Qiang Chen43fb9122017-12-20 10:47:36 -080037
38 OnI420FrameReady(i420a_buffer->DataY(), i420a_buffer->DataU(),
39 i420a_buffer->DataV(), i420a_buffer->DataA(),
40 i420a_buffer->StrideY(), i420a_buffer->StrideU(),
41 i420a_buffer->StrideV(), i420a_buffer->StrideA(),
gyzhoub38f3862017-07-25 16:04:31 -070042 frame.width(), frame.height());
43 }
44}