diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-07 19:35:43 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-07 19:35:43 +0000 |
commit | 137e58f169fb978c4108f38e7275fefda5e45519 (patch) | |
tree | d7140551e654937e21fd897bf4b42de933b83fb2 /remoting | |
parent | 11b2483d225127bea7836957a61bb5d1b0f2547a (diff) | |
download | chromium_src-137e58f169fb978c4108f38e7275fefda5e45519.zip chromium_src-137e58f169fb978c4108f38e7275fefda5e45519.tar.gz chromium_src-137e58f169fb978c4108f38e7275fefda5e45519.tar.bz2 |
Reenable encoder/decoder tests.
BUG=57351
TEST=Unittests
Review URL: http://codereview.chromium.org/5635003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68504 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/base/codec_test.cc | 168 | ||||
-rw-r--r-- | remoting/base/codec_test.h | 2 | ||||
-rw-r--r-- | remoting/base/encode_decode_unittest.cc | 14 | ||||
-rw-r--r-- | remoting/base/encoder_row_based.cc | 12 | ||||
-rw-r--r-- | remoting/base/encoder_row_based.h | 2 | ||||
-rw-r--r-- | remoting/base/encoder_row_based_unittest.cc | 11 | ||||
-rw-r--r-- | remoting/remoting.gyp | 18 |
7 files changed, 81 insertions, 146 deletions
diff --git a/remoting/base/codec_test.cc b/remoting/base/codec_test.cc index dcc165e..0521b52d 100644 --- a/remoting/base/codec_test.cc +++ b/remoting/base/codec_test.cc @@ -29,42 +29,6 @@ static const gfx::Rect kTestRects[] = { namespace remoting { -// A class to test that the state transition of the Encoder is correct. -class EncoderStateTester { - public: - EncoderStateTester() - : next_state_(Encoder::EncodingStarting) { - } - - ~EncoderStateTester() { - EXPECT_EQ(Encoder::EncodingStarting, next_state_); - } - - // Set the state output of the Encoder. - void ReceivedState(Encoder::EncodingState state) { - if (state & Encoder::EncodingStarting) { - EXPECT_EQ(Encoder::EncodingStarting, next_state_); - next_state_ = Encoder::EncodingInProgress | Encoder::EncodingEnded; - } else { - EXPECT_FALSE(next_state_ & Encoder::EncodingStarting); - } - - if (state & Encoder::EncodingInProgress) { - EXPECT_TRUE(next_state_ & Encoder::EncodingInProgress); - } - - if (state & Encoder::EncodingEnded) { - EXPECT_TRUE(next_state_ & Encoder::EncodingEnded); - next_state_ = Encoder::EncodingStarting; - } - } - - private: - Encoder::EncodingState next_state_; - - DISALLOW_COPY_AND_ASSIGN(EncoderStateTester); -}; - // A class to test the message output of the encoder. class EncoderMessageTester { public: @@ -86,35 +50,31 @@ class EncoderMessageTester { } } - // Test that we received the correct message. - void ReceivedMessage(ChromotingHostMessage* message) { - EXPECT_TRUE(message->has_update_stream_packet()); - + // Test that we received the correct packet. + void ReceivedPacket(VideoPacket* packet) { if (state_ == kWaitingForBeginRect) { - EXPECT_TRUE(message->update_stream_packet().has_begin_rect()); + EXPECT_TRUE((packet->flags() & VideoPacket::FIRST_PACKET) != 0); state_ = kWaitingForRectData; ++begin_rect_; if (strict_) { gfx::Rect rect = rects_.front(); rects_.pop_front(); - EXPECT_EQ(rect.x(), message->update_stream_packet().begin_rect().x()); - EXPECT_EQ(rect.y(), message->update_stream_packet().begin_rect().y()); - EXPECT_EQ(rect.width(), - message->update_stream_packet().begin_rect().width()); - EXPECT_EQ(rect.height(), - message->update_stream_packet().begin_rect().height()); + EXPECT_EQ(rect.x(), packet->format().x()); + EXPECT_EQ(rect.y(), packet->format().y()); + EXPECT_EQ(rect.width(), packet->format().width()); + EXPECT_EQ(rect.height(), packet->format().height()); } } else { - EXPECT_FALSE(message->update_stream_packet().has_begin_rect()); + EXPECT_FALSE((packet->flags() & VideoPacket::FIRST_PACKET) != 0); } if (state_ == kWaitingForRectData) { - if (message->update_stream_packet().has_rect_data()) { + if (packet->has_data()) { ++rect_data_; } - if (message->update_stream_packet().has_end_rect()) { + if ((packet->flags() & VideoPacket::LAST_PACKET) != 0) { // Expect that we have received some data. EXPECT_GT(rect_data_, 0); rect_data_ = 0; @@ -155,32 +115,28 @@ class DecoderTester { public: DecoderTester(Decoder* decoder) : strict_(false), - decoder_(decoder), - decode_done_(false) { + decoder_(decoder) { media::VideoFrame::CreateFrame(media::VideoFrame::RGB32, kWidth, kHeight, base::TimeDelta(), base::TimeDelta(), &frame_); EXPECT_TRUE(frame_.get()); + decoder_->Initialize(frame_); } - void ReceivedMessage(ChromotingHostMessage* message) { - if (message->has_update_stream_packet()) { - EXPECT_TRUE(decoder_->PartialDecode(message)); - return; - } + void Reset() { + rects_.clear(); + update_rects_.clear(); + } - if (message->has_begin_update_stream()) { - EXPECT_TRUE(decoder_->BeginDecode( - frame_, &update_rects_, - NewRunnableMethod(this, &DecoderTester::OnPartialDecodeDone), - NewRunnableMethod(this, &DecoderTester::OnDecodeDone))); - } + void ReceivedPacket(VideoPacket* packet) { + Decoder::DecodeResult result = decoder_->DecodePacket(packet); + + ASSERT_NE(Decoder::DECODE_ERROR, result); - if (message->has_end_update_stream()) { - decoder_->EndDecode(); + if (result == Decoder::DECODE_DONE) { + decoder_->GetUpdatedRects(&update_rects_); } - delete message; } void set_strict(bool strict) { @@ -195,19 +151,16 @@ class DecoderTester { rects_.insert(rects_.begin() + rects_.size(), rects, rects + count); } - bool decode_done() const { return decode_done_; } - void reset_decode_done() { decode_done_ = false; } - - private: - void OnPartialDecodeDone() { + void VerifyResults() { if (!strict_) return; + ASSERT_TRUE(capture_data_.get()); + // Test the content of the update rect. + ASSERT_EQ(rects_.size(), update_rects_.size()); for (size_t i = 0; i < update_rects_.size(); ++i) { - EXPECT_FALSE(rects_.empty()); - gfx::Rect rect = rects_.front(); - rects_.pop_front(); + gfx::Rect rect = rects_[i]; EXPECT_EQ(rect, update_rects_[i]); EXPECT_EQ(frame_->stride(0), capture_data_->data_planes().strides[0]); @@ -226,29 +179,13 @@ class DecoderTester { } } - void OnDecodeDone() { - decode_done_ = true; - if (!strict_) - return; - - EXPECT_TRUE(capture_data_.get()); - for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { - if (!frame_->data(i) || !capture_data_->data_planes().data[i]) - continue; - // TODO(hclam): HAndle YUV. - int size = capture_data_->data_planes().strides[i] * kHeight; - EXPECT_EQ(0, memcmp(capture_data_->data_planes().data[i], - frame_->data(i), size)); - } - } - + private: bool strict_; std::deque<gfx::Rect> rects_; UpdatedRects update_rects_; Decoder* decoder_; scoped_refptr<media::VideoFrame> frame_; scoped_refptr<CaptureData> capture_data_; - bool decode_done_; DISALLOW_COPY_AND_ASSIGN(DecoderTester); }; @@ -257,10 +194,8 @@ class DecoderTester { // message to other subprograms for validaton. class EncoderTester { public: - EncoderTester(EncoderMessageTester* message_tester, - EncoderStateTester* state_tester) + EncoderTester(EncoderMessageTester* message_tester) : message_tester_(message_tester), - state_tester_(state_tester), decoder_tester_(NULL), data_available_(0) { } @@ -269,32 +204,16 @@ class EncoderTester { EXPECT_GT(data_available_, 0); } - void DataAvailable(ChromotingHostMessage* message, - Encoder::EncodingState state) { + void DataAvailable(VideoPacket *packet) { ++data_available_; - message_tester_->ReceivedMessage(message); - state_tester_->ReceivedState(state); + message_tester_->ReceivedPacket(packet); // Send the message to the DecoderTester. if (decoder_tester_) { - if (state & Encoder::EncodingStarting) { - ChromotingHostMessage* begin_update = new ChromotingHostMessage(); - begin_update->mutable_begin_update_stream(); - decoder_tester_->ReceivedMessage(begin_update); - } - - if (state & Encoder::EncodingInProgress) { - decoder_tester_->ReceivedMessage(message); - } - - if (state & Encoder::EncodingEnded) { - ChromotingHostMessage* end_update = new ChromotingHostMessage(); - end_update->mutable_end_update_stream(); - decoder_tester_->ReceivedMessage(end_update); - } - } else { - delete message; + decoder_tester_->ReceivedPacket(packet); } + + delete packet; } void AddRects(const gfx::Rect* rects, int count) { @@ -307,17 +226,16 @@ class EncoderTester { private: EncoderMessageTester* message_tester_; - EncoderStateTester* state_tester_; DecoderTester* decoder_tester_; int data_available_; DISALLOW_COPY_AND_ASSIGN(EncoderTester); }; -scoped_refptr<CaptureData> PrepareEncodeData(PixelFormat format, +scoped_refptr<CaptureData> PrepareEncodeData(media::VideoFrame::Format format, uint8** memory) { // TODO(hclam): Support also YUV format. - CHECK(format == PIXEL_FORMAT_RGB32); + CHECK_EQ(format, media::VideoFrame::RGB32); int size = kWidth * kHeight * kBytesPerPixel; *memory = new uint8[size]; @@ -355,12 +273,11 @@ void TestEncoder(Encoder* encoder, bool strict) { EncoderMessageTester message_tester; message_tester.set_strict(strict); - EncoderStateTester state_tester; - EncoderTester tester(&message_tester, &state_tester); + EncoderTester tester(&message_tester); uint8* memory; scoped_refptr<CaptureData> data = - PrepareEncodeData(PIXEL_FORMAT_RGB32, &memory); + PrepareEncodeData(media::VideoFrame::RGB32, &memory); TestEncodingRects(encoder, &tester, data, kTestRects, 1); TestEncodingRects(encoder, &tester, data, kTestRects + 1, 1); @@ -380,7 +297,6 @@ static void TestEncodingRects(Encoder* encoder, } encoder_tester->AddRects(rects, count); decoder_tester->AddRects(rects, count); - decoder_tester->reset_decode_done(); // Generate random data for the updated rects. srand(0); @@ -400,19 +316,19 @@ static void TestEncodingRects(Encoder* encoder, encoder->Encode(data, true, NewCallback(encoder_tester, &EncoderTester::DataAvailable)); - EXPECT_TRUE(decoder_tester->decode_done()); + decoder_tester->VerifyResults(); + decoder_tester->Reset(); } void TestEncoderDecoder(Encoder* encoder, Decoder* decoder, bool strict) { EncoderMessageTester message_tester; message_tester.set_strict(strict); - EncoderStateTester state_tester; - EncoderTester encoder_tester(&message_tester, &state_tester); + EncoderTester encoder_tester(&message_tester); uint8* memory; scoped_refptr<CaptureData> data = - PrepareEncodeData(PIXEL_FORMAT_RGB32, &memory); + PrepareEncodeData(media::VideoFrame::RGB32, &memory); DecoderTester decoder_tester(decoder); decoder_tester.set_strict(strict); decoder_tester.set_capture_data(data); diff --git a/remoting/base/codec_test.h b/remoting/base/codec_test.h index d5702dd..613a537 100644 --- a/remoting/base/codec_test.h +++ b/remoting/base/codec_test.h @@ -16,7 +16,7 @@ class Encoder; // Prepare testing data for encoding. Memory created is written to |memory|. // Returns randomly generated data in CaptureData. -scoped_refptr<CaptureData> PrepareEncodeData(PixelFormat format, +scoped_refptr<CaptureData> PrepareEncodeData(media::VideoFrame::Format format, uint8** memory); // Generate test data and test the encoder for a regular encoding sequence. diff --git a/remoting/base/encode_decode_unittest.cc b/remoting/base/encode_decode_unittest.cc index 4e859a6..d1d409d 100644 --- a/remoting/base/encode_decode_unittest.cc +++ b/remoting/base/encode_decode_unittest.cc @@ -5,29 +5,29 @@ #include "media/base/video_frame.h" #include "remoting/base/codec_test.h" #include "remoting/base/decoder_row_based.h" -#include "remoting/base/encoder_zlib.h" +#include "remoting/base/encoder_row_based.h" #include "testing/gtest/include/gtest/gtest.h" namespace remoting { TEST(EncodeDecodeTest, EncodeAndDecodeZlib) { - EncoderZlib encoder; + scoped_ptr<EncoderRowBased> encoder(EncoderRowBased::CreateZlibEncoder()); scoped_ptr<DecoderRowBased> decoder(DecoderRowBased::CreateZlibDecoder()); decoder->set_reverse_rows(false); - TestEncoderDecoder(&encoder, decoder.get(), true); + TestEncoderDecoder(encoder.get(), decoder.get(), true); } TEST(EncodeDecodeTest, EncodeAndDecodeSmallOutputBufferZlib) { - EncoderZlib encoder(64); + scoped_ptr<EncoderRowBased> encoder(EncoderRowBased::CreateZlibEncoder(64)); scoped_ptr<DecoderRowBased> decoder(DecoderRowBased::CreateZlibDecoder()); decoder->set_reverse_rows(false); - TestEncoderDecoder(&encoder, decoder.get(), true); + TestEncoderDecoder(encoder.get(), decoder.get(), true); } TEST(EncodeDecodeTest, EncodeAndDecodeNoneStrictZlib) { - EncoderZlib encoder; + scoped_ptr<EncoderRowBased> encoder(EncoderRowBased::CreateZlibEncoder()); scoped_ptr<DecoderRowBased> decoder(DecoderRowBased::CreateZlibDecoder()); - TestEncoderDecoder(&encoder, decoder.get(), false); + TestEncoderDecoder(encoder.get(), decoder.get(), false); } } // namespace remoting diff --git a/remoting/base/encoder_row_based.cc b/remoting/base/encoder_row_based.cc index a7919e1..6a797b2 100644 --- a/remoting/base/encoder_row_based.cc +++ b/remoting/base/encoder_row_based.cc @@ -21,11 +21,23 @@ EncoderRowBased* EncoderRowBased::CreateZlibEncoder() { VideoPacketFormat::ENCODING_ZLIB); } +EncoderRowBased* EncoderRowBased::CreateZlibEncoder(int packet_size) { + return new EncoderRowBased(new CompressorZlib(), + VideoPacketFormat::ENCODING_ZLIB, + packet_size); +} + EncoderRowBased* EncoderRowBased::CreateVerbatimEncoder() { return new EncoderRowBased(new CompressorVerbatim(), VideoPacketFormat::ENCODING_VERBATIM); } +EncoderRowBased* EncoderRowBased::CreateVerbatimEncoder(int packet_size) { + return new EncoderRowBased(new CompressorVerbatim(), + VideoPacketFormat::ENCODING_VERBATIM, + packet_size); +} + EncoderRowBased::EncoderRowBased(Compressor* compressor, VideoPacketFormat::Encoding encoding) : encoding_(encoding), diff --git a/remoting/base/encoder_row_based.h b/remoting/base/encoder_row_based.h index bdc992d..1dfd916 100644 --- a/remoting/base/encoder_row_based.h +++ b/remoting/base/encoder_row_based.h @@ -25,7 +25,9 @@ class UpdateStreamPacket; class EncoderRowBased : public Encoder { public: static EncoderRowBased* CreateZlibEncoder(); + static EncoderRowBased* CreateZlibEncoder(int packet_size); static EncoderRowBased* CreateVerbatimEncoder(); + static EncoderRowBased* CreateVerbatimEncoder(int packet_size); virtual ~EncoderRowBased(); diff --git a/remoting/base/encoder_row_based_unittest.cc b/remoting/base/encoder_row_based_unittest.cc index 8f54e82..735e806 100644 --- a/remoting/base/encoder_row_based_unittest.cc +++ b/remoting/base/encoder_row_based_unittest.cc @@ -3,20 +3,19 @@ // found in the LICENSE file. #include "remoting/base/codec_test.h" -#include "remoting/base/encoder_zlib.h" +#include "remoting/base/encoder_row_based.h" #include "testing/gtest/include/gtest/gtest.h" namespace remoting { TEST(EncoderZlibTest, TestEncoder) { - EncoderZlib encoder; - TestEncoder(&encoder, true); + scoped_ptr<EncoderRowBased> encoder(EncoderRowBased::CreateZlibEncoder()); + TestEncoder(encoder.get(), true); } - TEST(EncoderZlibTest, TestEncoderSmallOutputBuffer) { - EncoderZlib encoder(16); - TestEncoder(&encoder, true); + scoped_ptr<EncoderRowBased> encoder(EncoderRowBased::CreateZlibEncoder(16)); + TestEncoder(encoder.get(), true); } } // namespace remoting diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index e9a7789..d5e4b0f 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -448,15 +448,15 @@ '../testing/gmock/include', ], 'sources': [ -# BUG57351 'base/codec_test.cc', -# BUG57351 'base/codec_test.h', + 'base/codec_test.cc', + 'base/codec_test.h', 'base/compound_buffer_unittest.cc', 'base/compressor_zlib_unittest.cc', -# BUG57351 'base/decoder_vp8_unittest.cc', + 'base/decoder_vp8_unittest.cc', 'base/decompressor_zlib_unittest.cc', -# BUG57351 'base/encode_decode_unittest.cc', -# BUG57351 'base/encoder_vp8_unittest.cc', -# BUG57351 'base/encoder_row_based_unittest.cc', + 'base/encode_decode_unittest.cc', + 'base/encoder_vp8_unittest.cc', + 'base/encoder_row_based_unittest.cc', 'base/mock_objects.h', # BUG57351 'client/chromoting_view_unittest.cc', 'client/mock_objects.h', @@ -519,6 +519,12 @@ 'host/capturer_mac_unittest.cc', ], }], + ['target_arch=="arm"', { + 'sources!': [ + 'base/decoder_vp8_unittest.cc', + 'base/encoder_vp8_unittest.cc', + ], + }], ], # end of 'conditions' }, # end of target 'chromoting_unittests' ], # end of targets |