| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/cast/sender/external_video_encoder.h" | 5 #include "media/cast/sender/external_video_encoder.h" |
| 6 | 6 |
| 7 #include "media/base/video_frame.h" | 7 #include "media/base/video_frame.h" |
| 8 #include "media/base/video_types.h" | 8 #include "media/base/video_types.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace media { | 11 namespace media { |
| 12 namespace cast { | 12 namespace cast { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 scoped_refptr<VideoFrame> CreateFrame(const uint8* y_plane_data, | 16 scoped_refptr<VideoFrame> CreateFrame(const uint8_t* y_plane_data, |
| 17 const gfx::Size& size) { | 17 const gfx::Size& size) { |
| 18 scoped_refptr<VideoFrame> result = VideoFrame::CreateFrame(PIXEL_FORMAT_I420, | 18 scoped_refptr<VideoFrame> result = VideoFrame::CreateFrame(PIXEL_FORMAT_I420, |
| 19 size, | 19 size, |
| 20 gfx::Rect(size), | 20 gfx::Rect(size), |
| 21 size, | 21 size, |
| 22 base::TimeDelta()); | 22 base::TimeDelta()); |
| 23 for (int y = 0, y_end = size.height(); y < y_end; ++y) { | 23 for (int y = 0, y_end = size.height(); y < y_end; ++y) { |
| 24 memcpy(result->visible_data(VideoFrame::kYPlane) + | 24 memcpy(result->visible_data(VideoFrame::kYPlane) + |
| 25 y * result->stride(VideoFrame::kYPlane), | 25 y * result->stride(VideoFrame::kYPlane), |
| 26 y_plane_data + y * size.width(), | 26 y_plane_data + y * size.width(), |
| 27 size.width()); | 27 size.width()); |
| 28 } | 28 } |
| 29 return result; | 29 return result; |
| 30 } | 30 } |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 TEST(QuantizerEstimator, EstimatesForTrivialFrames) { | 34 TEST(QuantizerEstimator, EstimatesForTrivialFrames) { |
| 35 QuantizerEstimator qe; | 35 QuantizerEstimator qe; |
| 36 | 36 |
| 37 const gfx::Size frame_size(320, 180); | 37 const gfx::Size frame_size(320, 180); |
| 38 const scoped_ptr<uint8[]> black_frame_data(new uint8[frame_size.GetArea()]); | 38 const scoped_ptr<uint8_t[]> black_frame_data( |
| 39 new uint8_t[frame_size.GetArea()]); |
| 39 memset(black_frame_data.get(), 0, frame_size.GetArea()); | 40 memset(black_frame_data.get(), 0, frame_size.GetArea()); |
| 40 const scoped_refptr<VideoFrame> black_frame = | 41 const scoped_refptr<VideoFrame> black_frame = |
| 41 CreateFrame(black_frame_data.get(), frame_size); | 42 CreateFrame(black_frame_data.get(), frame_size); |
| 42 | 43 |
| 43 // A solid color frame should always generate a minimum quantizer value (4.0) | 44 // 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 // 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 // quantizer value should be repeatedly generated since there is no difference |
| 46 // between frames. | 47 // between frames. |
| 47 EXPECT_EQ(4.0, qe.EstimateForKeyFrame(*black_frame)); | 48 EXPECT_EQ(4.0, qe.EstimateForKeyFrame(*black_frame)); |
| 48 for (int i = 0; i < 3; ++i) | 49 for (int i = 0; i < 3; ++i) |
| 49 EXPECT_EQ(4.0, qe.EstimateForDeltaFrame(*black_frame)); | 50 EXPECT_EQ(4.0, qe.EstimateForDeltaFrame(*black_frame)); |
| 50 | 51 |
| 51 const scoped_ptr<uint8[]> checkerboard_frame_data( | 52 const scoped_ptr<uint8_t[]> checkerboard_frame_data( |
| 52 new uint8[frame_size.GetArea()]); | 53 new uint8_t[frame_size.GetArea()]); |
| 53 for (int i = 0, end = frame_size.GetArea(); i < end; ++i) | 54 for (int i = 0, end = frame_size.GetArea(); i < end; ++i) |
| 54 checkerboard_frame_data.get()[i] = (((i % 2) == 0) ? 0 : 255); | 55 checkerboard_frame_data.get()[i] = (((i % 2) == 0) ? 0 : 255); |
| 55 const scoped_refptr<VideoFrame> checkerboard_frame = | 56 const scoped_refptr<VideoFrame> checkerboard_frame = |
| 56 CreateFrame(checkerboard_frame_data.get(), frame_size); | 57 CreateFrame(checkerboard_frame_data.get(), frame_size); |
| 57 | 58 |
| 58 // Now, introduce a frame with a checkerboard pattern. Half of the pixels | 59 // 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 // 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 // Therefore, the Shannon Entropy should be 1.0 and the resulting quantizer |
| 61 // estimate should be ~11.9. | 62 // estimate should be ~11.9. |
| 62 EXPECT_NEAR(11.9, qe.EstimateForDeltaFrame(*checkerboard_frame), 0.1); | 63 EXPECT_NEAR(11.9, qe.EstimateForDeltaFrame(*checkerboard_frame), 0.1); |
| 63 | 64 |
| 64 // Now, introduce a series of frames with "random snow" in them. Expect this | 65 // Now, introduce a series of frames with "random snow" in them. Expect this |
| 65 // results in high quantizer estimates. | 66 // results in high quantizer estimates. |
| 66 for (int i = 0; i < 3; ++i) { | 67 for (int i = 0; i < 3; ++i) { |
| 67 int rand_seed = 0xdeadbeef + i; | 68 int rand_seed = 0xdeadbeef + i; |
| 68 const scoped_ptr<uint8[]> random_frame_data( | 69 const scoped_ptr<uint8_t[]> random_frame_data( |
| 69 new uint8[frame_size.GetArea()]); | 70 new uint8_t[frame_size.GetArea()]); |
| 70 for (int j = 0, end = frame_size.GetArea(); j < end; ++j) { | 71 for (int j = 0, end = frame_size.GetArea(); j < end; ++j) { |
| 71 rand_seed = (1103515245 * rand_seed + 12345) % (1 << 31); | 72 rand_seed = (1103515245 * rand_seed + 12345) % (1 << 31); |
| 72 random_frame_data.get()[j] = static_cast<uint8>(rand_seed & 0xff); | 73 random_frame_data.get()[j] = static_cast<uint8_t>(rand_seed & 0xff); |
| 73 } | 74 } |
| 74 const scoped_refptr<VideoFrame> random_frame = | 75 const scoped_refptr<VideoFrame> random_frame = |
| 75 CreateFrame(random_frame_data.get(), frame_size); | 76 CreateFrame(random_frame_data.get(), frame_size); |
| 76 EXPECT_LE(50.0, qe.EstimateForDeltaFrame(*random_frame)); | 77 EXPECT_LE(50.0, qe.EstimateForDeltaFrame(*random_frame)); |
| 77 } | 78 } |
| 78 } | 79 } |
| 79 | 80 |
| 80 } // namespace cast | 81 } // namespace cast |
| 81 } // namespace media | 82 } // namespace media |
| OLD | NEW |