Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1001)

Side by Side Diff: remoting/protocol/rtp_video_writer_unittest.cc

Issue 9827006: Refactor VideoStub interface to accept ownership of video packets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/rtp_video_writer.cc ('k') | remoting/protocol/video_stub.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/bind.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 void InitData(int size) { 76 void InitData(int size) {
77 data_.resize(size); 77 data_.resize(size);
78 for (int i = 0; i < size; ++i) { 78 for (int i = 0; i < size; ++i) {
79 data_[i] = static_cast<char>(i); 79 data_[i] = static_cast<char>(i);
80 } 80 }
81 } 81 }
82 82
83 void InitPacket(int size, bool first, bool last) { 83 void InitPacket(int size, bool first, bool last) {
84 InitData(size); 84 InitData(size);
85 85
86 packet_ = new VideoPacket(); 86 packet_.reset(new VideoPacket());
87 packet_->mutable_format()->set_encoding(VideoPacketFormat::ENCODING_VP8); 87 packet_->mutable_format()->set_encoding(VideoPacketFormat::ENCODING_VP8);
88 if (first) 88 if (first)
89 packet_->set_flags(packet_->flags() | VideoPacket::FIRST_PACKET); 89 packet_->set_flags(packet_->flags() | VideoPacket::FIRST_PACKET);
90 if (last) 90 if (last)
91 packet_->set_flags(packet_->flags() | VideoPacket::LAST_PACKET); 91 packet_->set_flags(packet_->flags() | VideoPacket::LAST_PACKET);
92 packet_->mutable_data()->assign(data_.begin(), data_.end()); 92 packet_->mutable_data()->assign(data_.begin(), data_.end());
93 } 93 }
94 94
95 bool CompareData(const CompoundBuffer& buffer, char* data, int size) { 95 bool CompareData(const CompoundBuffer& buffer, char* data, int size) {
96 scoped_refptr<IOBuffer> buffer_data = buffer.ToIOBufferWithSize(); 96 scoped_refptr<IOBuffer> buffer_data = buffer.ToIOBufferWithSize();
(...skipping 22 matching lines...) Expand all
119 } 119 }
120 EXPECT_EQ(pos, static_cast<int>(data_.size())); 120 EXPECT_EQ(pos, static_cast<int>(data_.size()));
121 } 121 }
122 122
123 MessageLoop message_loop_; 123 MessageLoop message_loop_;
124 124
125 scoped_ptr<FakeSession> session_; 125 scoped_ptr<FakeSession> session_;
126 RtpVideoWriter writer_; 126 RtpVideoWriter writer_;
127 127
128 vector<char> data_; 128 vector<char> data_;
129 VideoPacket* packet_; 129 scoped_ptr<VideoPacket> packet_;
130 }; 130 };
131 131
132 TEST_F(RtpVideoWriterTest, NotFragmented_FirstPacket) { 132 TEST_F(RtpVideoWriterTest, NotFragmented_FirstPacket) {
133 InitPacket(1024, true, false); 133 InitPacket(1024, true, false);
134 writer_.ProcessVideoPacket( 134 writer_.ProcessVideoPacket(packet_.Pass(), base::Closure());
135 packet_, base::Bind(&base::DeletePointer<VideoPacket>, packet_));
136 message_loop_.RunAllPending(); 135 message_loop_.RunAllPending();
137 136
138 ExpectedPacket expected[] = { 137 ExpectedPacket expected[] = {
139 { true, Vp8Descriptor::NOT_FRAGMENTED, false } 138 { true, Vp8Descriptor::NOT_FRAGMENTED, false }
140 }; 139 };
141 VerifyResult(expected, arraysize(expected)); 140 VerifyResult(expected, arraysize(expected));
142 } 141 }
143 142
144 TEST_F(RtpVideoWriterTest, NotFragmented_LastPackes) { 143 TEST_F(RtpVideoWriterTest, NotFragmented_LastPackes) {
145 InitPacket(1024, false, true); 144 InitPacket(1024, false, true);
146 writer_.ProcessVideoPacket( 145 writer_.ProcessVideoPacket(packet_.Pass(), base::Closure());
147 packet_, base::Bind(&base::DeletePointer<VideoPacket>, packet_));
148 message_loop_.RunAllPending(); 146 message_loop_.RunAllPending();
149 147
150 ExpectedPacket expected[] = { 148 ExpectedPacket expected[] = {
151 { false, Vp8Descriptor::NOT_FRAGMENTED, true } 149 { false, Vp8Descriptor::NOT_FRAGMENTED, true }
152 }; 150 };
153 VerifyResult(expected, arraysize(expected)); 151 VerifyResult(expected, arraysize(expected));
154 } 152 }
155 153
156 TEST_F(RtpVideoWriterTest, TwoFragments_FirstPacket) { 154 TEST_F(RtpVideoWriterTest, TwoFragments_FirstPacket) {
157 InitPacket(2000, true, false); 155 InitPacket(2000, true, false);
158 writer_.ProcessVideoPacket( 156 writer_.ProcessVideoPacket(packet_.Pass(), base::Closure());
159 packet_, base::Bind(&base::DeletePointer<VideoPacket>, packet_));
160 message_loop_.RunAllPending(); 157 message_loop_.RunAllPending();
161 158
162 ExpectedPacket expected[] = { 159 ExpectedPacket expected[] = {
163 { true, Vp8Descriptor::FIRST_FRAGMENT, false }, 160 { true, Vp8Descriptor::FIRST_FRAGMENT, false },
164 { false, Vp8Descriptor::LAST_FRAGMENT, false }, 161 { false, Vp8Descriptor::LAST_FRAGMENT, false },
165 }; 162 };
166 VerifyResult(expected, arraysize(expected)); 163 VerifyResult(expected, arraysize(expected));
167 } 164 }
168 165
169 TEST_F(RtpVideoWriterTest, TwoFragments_LastPacket) { 166 TEST_F(RtpVideoWriterTest, TwoFragments_LastPacket) {
170 InitPacket(2000, false, true); 167 InitPacket(2000, false, true);
171 writer_.ProcessVideoPacket( 168 writer_.ProcessVideoPacket(packet_.Pass(), base::Closure());
172 packet_, base::Bind(&base::DeletePointer<VideoPacket>, packet_));
173 message_loop_.RunAllPending(); 169 message_loop_.RunAllPending();
174 170
175 ExpectedPacket expected[] = { 171 ExpectedPacket expected[] = {
176 { false, Vp8Descriptor::FIRST_FRAGMENT, false }, 172 { false, Vp8Descriptor::FIRST_FRAGMENT, false },
177 { false, Vp8Descriptor::LAST_FRAGMENT, true }, 173 { false, Vp8Descriptor::LAST_FRAGMENT, true },
178 }; 174 };
179 VerifyResult(expected, arraysize(expected)); 175 VerifyResult(expected, arraysize(expected));
180 } 176 }
181 177
182 TEST_F(RtpVideoWriterTest, ThreeFragments) { 178 TEST_F(RtpVideoWriterTest, ThreeFragments) {
183 InitPacket(3000, true, true); 179 InitPacket(3000, true, true);
184 writer_.ProcessVideoPacket( 180 writer_.ProcessVideoPacket(packet_.Pass(), base::Closure());
185 packet_, base::Bind(&base::DeletePointer<VideoPacket>, packet_));
186 message_loop_.RunAllPending(); 181 message_loop_.RunAllPending();
187 182
188 ExpectedPacket expected[] = { 183 ExpectedPacket expected[] = {
189 { true, Vp8Descriptor::FIRST_FRAGMENT, false }, 184 { true, Vp8Descriptor::FIRST_FRAGMENT, false },
190 { false, Vp8Descriptor::MIDDLE_FRAGMENT, false }, 185 { false, Vp8Descriptor::MIDDLE_FRAGMENT, false },
191 { false, Vp8Descriptor::LAST_FRAGMENT, true }, 186 { false, Vp8Descriptor::LAST_FRAGMENT, true },
192 }; 187 };
193 VerifyResult(expected, arraysize(expected)); 188 VerifyResult(expected, arraysize(expected));
194 } 189 }
195 190
196 } // namespace protocol 191 } // namespace protocol
197 } // namespace remoting 192 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/rtp_video_writer.cc ('k') | remoting/protocol/video_stub.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698