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

Side by Side Diff: talk/media/base/videoengine_unittest.h

Issue 1613433002: Remove SendStreamFormat and ViewRequests. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 10 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
« no previous file with comments | « talk/media/base/streamparams.h ('k') | talk/media/webrtc/webrtcvideoengine2.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 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 success = channel_->SetSendParameters(parameters); 226 success = channel_->SetSendParameters(parameters);
227 } 227 }
228 if (success) { 228 if (success) {
229 success = SetSend(sending); 229 success = SetSend(sending);
230 } 230 }
231 return success; 231 return success;
232 } 232 }
233 bool SetSend(bool send) { 233 bool SetSend(bool send) {
234 return channel_->SetSend(send); 234 return channel_->SetSend(send);
235 } 235 }
236 bool SetSendStreamFormat(uint32_t ssrc, const cricket::VideoCodec& codec) {
237 return channel_->SetSendStreamFormat(ssrc, cricket::VideoFormat(
238 codec.width, codec.height,
239 cricket::VideoFormat::FpsToInterval(codec.framerate),
240 cricket::FOURCC_ANY));
241 }
242 int DrainOutgoingPackets() { 236 int DrainOutgoingPackets() {
243 int packets = 0; 237 int packets = 0;
244 do { 238 do {
245 packets = NumRtpPackets(); 239 packets = NumRtpPackets();
246 // 100 ms should be long enough. 240 // 100 ms should be long enough.
247 rtc::Thread::Current()->ProcessMessages(100); 241 rtc::Thread::Current()->ProcessMessages(100);
248 } while (NumRtpPackets() > packets); 242 } while (NumRtpPackets() > packets);
249 return NumRtpPackets(); 243 return NumRtpPackets();
250 } 244 }
251 bool SendFrame() { 245 bool SendFrame() {
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 cricket::VideoSendParameters parameters; 644 cricket::VideoSendParameters parameters;
651 parameters.codecs.push_back(DefaultCodec()); 645 parameters.codecs.push_back(DefaultCodec());
652 parameters.max_bandwidth_bps = -1; // <= 0 means unlimited. 646 parameters.max_bandwidth_bps = -1; // <= 0 means unlimited.
653 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 647 EXPECT_TRUE(channel_->SetSendParameters(parameters));
654 parameters.max_bandwidth_bps = 128 * 1024; 648 parameters.max_bandwidth_bps = 128 * 1024;
655 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 649 EXPECT_TRUE(channel_->SetSendParameters(parameters));
656 } 650 }
657 // Test that we can set the SSRC for the default send source. 651 // Test that we can set the SSRC for the default send source.
658 void SetSendSsrc() { 652 void SetSendSsrc() {
659 EXPECT_TRUE(SetDefaultCodec()); 653 EXPECT_TRUE(SetDefaultCodec());
660 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec()));
661 EXPECT_TRUE(SetSend(true)); 654 EXPECT_TRUE(SetSend(true));
662 EXPECT_TRUE(SendFrame()); 655 EXPECT_TRUE(SendFrame());
663 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); 656 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout);
664 uint32_t ssrc = 0; 657 uint32_t ssrc = 0;
665 rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0)); 658 rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0));
666 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); 659 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
667 EXPECT_EQ(kSsrc, ssrc); 660 EXPECT_EQ(kSsrc, ssrc);
668 // Packets are being paced out, so these can mismatch between the first and 661 // Packets are being paced out, so these can mismatch between the first and
669 // second call to NumRtpPackets until pending packets are paced out. 662 // second call to NumRtpPackets until pending packets are paced out.
670 EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout); 663 EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout);
671 EXPECT_EQ_WAIT(NumRtpBytes(), NumRtpBytes(ssrc), kTimeout); 664 EXPECT_EQ_WAIT(NumRtpBytes(), NumRtpBytes(ssrc), kTimeout);
672 EXPECT_EQ(1, NumSentSsrcs()); 665 EXPECT_EQ(1, NumSentSsrcs());
673 EXPECT_EQ(0, NumRtpPackets(kSsrc - 1)); 666 EXPECT_EQ(0, NumRtpPackets(kSsrc - 1));
674 EXPECT_EQ(0, NumRtpBytes(kSsrc - 1)); 667 EXPECT_EQ(0, NumRtpBytes(kSsrc - 1));
675 } 668 }
676 // Test that we can set the SSRC even after codecs are set. 669 // Test that we can set the SSRC even after codecs are set.
677 void SetSendSsrcAfterSetCodecs() { 670 void SetSendSsrcAfterSetCodecs() {
678 // Remove stream added in Setup. 671 // Remove stream added in Setup.
679 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); 672 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
680 EXPECT_TRUE(SetDefaultCodec()); 673 EXPECT_TRUE(SetDefaultCodec());
681 EXPECT_TRUE(channel_->AddSendStream( 674 EXPECT_TRUE(channel_->AddSendStream(
682 cricket::StreamParams::CreateLegacy(999))); 675 cricket::StreamParams::CreateLegacy(999)));
683 EXPECT_TRUE(channel_->SetCapturer(999u, video_capturer_.get())); 676 EXPECT_TRUE(channel_->SetCapturer(999u, video_capturer_.get()));
684 EXPECT_TRUE(SetSendStreamFormat(999u, DefaultCodec()));
685 EXPECT_TRUE(SetSend(true)); 677 EXPECT_TRUE(SetSend(true));
686 EXPECT_TRUE(WaitAndSendFrame(0)); 678 EXPECT_TRUE(WaitAndSendFrame(0));
687 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); 679 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout);
688 uint32_t ssrc = 0; 680 uint32_t ssrc = 0;
689 rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0)); 681 rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0));
690 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); 682 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
691 EXPECT_EQ(999u, ssrc); 683 EXPECT_EQ(999u, ssrc);
692 // Packets are being paced out, so these can mismatch between the first and 684 // Packets are being paced out, so these can mismatch between the first and
693 // second call to NumRtpPackets until pending packets are paced out. 685 // second call to NumRtpPackets until pending packets are paced out.
694 EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout); 686 EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout);
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 EXPECT_EQ(0, renderer_.num_rendered_frames()); 1083 EXPECT_EQ(0, renderer_.num_rendered_frames());
1092 EXPECT_TRUE(SendFrame()); 1084 EXPECT_TRUE(SendFrame());
1093 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout); 1085 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
1094 1086
1095 // Check that we send smaller frames at the new resolution. 1087 // Check that we send smaller frames at the new resolution.
1096 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(33)); 1088 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(33));
1097 EXPECT_TRUE(video_capturer_->CaptureCustomFrame( 1089 EXPECT_TRUE(video_capturer_->CaptureCustomFrame(
1098 codec.width / 2, codec.height / 2, cricket::FOURCC_I420)); 1090 codec.width / 2, codec.height / 2, cricket::FOURCC_I420));
1099 EXPECT_FRAME_WAIT(2, codec.width / 2, codec.height / 2, kTimeout); 1091 EXPECT_FRAME_WAIT(2, codec.width / 2, codec.height / 2, kTimeout);
1100 } 1092 }
1101 // Tests that we can set the send stream format properly.
1102 void SetSendStreamFormat() {
1103 cricket::VideoCodec codec(DefaultCodec());
1104 SendAndReceive(codec);
1105 int frame_count = 1;
1106 EXPECT_FRAME_WAIT(frame_count, codec.width, codec.height, kTimeout);
1107
1108 // Adapt the resolution and frame rate to half.
1109 cricket::VideoFormat format(
1110 codec.width / 2,
1111 codec.height / 2,
1112 cricket::VideoFormat::FpsToInterval(codec.framerate / 2),
1113 cricket::FOURCC_I420);
1114 // The SSRC differs from the send SSRC.
1115 EXPECT_FALSE(channel_->SetSendStreamFormat(kSsrc - 1, format));
1116 EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc, format));
1117
1118 EXPECT_TRUE(WaitAndSendFrame(30)); // Should be dropped.
1119 EXPECT_TRUE(WaitAndSendFrame(30)); // Should be rendered.
1120 EXPECT_TRUE(WaitAndSendFrame(30)); // Should be dropped.
1121 frame_count += 1;
1122 EXPECT_FRAME_WAIT(frame_count, format.width, format.height, kTimeout);
1123
1124 // Adapt the resolution to 0x0, which should drop all frames.
1125 format.width = 0;
1126 format.height = 0;
1127 EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc, format));
1128 EXPECT_TRUE(SendFrame());
1129 EXPECT_TRUE(SendFrame());
1130 rtc::Thread::Current()->ProcessMessages(500);
1131 EXPECT_EQ(frame_count, renderer_.num_rendered_frames());
1132 }
1133 // Test that setting send stream format to 0x0 resolution will result in
1134 // frames being dropped.
1135 void SetSendStreamFormat0x0() {
1136 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
1137 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec()));
1138 EXPECT_TRUE(SetSend(true));
1139 EXPECT_TRUE(channel_->SetRenderer(kDefaultReceiveSsrc, &renderer_));
1140 EXPECT_EQ(0, renderer_.num_rendered_frames());
1141 // This frame should be received.
1142 EXPECT_TRUE(SendFrame());
1143 EXPECT_FRAME_WAIT(1, DefaultCodec().width, DefaultCodec().height, kTimeout);
1144 const int64_t interval =
1145 cricket::VideoFormat::FpsToInterval(DefaultCodec().framerate);
1146 cricket::VideoFormat format(
1147 0,
1148 0,
1149 interval,
1150 cricket::FOURCC_I420);
1151 EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc, format));
1152 // This frame should not be received.
1153 EXPECT_TRUE(WaitAndSendFrame(
1154 static_cast<int>(interval/rtc::kNumNanosecsPerMillisec)));
1155 rtc::Thread::Current()->ProcessMessages(500);
1156 EXPECT_EQ(1, renderer_.num_rendered_frames());
1157 }
1158 1093
1159 // Tests that we can mute and unmute the channel properly. 1094 // Tests that we can mute and unmute the channel properly.
1160 void MuteStream() { 1095 void MuteStream() {
1161 EXPECT_TRUE(SetDefaultCodec()); 1096 EXPECT_TRUE(SetDefaultCodec());
1162 cricket::FakeVideoCapturer video_capturer; 1097 cricket::FakeVideoCapturer video_capturer;
1163 video_capturer.Start( 1098 video_capturer.Start(
1164 cricket::VideoFormat( 1099 cricket::VideoFormat(
1165 640, 480, 1100 640, 480,
1166 cricket::VideoFormat::FpsToInterval(30), 1101 cricket::VideoFormat::FpsToInterval(30),
1167 cricket::FOURCC_I420)); 1102 cricket::FOURCC_I420));
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 rtc::scoped_ptr<C> channel_; 1214 rtc::scoped_ptr<C> channel_;
1280 cricket::FakeNetworkInterface network_interface_; 1215 cricket::FakeNetworkInterface network_interface_;
1281 cricket::FakeVideoRenderer renderer_; 1216 cricket::FakeVideoRenderer renderer_;
1282 cricket::VideoMediaChannel::Error media_error_; 1217 cricket::VideoMediaChannel::Error media_error_;
1283 1218
1284 // Used by test cases where 2 streams are run on the same channel. 1219 // Used by test cases where 2 streams are run on the same channel.
1285 cricket::FakeVideoRenderer renderer2_; 1220 cricket::FakeVideoRenderer renderer2_;
1286 }; 1221 };
1287 1222
1288 #endif // TALK_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT 1223 #endif // TALK_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT
OLDNEW
« no previous file with comments | « talk/media/base/streamparams.h ('k') | talk/media/webrtc/webrtcvideoengine2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698