blob: d4f2e2977ffdbc839f859ccca0acd3c447c8aa09 [file] [log] [blame]
David Ghandehari9e5b5872016-07-28 09:50:04 -07001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/memory/scoped_ptr.h"
6#include "media/base/video_frame.h"
7#include "media/base/video_util.h"
8#include "testing/gtest/include/gtest/gtest.h"
9
10namespace media {
11
12class VideoUtilTest : public testing::Test {
13 public:
14 VideoUtilTest()
15 : height_(0),
16 y_stride_(0),
17 u_stride_(0),
18 v_stride_(0) {
19 }
20
21 virtual ~VideoUtilTest() {}
22
23 void CreateSourceFrame(int width, int height,
24 int y_stride, int u_stride, int v_stride) {
25 EXPECT_GE(y_stride, width);
26 EXPECT_GE(u_stride, width / 2);
27 EXPECT_GE(v_stride, width / 2);
28
29 height_ = height;
30 y_stride_ = y_stride;
31 u_stride_ = u_stride;
32 v_stride_ = v_stride;
33
34 y_plane_.reset(new uint8[y_stride * height]);
35 u_plane_.reset(new uint8[u_stride * height / 2]);
36 v_plane_.reset(new uint8[v_stride * height / 2]);
37 }
38
39 void CreateDestinationFrame(int width, int height) {
40 gfx::Size size(width, height);
41 destination_frame_ =
42 VideoFrame::CreateFrame(VideoFrame::YV12, size, gfx::Rect(size), size,
43 base::TimeDelta());
44 }
45
46 void CopyPlanes() {
47 CopyYPlane(y_plane_.get(), y_stride_, height_, destination_frame_);
48 CopyUPlane(u_plane_.get(), u_stride_, height_ / 2, destination_frame_);
49 CopyVPlane(v_plane_.get(), v_stride_, height_ / 2, destination_frame_);
50 }
51
52 private:
53 scoped_array<uint8> y_plane_;
54 scoped_array<uint8> u_plane_;
55 scoped_array<uint8> v_plane_;
56
57 int height_;
58 int y_stride_;
59 int u_stride_;
60 int v_stride_;
61
62 scoped_refptr<VideoFrame> destination_frame_;
63
64 DISALLOW_COPY_AND_ASSIGN(VideoUtilTest);
65};
66
67TEST_F(VideoUtilTest, CopyPlane_Exact) {
68 CreateSourceFrame(16, 16, 16, 8, 8);
69 CreateDestinationFrame(16, 16);
70 CopyPlanes();
71}
72
73TEST_F(VideoUtilTest, CopyPlane_SmallerSource) {
74 CreateSourceFrame(8, 8, 8, 4, 4);
75 CreateDestinationFrame(16, 16);
76 CopyPlanes();
77}
78
79TEST_F(VideoUtilTest, CopyPlane_SmallerDestination) {
80 CreateSourceFrame(16, 16, 16, 8, 8);
81 CreateDestinationFrame(8, 8);
82 CopyPlanes();
83}
84
85} // namespace media