Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // 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 | 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 <deque> | 5 #include <deque> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
| 12 #include "ppapi/cpp/image_data.h" | |
|
Wez
2012/02/07 01:56:31
Is this needed?
alexeypa (please no reviews)
2012/02/15 23:06:22
No. Removed.
| |
| 12 #include "remoting/base/base_mock_objects.h" | 13 #include "remoting/base/base_mock_objects.h" |
| 13 #include "remoting/base/codec_test.h" | 14 #include "remoting/base/codec_test.h" |
| 14 #include "remoting/base/decoder.h" | 15 #include "remoting/base/decoder.h" |
| 15 #include "remoting/base/encoder.h" | 16 #include "remoting/base/encoder.h" |
| 16 #include "remoting/base/util.h" | 17 #include "remoting/base/util.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 static const int kWidth = 320; | 20 static const int kWidth = 320; |
| 20 static const int kHeight = 240; | 21 static const int kHeight = 240; |
| 21 static const int kBytesPerPixel = 4; | 22 static const int kBytesPerPixel = 4; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 std::deque<SkIRect> rects_; | 117 std::deque<SkIRect> rects_; |
| 117 | 118 |
| 118 DISALLOW_COPY_AND_ASSIGN(EncoderMessageTester); | 119 DISALLOW_COPY_AND_ASSIGN(EncoderMessageTester); |
| 119 }; | 120 }; |
| 120 | 121 |
| 121 class DecoderTester { | 122 class DecoderTester { |
| 122 public: | 123 public: |
| 123 DecoderTester(Decoder* decoder) | 124 DecoderTester(Decoder* decoder) |
| 124 : strict_(false), | 125 : strict_(false), |
| 125 decoder_(decoder) { | 126 decoder_(decoder) { |
| 126 frame_ = media::VideoFrame::CreateFrame(media::VideoFrame::RGB32, | 127 image_data_.reset(new uint8[kWidth * kHeight * kBytesPerPixel]); |
| 127 kWidth, kHeight, | 128 EXPECT_TRUE(image_data_.get()); |
| 128 base::TimeDelta(), | 129 decoder_->Initialize(SkISize::Make(kWidth, kHeight)); |
| 129 base::TimeDelta()); | |
| 130 EXPECT_TRUE(frame_.get()); | |
| 131 decoder_->Initialize(frame_); | |
| 132 } | 130 } |
| 133 | 131 |
| 134 void Reset() { | 132 void Reset() { |
| 135 expected_region_.setEmpty(); | 133 expected_region_.setEmpty(); |
| 136 update_region_.setEmpty(); | 134 update_region_.setEmpty(); |
| 137 } | 135 } |
| 138 | 136 |
| 139 void ReceivedPacket(VideoPacket* packet) { | 137 void ReceivedPacket(VideoPacket* packet) { |
| 140 Decoder::DecodeResult result = decoder_->DecodePacket(packet); | 138 Decoder::DecodeResult result = decoder_->DecodePacket(packet); |
| 141 | 139 |
| 142 ASSERT_NE(Decoder::DECODE_ERROR, result); | 140 ASSERT_NE(Decoder::DECODE_ERROR, result); |
| 143 | 141 |
| 144 if (result == Decoder::DECODE_DONE) { | 142 if (result == Decoder::DECODE_DONE) { |
| 145 decoder_->GetUpdatedRegion(&update_region_); | 143 decoder_->Draw(SkISize::Make(kWidth, kHeight), |
| 144 SkIRect::MakeXYWH(0, 0, kWidth, kHeight), | |
| 145 image_data_.get(), | |
| 146 kWidth * kBytesPerPixel, | |
| 147 &update_region_); | |
| 146 } | 148 } |
| 147 } | 149 } |
| 148 | 150 |
| 149 void set_strict(bool strict) { | 151 void set_strict(bool strict) { |
| 150 strict_ = strict; | 152 strict_ = strict; |
| 151 } | 153 } |
| 152 | 154 |
| 153 void set_capture_data(scoped_refptr<CaptureData> data) { | 155 void set_capture_data(scoped_refptr<CaptureData> data) { |
| 154 capture_data_ = data; | 156 capture_data_ = data; |
| 155 } | 157 } |
| 156 | 158 |
| 157 void AddRects(const SkIRect* rects, int count) { | 159 void AddRects(const SkIRect* rects, int count) { |
| 158 SkRegion new_rects; | 160 SkRegion new_rects; |
| 159 new_rects.setRects(rects, count); | 161 new_rects.setRects(rects, count); |
| 160 expected_region_.op(new_rects, SkRegion::kUnion_Op); | 162 expected_region_.op(new_rects, SkRegion::kUnion_Op); |
| 161 } | 163 } |
| 162 | 164 |
| 163 void VerifyResults() { | 165 void VerifyResults() { |
| 164 if (!strict_) | 166 if (!strict_) |
| 165 return; | 167 return; |
| 166 | 168 |
| 167 ASSERT_TRUE(capture_data_.get()); | 169 ASSERT_TRUE(capture_data_.get()); |
| 168 | 170 |
| 169 // Test the content of the update region. | 171 // Test the content of the update region. |
| 170 EXPECT_EQ(expected_region_, update_region_); | 172 EXPECT_EQ(expected_region_, update_region_); |
| 171 for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) { | 173 for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) { |
| 172 EXPECT_EQ(frame_->stride(0), capture_data_->data_planes().strides[0]); | 174 const int stride = kWidth * kBytesPerPixel; |
| 173 const int stride = frame_->stride(0); | 175 EXPECT_EQ(stride, capture_data_->data_planes().strides[0]); |
| 174 const int offset = stride * i.rect().top() + | 176 const int offset = stride * i.rect().top() + |
| 175 kBytesPerPixel * i.rect().left(); | 177 kBytesPerPixel * i.rect().left(); |
| 176 const uint8* original = capture_data_->data_planes().data[0] + offset; | 178 const uint8* original = capture_data_->data_planes().data[0] + offset; |
| 177 const uint8* decoded = frame_->data(0) + offset; | 179 const uint8* decoded = image_data_.get() + offset; |
| 178 const int row_size = kBytesPerPixel * i.rect().width(); | 180 const int row_size = kBytesPerPixel * i.rect().width(); |
| 179 for (int y = 0; y < i.rect().height(); ++y) { | 181 for (int y = 0; y < i.rect().height(); ++y) { |
| 180 EXPECT_EQ(0, memcmp(original, decoded, row_size)) | 182 EXPECT_EQ(0, memcmp(original, decoded, row_size)) |
| 181 << "Row " << y << " is different"; | 183 << "Row " << y << " is different"; |
| 182 original += stride; | 184 original += stride; |
| 183 decoded += stride; | 185 decoded += stride; |
| 184 } | 186 } |
| 185 } | 187 } |
| 186 } | 188 } |
| 187 | 189 |
| 188 private: | 190 private: |
| 189 bool strict_; | 191 bool strict_; |
| 190 SkRegion expected_region_; | 192 SkRegion expected_region_; |
| 191 SkRegion update_region_; | 193 SkRegion update_region_; |
| 192 Decoder* decoder_; | 194 Decoder* decoder_; |
| 193 scoped_refptr<media::VideoFrame> frame_; | 195 scoped_array<uint8> image_data_; |
| 194 scoped_refptr<CaptureData> capture_data_; | 196 scoped_refptr<CaptureData> capture_data_; |
| 195 | 197 |
| 196 DISALLOW_COPY_AND_ASSIGN(DecoderTester); | 198 DISALLOW_COPY_AND_ASSIGN(DecoderTester); |
| 197 }; | 199 }; |
| 198 | 200 |
| 199 // The EncoderTester provides a hook for retrieving the data, and passing the | 201 // The EncoderTester provides a hook for retrieving the data, and passing the |
| 200 // message to other subprograms for validaton. | 202 // message to other subprograms for validaton. |
| 201 class EncoderTester { | 203 class EncoderTester { |
| 202 public: | 204 public: |
| 203 EncoderTester(EncoderMessageTester* message_tester) | 205 EncoderTester(EncoderMessageTester* message_tester) |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 kTestRects, 1); | 344 kTestRects, 1); |
| 343 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, | 345 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, |
| 344 kTestRects + 1, 1); | 346 kTestRects + 1, 1); |
| 345 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, | 347 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, |
| 346 kTestRects + 2, 1); | 348 kTestRects + 2, 1); |
| 347 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, | 349 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, |
| 348 kTestRects + 3, 2); | 350 kTestRects + 3, 2); |
| 349 } | 351 } |
| 350 | 352 |
| 351 } // namespace remoting | 353 } // namespace remoting |
| OLD | NEW |