| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 9 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 11 #include "remoting/base/constants.h" |
| 10 #include "remoting/proto/video.pb.h" | 12 #include "remoting/proto/video.pb.h" |
| 11 #include "remoting/protocol/fake_session.h" | 13 #include "remoting/protocol/fake_session.h" |
| 12 #include "remoting/protocol/rtp_reader.h" | 14 #include "remoting/protocol/rtp_reader.h" |
| 13 #include "remoting/protocol/rtp_utils.h" | 15 #include "remoting/protocol/rtp_utils.h" |
| 14 #include "remoting/protocol/rtp_video_writer.h" | 16 #include "remoting/protocol/rtp_video_writer.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 18 |
| 17 using net::IOBuffer; | 19 using net::IOBuffer; |
| 18 using std::string; | 20 using std::string; |
| 19 using std::vector; | 21 using std::vector; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 50 class RtpVideoWriterTest : public testing::Test { | 52 class RtpVideoWriterTest : public testing::Test { |
| 51 protected: | 53 protected: |
| 52 struct ExpectedPacket { | 54 struct ExpectedPacket { |
| 53 bool first; | 55 bool first; |
| 54 Vp8Descriptor::FragmentationInfo fragmentation_info; | 56 Vp8Descriptor::FragmentationInfo fragmentation_info; |
| 55 bool last; | 57 bool last; |
| 56 }; | 58 }; |
| 57 | 59 |
| 58 virtual void SetUp() { | 60 virtual void SetUp() { |
| 59 session_.reset(new FakeSession()); | 61 session_.reset(new FakeSession()); |
| 60 writer_.Init(session_.get()); | 62 writer_.Init(session_.get(), |
| 63 base::Bind(&RtpVideoWriterTest::OnWriterInitialized, |
| 64 base::Unretained(this))); |
| 65 } |
| 66 |
| 67 void OnWriterInitialized(bool success) { |
| 68 ASSERT_TRUE(success); |
| 61 } | 69 } |
| 62 | 70 |
| 63 void InitData(int size) { | 71 void InitData(int size) { |
| 64 data_.resize(size); | 72 data_.resize(size); |
| 65 for (int i = 0; i < size; ++i) { | 73 for (int i = 0; i < size; ++i) { |
| 66 data_[i] = static_cast<char>(i); | 74 data_[i] = static_cast<char>(i); |
| 67 } | 75 } |
| 68 } | 76 } |
| 69 | 77 |
| 70 void InitPacket(int size, bool first, bool last) { | 78 void InitPacket(int size, bool first, bool last) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 81 | 89 |
| 82 bool CompareData(const CompoundBuffer& buffer, char* data, int size) { | 90 bool CompareData(const CompoundBuffer& buffer, char* data, int size) { |
| 83 scoped_refptr<IOBuffer> buffer_data = buffer.ToIOBufferWithSize(); | 91 scoped_refptr<IOBuffer> buffer_data = buffer.ToIOBufferWithSize(); |
| 84 return buffer.total_bytes() == size && | 92 return buffer.total_bytes() == size && |
| 85 memcmp(buffer_data->data(), data, size) == 0; | 93 memcmp(buffer_data->data(), data, size) == 0; |
| 86 } | 94 } |
| 87 | 95 |
| 88 void VerifyResult(const ExpectedPacket expected[], | 96 void VerifyResult(const ExpectedPacket expected[], |
| 89 int count) { | 97 int count) { |
| 90 const vector<string>& rtp_packets = | 98 const vector<string>& rtp_packets = |
| 91 session_->video_rtp_channel()->written_packets(); | 99 session_->GetDatagramChannel(kVideoRtpChannelName)->written_packets(); |
| 92 ASSERT_EQ(count, static_cast<int>(rtp_packets.size())); | 100 ASSERT_EQ(count, static_cast<int>(rtp_packets.size())); |
| 93 int pos = 0; | 101 int pos = 0; |
| 94 for (int i = 0; i < count; ++i) { | 102 for (int i = 0; i < count; ++i) { |
| 95 SCOPED_TRACE("Packet " + base::IntToString(i)); | 103 SCOPED_TRACE("Packet " + base::IntToString(i)); |
| 96 | 104 |
| 97 RtpPacket packet; | 105 RtpPacket packet; |
| 98 ASSERT_TRUE(ParsePacket(rtp_packets[i], &packet)); | 106 ASSERT_TRUE(ParsePacket(rtp_packets[i], &packet)); |
| 99 EXPECT_EQ(expected[i].first, packet.vp8_descriptor().frame_beginning); | 107 EXPECT_EQ(expected[i].first, packet.vp8_descriptor().frame_beginning); |
| 100 EXPECT_EQ(expected[i].last, packet.header().marker); | 108 EXPECT_EQ(expected[i].last, packet.header().marker); |
| 101 EXPECT_EQ(expected[i].fragmentation_info, | 109 EXPECT_EQ(expected[i].fragmentation_info, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 ExpectedPacket expected[] = { | 178 ExpectedPacket expected[] = { |
| 171 { true, Vp8Descriptor::FIRST_FRAGMENT, false }, | 179 { true, Vp8Descriptor::FIRST_FRAGMENT, false }, |
| 172 { false, Vp8Descriptor::MIDDLE_FRAGMENT, false }, | 180 { false, Vp8Descriptor::MIDDLE_FRAGMENT, false }, |
| 173 { false, Vp8Descriptor::LAST_FRAGMENT, true }, | 181 { false, Vp8Descriptor::LAST_FRAGMENT, true }, |
| 174 }; | 182 }; |
| 175 VerifyResult(expected, arraysize(expected)); | 183 VerifyResult(expected, arraysize(expected)); |
| 176 } | 184 } |
| 177 | 185 |
| 178 } // namespace protocol | 186 } // namespace protocol |
| 179 } // namespace remoting | 187 } // namespace remoting |
| OLD | NEW |