Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / media / cast / sender / external_video_encoder_unittest.cc
blob78359f3408cab4ba89ddde0d974667b5b73c6b84
1 // Copyright 2015 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.
5 #include "media/cast/sender/external_video_encoder.h"
7 #include "media/base/video_frame.h"
8 #include "media/base/video_types.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace media {
12 namespace cast {
14 namespace {
16 scoped_refptr<VideoFrame> CreateFrame(const uint8* y_plane_data,
17 const gfx::Size& size) {
18 scoped_refptr<VideoFrame> result = VideoFrame::CreateFrame(PIXEL_FORMAT_I420,
19 size,
20 gfx::Rect(size),
21 size,
22 base::TimeDelta());
23 for (int y = 0, y_end = size.height(); y < y_end; ++y) {
24 memcpy(result->visible_data(VideoFrame::kYPlane) +
25 y * result->stride(VideoFrame::kYPlane),
26 y_plane_data + y * size.width(),
27 size.width());
29 return result;
32 } // namespace
34 TEST(QuantizerEstimator, EstimatesForTrivialFrames) {
35 QuantizerEstimator qe;
37 const gfx::Size frame_size(320, 180);
38 const scoped_ptr<uint8[]> black_frame_data(new uint8[frame_size.GetArea()]);
39 memset(black_frame_data.get(), 0, frame_size.GetArea());
40 const scoped_refptr<VideoFrame> black_frame =
41 CreateFrame(black_frame_data.get(), frame_size);
43 // A solid color frame should always generate a minimum quantizer value (4.0)
44 // as a key frame. If it is provided repeatedly as delta frames, the minimum
45 // quantizer value should be repeatedly generated since there is no difference
46 // between frames.
47 EXPECT_EQ(4.0, qe.EstimateForKeyFrame(*black_frame));
48 for (int i = 0; i < 3; ++i)
49 EXPECT_EQ(4.0, qe.EstimateForDeltaFrame(*black_frame));
51 const scoped_ptr<uint8[]> checkerboard_frame_data(
52 new uint8[frame_size.GetArea()]);
53 for (int i = 0, end = frame_size.GetArea(); i < end; ++i)
54 checkerboard_frame_data.get()[i] = (((i % 2) == 0) ? 0 : 255);
55 const scoped_refptr<VideoFrame> checkerboard_frame =
56 CreateFrame(checkerboard_frame_data.get(), frame_size);
58 // Now, introduce a frame with a checkerboard pattern. Half of the pixels
59 // will have a difference of 255, and half will have zero difference.
60 // Therefore, the Shannon Entropy should be 1.0 and the resulting quantizer
61 // estimate should be ~11.9.
62 EXPECT_NEAR(11.9, qe.EstimateForDeltaFrame(*checkerboard_frame), 0.1);
64 // Now, introduce a series of frames with "random snow" in them. Expect this
65 // results in high quantizer estimates.
66 for (int i = 0; i < 3; ++i) {
67 int rand_seed = 0xdeadbeef + i;
68 const scoped_ptr<uint8[]> random_frame_data(
69 new uint8[frame_size.GetArea()]);
70 for (int j = 0, end = frame_size.GetArea(); j < end; ++j) {
71 rand_seed = (1103515245 * rand_seed + 12345) % (1 << 31);
72 random_frame_data.get()[j] = static_cast<uint8>(rand_seed & 0xff);
74 const scoped_refptr<VideoFrame> random_frame =
75 CreateFrame(random_frame_data.get(), frame_size);
76 EXPECT_LE(50.0, qe.EstimateForDeltaFrame(*random_frame));
80 } // namespace cast
81 } // namespace media