blob: 821acd66aaaedeaa627e33ebaab36e9b5fa08a6a [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);
Lu Liuec841072017-12-20 18:37:17 +000020 rtc::scoped_refptr<webrtc::PlanarYuvBuffer> buffer(
21 frame.video_frame_buffer()->ToI420());
22 if (OnI420FrameReady) {
23 OnI420FrameReady(buffer->DataY(), buffer->DataU(), buffer->DataV(),
24 buffer->StrideY(), buffer->StrideU(), buffer->StrideV(),
gyzhoub38f3862017-07-25 16:04:31 -070025 frame.width(), frame.height());
26 }
27}