blob: 682e7b6bae679a7ee5a90fc4edd983dd6ac356c0 [file] [log] [blame]
Peter Boströmeb66e802015-06-05 11:08:03 +02001/*
2 * Copyright (c) 2015 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#ifndef WEBRTC_TEST_FAKE_TEXTURE_FRAME_H_
11#define WEBRTC_TEST_FAKE_TEXTURE_FRAME_H_
12
13#include "webrtc/base/checks.h"
14#include "webrtc/common_video/interface/video_frame_buffer.h"
15#include "webrtc/video_frame.h"
16
17namespace webrtc {
18namespace test {
19
20class FakeNativeHandle {};
21
22class FakeNativeHandleBuffer : public NativeHandleBuffer {
23 public:
24 FakeNativeHandleBuffer(void* native_handle, int width, int height)
25 : NativeHandleBuffer(native_handle, width, height) {}
26
27 ~FakeNativeHandleBuffer() {
28 delete reinterpret_cast<FakeNativeHandle*>(native_handle_);
29 }
30
31 private:
32 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override {
33 rtc::scoped_refptr<VideoFrameBuffer> buffer(
34 new rtc::RefCountedObject<I420Buffer>(width_, height_));
35 int half_height = (height_ + 1) / 2;
36 int half_width = (width_ + 1) / 2;
37 memset(buffer->data(kYPlane), 0, height_ * width_);
38 memset(buffer->data(kUPlane), 0, half_height * half_width);
39 memset(buffer->data(kVPlane), 0, half_height * half_width);
40 return buffer;
41 }
42};
43
44static VideoFrame CreateFakeNativeHandleFrame(FakeNativeHandle* native_handle,
45 int width,
46 int height,
47 uint32_t timestamp,
48 int64_t render_time_ms,
49 VideoRotation rotation) {
50 return VideoFrame(new rtc::RefCountedObject<FakeNativeHandleBuffer>(
51 native_handle, width, height),
52 timestamp, render_time_ms, rotation);
53}
54} // namespace test
55} // namespace webrtc
56#endif // WEBRTC_TEST_FAKE_TEXTURE_FRAME_H_