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

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

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: google::int32 Created 5 years, 3 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
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #define EXPECT_FRAME_ON_RENDERER_WAIT(r, c, w, h, t) \ 51 #define EXPECT_FRAME_ON_RENDERER_WAIT(r, c, w, h, t) \
52 EXPECT_EQ_WAIT((c), (r).num_rendered_frames(), (t)); \ 52 EXPECT_EQ_WAIT((c), (r).num_rendered_frames(), (t)); \
53 EXPECT_EQ((w), (r).width()); \ 53 EXPECT_EQ((w), (r).width()); \
54 EXPECT_EQ((h), (r).height()); \ 54 EXPECT_EQ((h), (r).height()); \
55 EXPECT_EQ(0, (r).errors()); \ 55 EXPECT_EQ(0, (r).errors()); \
56 56
57 #define EXPECT_GT_FRAME_ON_RENDERER_WAIT(r, c, w, h, t) \ 57 #define EXPECT_GT_FRAME_ON_RENDERER_WAIT(r, c, w, h, t) \
58 EXPECT_TRUE_WAIT((r).num_rendered_frames() >= (c) && \ 58 EXPECT_TRUE_WAIT((r).num_rendered_frames() >= (c) && \
59 (w) == (r).width() && \ 59 (w) == (r).width() && \
60 (h) == (r).height(), (t)); \ 60 (h) == (r).height(), (t)); \
61 EXPECT_EQ(0, (r).errors()); \ 61 EXPECT_EQ(0, (r).errors());
62 62
63 static const uint32 kTimeout = 5000U; 63 static const uint32_t kTimeout = 5000U;
64 static const uint32 kDefaultReceiveSsrc = 0; 64 static const uint32_t kDefaultReceiveSsrc = 0;
65 static const uint32 kSsrc = 1234u; 65 static const uint32_t kSsrc = 1234u;
66 static const uint32 kRtxSsrc = 4321u; 66 static const uint32_t kRtxSsrc = 4321u;
67 static const uint32 kSsrcs4[] = {1, 2, 3, 4}; 67 static const uint32_t kSsrcs4[] = {1, 2, 3, 4};
68 68
69 inline bool IsEqualRes(const cricket::VideoCodec& a, int w, int h, int fps) { 69 inline bool IsEqualRes(const cricket::VideoCodec& a, int w, int h, int fps) {
70 return a.width == w && a.height == h && a.framerate == fps; 70 return a.width == w && a.height == h && a.framerate == fps;
71 } 71 }
72 72
73 inline bool IsEqualCodec(const cricket::VideoCodec& a, 73 inline bool IsEqualCodec(const cricket::VideoCodec& a,
74 const cricket::VideoCodec& b) { 74 const cricket::VideoCodec& b) {
75 return a.id == b.id && a.name == b.name && 75 return a.id == b.id && a.name == b.name &&
76 IsEqualRes(a, b.width, b.height, b.framerate); 76 IsEqualRes(a, b.width, b.height, b.framerate);
77 } 77 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 video_capturer->SignalVideoFrame.disconnect(this); 112 video_capturer->SignalVideoFrame.disconnect(this);
113 } 113 }
114 } 114 }
115 void OnLocalFrame(cricket::VideoCapturer*, 115 void OnLocalFrame(cricket::VideoCapturer*,
116 const cricket::VideoFrame*) { 116 const cricket::VideoFrame*) {
117 } 117 }
118 void OnLocalFrameFormat(cricket::VideoCapturer*, 118 void OnLocalFrameFormat(cricket::VideoCapturer*,
119 const cricket::VideoFormat*) { 119 const cricket::VideoFormat*) {
120 } 120 }
121 121
122 void TriggerMediaFrame( 122 void TriggerMediaFrame(uint32_t ssrc,
123 uint32 ssrc, cricket::VideoFrame* frame, bool* drop_frame) { 123 cricket::VideoFrame* frame,
124 bool* drop_frame) {
124 T::SignalMediaFrame(ssrc, frame, drop_frame); 125 T::SignalMediaFrame(ssrc, frame, drop_frame);
125 } 126 }
126 }; 127 };
127 128
128 template<class E> 129 template<class E>
129 class VideoEngineTest : public testing::Test { 130 class VideoEngineTest : public testing::Test {
130 protected: 131 protected:
131 // Tests starting and stopping the engine, and creating a channel. 132 // Tests starting and stopping the engine, and creating a channel.
132 void StartupShutdown() { 133 void StartupShutdown() {
133 EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); 134 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 success = channel_->SetSendParameters(parameters); 552 success = channel_->SetSendParameters(parameters);
552 } 553 }
553 if (success) { 554 if (success) {
554 success = SetSend(sending); 555 success = SetSend(sending);
555 } 556 }
556 return success; 557 return success;
557 } 558 }
558 bool SetSend(bool send) { 559 bool SetSend(bool send) {
559 return channel_->SetSend(send); 560 return channel_->SetSend(send);
560 } 561 }
561 bool SetSendStreamFormat(uint32 ssrc, const cricket::VideoCodec& codec) { 562 bool SetSendStreamFormat(uint32_t ssrc, const cricket::VideoCodec& codec) {
562 return channel_->SetSendStreamFormat(ssrc, cricket::VideoFormat( 563 return channel_->SetSendStreamFormat(ssrc, cricket::VideoFormat(
563 codec.width, codec.height, 564 codec.width, codec.height,
564 cricket::VideoFormat::FpsToInterval(codec.framerate), 565 cricket::VideoFormat::FpsToInterval(codec.framerate),
565 cricket::FOURCC_ANY)); 566 cricket::FOURCC_ANY));
566 } 567 }
567 int DrainOutgoingPackets() { 568 int DrainOutgoingPackets() {
568 int packets = 0; 569 int packets = 0;
569 do { 570 do {
570 packets = NumRtpPackets(); 571 packets = NumRtpPackets();
571 // 100 ms should be long enough. 572 // 100 ms should be long enough.
(...skipping 30 matching lines...) Expand all
602 return 0; 603 return 0;
603 #endif 604 #endif
604 } 605 }
605 bool SendCustomVideoFrame(int w, int h) { 606 bool SendCustomVideoFrame(int w, int h) {
606 if (!video_capturer_.get()) return false; 607 if (!video_capturer_.get()) return false;
607 return video_capturer_->CaptureCustomFrame(w, h, cricket::FOURCC_I420); 608 return video_capturer_->CaptureCustomFrame(w, h, cricket::FOURCC_I420);
608 } 609 }
609 int NumRtpBytes() { 610 int NumRtpBytes() {
610 return network_interface_.NumRtpBytes(); 611 return network_interface_.NumRtpBytes();
611 } 612 }
612 int NumRtpBytes(uint32 ssrc) { 613 int NumRtpBytes(uint32_t ssrc) {
613 return network_interface_.NumRtpBytes(ssrc); 614 return network_interface_.NumRtpBytes(ssrc);
614 } 615 }
615 int NumRtpPackets() { 616 int NumRtpPackets() {
616 return network_interface_.NumRtpPackets(); 617 return network_interface_.NumRtpPackets();
617 } 618 }
618 int NumRtpPackets(uint32 ssrc) { 619 int NumRtpPackets(uint32_t ssrc) {
619 return network_interface_.NumRtpPackets(ssrc); 620 return network_interface_.NumRtpPackets(ssrc);
620 } 621 }
621 int NumSentSsrcs() { 622 int NumSentSsrcs() {
622 return network_interface_.NumSentSsrcs(); 623 return network_interface_.NumSentSsrcs();
623 } 624 }
624 const rtc::Buffer* GetRtpPacket(int index) { 625 const rtc::Buffer* GetRtpPacket(int index) {
625 return network_interface_.GetRtpPacket(index); 626 return network_interface_.GetRtpPacket(index);
626 } 627 }
627 int NumRtcpPackets() { 628 int NumRtcpPackets() {
628 return network_interface_.NumRtcpPackets(); 629 return network_interface_.NumRtcpPackets();
629 } 630 }
630 const rtc::Buffer* GetRtcpPacket(int index) { 631 const rtc::Buffer* GetRtcpPacket(int index) {
631 return network_interface_.GetRtcpPacket(index); 632 return network_interface_.GetRtcpPacket(index);
632 } 633 }
633 static int GetPayloadType(const rtc::Buffer* p) { 634 static int GetPayloadType(const rtc::Buffer* p) {
634 int pt = -1; 635 int pt = -1;
635 ParseRtpPacket(p, NULL, &pt, NULL, NULL, NULL, NULL); 636 ParseRtpPacket(p, NULL, &pt, NULL, NULL, NULL, NULL);
636 return pt; 637 return pt;
637 } 638 }
638 static bool ParseRtpPacket(const rtc::Buffer* p, bool* x, int* pt, 639 static bool ParseRtpPacket(const rtc::Buffer* p,
639 int* seqnum, uint32* tstamp, uint32* ssrc, 640 bool* x,
641 int* pt,
642 int* seqnum,
643 uint32_t* tstamp,
644 uint32_t* ssrc,
640 std::string* payload) { 645 std::string* payload) {
641 rtc::ByteBuffer buf(*p); 646 rtc::ByteBuffer buf(*p);
642 uint8 u08 = 0; 647 uint8_t u08 = 0;
643 uint16 u16 = 0; 648 uint16_t u16 = 0;
644 uint32 u32 = 0; 649 uint32_t u32 = 0;
645 650
646 // Read X and CC fields. 651 // Read X and CC fields.
647 if (!buf.ReadUInt8(&u08)) return false; 652 if (!buf.ReadUInt8(&u08)) return false;
648 bool extension = ((u08 & 0x10) != 0); 653 bool extension = ((u08 & 0x10) != 0);
649 uint8 cc = (u08 & 0x0F); 654 uint8_t cc = (u08 & 0x0F);
650 if (x) *x = extension; 655 if (x) *x = extension;
651 656
652 // Read PT field. 657 // Read PT field.
653 if (!buf.ReadUInt8(&u08)) return false; 658 if (!buf.ReadUInt8(&u08)) return false;
654 if (pt) *pt = (u08 & 0x7F); 659 if (pt) *pt = (u08 & 0x7F);
655 660
656 // Read Sequence Number field. 661 // Read Sequence Number field.
657 if (!buf.ReadUInt16(&u16)) return false; 662 if (!buf.ReadUInt16(&u16)) return false;
658 if (seqnum) *seqnum = u16; 663 if (seqnum) *seqnum = u16;
659 664
660 // Read Timestamp field. 665 // Read Timestamp field.
661 if (!buf.ReadUInt32(&u32)) return false; 666 if (!buf.ReadUInt32(&u32)) return false;
662 if (tstamp) *tstamp = u32; 667 if (tstamp) *tstamp = u32;
663 668
664 // Read SSRC field. 669 // Read SSRC field.
665 if (!buf.ReadUInt32(&u32)) return false; 670 if (!buf.ReadUInt32(&u32)) return false;
666 if (ssrc) *ssrc = u32; 671 if (ssrc) *ssrc = u32;
667 672
668 // Skip CSRCs. 673 // Skip CSRCs.
669 for (uint8 i = 0; i < cc; ++i) { 674 for (uint8_t i = 0; i < cc; ++i) {
670 if (!buf.ReadUInt32(&u32)) return false; 675 if (!buf.ReadUInt32(&u32)) return false;
671 } 676 }
672 677
673 // Skip extension header. 678 // Skip extension header.
674 if (extension) { 679 if (extension) {
675 // Read Profile-specific extension header ID 680 // Read Profile-specific extension header ID
676 if (!buf.ReadUInt16(&u16)) return false; 681 if (!buf.ReadUInt16(&u16)) return false;
677 682
678 // Read Extension header length 683 // Read Extension header length
679 if (!buf.ReadUInt16(&u16)) return false; 684 if (!buf.ReadUInt16(&u16)) return false;
680 uint16 ext_header_len = u16; 685 uint16_t ext_header_len = u16;
681 686
682 // Read Extension header 687 // Read Extension header
683 for (uint16 i = 0; i < ext_header_len; ++i) { 688 for (uint16_t i = 0; i < ext_header_len; ++i) {
684 if (!buf.ReadUInt32(&u32)) return false; 689 if (!buf.ReadUInt32(&u32)) return false;
685 } 690 }
686 } 691 }
687 692
688 if (payload) { 693 if (payload) {
689 return buf.ReadString(payload, buf.Length()); 694 return buf.ReadString(payload, buf.Length());
690 } 695 }
691 return true; 696 return true;
692 } 697 }
693 698
694 // Parse all RTCP packet, from start_index to stop_index, and count how many 699 // Parse all RTCP packet, from start_index to stop_index, and count how many
695 // FIR (PT=206 and FMT=4 according to RFC 5104). If successful, set the count 700 // FIR (PT=206 and FMT=4 according to RFC 5104). If successful, set the count
696 // and return true. 701 // and return true.
697 bool CountRtcpFir(int start_index, int stop_index, int* fir_count) { 702 bool CountRtcpFir(int start_index, int stop_index, int* fir_count) {
698 int count = 0; 703 int count = 0;
699 for (int i = start_index; i < stop_index; ++i) { 704 for (int i = start_index; i < stop_index; ++i) {
700 rtc::scoped_ptr<const rtc::Buffer> p(GetRtcpPacket(i)); 705 rtc::scoped_ptr<const rtc::Buffer> p(GetRtcpPacket(i));
701 rtc::ByteBuffer buf(*p); 706 rtc::ByteBuffer buf(*p);
702 size_t total_len = 0; 707 size_t total_len = 0;
703 // The packet may be a compound RTCP packet. 708 // The packet may be a compound RTCP packet.
704 while (total_len < p->size()) { 709 while (total_len < p->size()) {
705 // Read FMT, type and length. 710 // Read FMT, type and length.
706 uint8 fmt = 0; 711 uint8_t fmt = 0;
707 uint8 type = 0; 712 uint8_t type = 0;
708 uint16 length = 0; 713 uint16_t length = 0;
709 if (!buf.ReadUInt8(&fmt)) return false; 714 if (!buf.ReadUInt8(&fmt)) return false;
710 fmt &= 0x1F; 715 fmt &= 0x1F;
711 if (!buf.ReadUInt8(&type)) return false; 716 if (!buf.ReadUInt8(&type)) return false;
712 if (!buf.ReadUInt16(&length)) return false; 717 if (!buf.ReadUInt16(&length)) return false;
713 buf.Consume(length * 4); // Skip RTCP data. 718 buf.Consume(length * 4); // Skip RTCP data.
714 total_len += (length + 1) * 4; 719 total_len += (length + 1) * 4;
715 if ((192 == type) || ((206 == type) && (4 == fmt))) { 720 if ((192 == type) || ((206 == type) && (4 == fmt))) {
716 ++count; 721 ++count;
717 } 722 }
718 } 723 }
719 } 724 }
720 725
721 if (fir_count) { 726 if (fir_count) {
722 *fir_count = count; 727 *fir_count = count;
723 } 728 }
724 return true; 729 return true;
725 } 730 }
726 731
727 void OnVideoChannelError(uint32 ssrc, 732 void OnVideoChannelError(uint32_t ssrc,
728 cricket::VideoMediaChannel::Error error) { 733 cricket::VideoMediaChannel::Error error) {
729 media_error_ = error; 734 media_error_ = error;
730 } 735 }
731 736
732 // Test that SetSend works. 737 // Test that SetSend works.
733 void SetSend() { 738 void SetSend() {
734 EXPECT_FALSE(channel_->sending()); 739 EXPECT_FALSE(channel_->sending());
735 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get())); 740 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get()));
736 EXPECT_TRUE(SetOneCodec(DefaultCodec())); 741 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
737 EXPECT_FALSE(channel_->sending()); 742 EXPECT_FALSE(channel_->sending());
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 EXPECT_TRUE(SetSend(true)); 888 EXPECT_TRUE(SetSend(true));
884 EXPECT_TRUE(channel_->AddRecvStream( 889 EXPECT_TRUE(channel_->AddRecvStream(
885 cricket::StreamParams::CreateLegacy(1))); 890 cricket::StreamParams::CreateLegacy(1)));
886 EXPECT_TRUE(channel_->AddRecvStream( 891 EXPECT_TRUE(channel_->AddRecvStream(
887 cricket::StreamParams::CreateLegacy(2))); 892 cricket::StreamParams::CreateLegacy(2)));
888 EXPECT_TRUE(channel_->SetRenderer(1, &renderer1)); 893 EXPECT_TRUE(channel_->SetRenderer(1, &renderer1));
889 EXPECT_TRUE(channel_->SetRenderer(2, &renderer2)); 894 EXPECT_TRUE(channel_->SetRenderer(2, &renderer2));
890 EXPECT_TRUE(channel_->SetRender(true)); 895 EXPECT_TRUE(channel_->SetRender(true));
891 EXPECT_EQ(0, renderer1.num_rendered_frames()); 896 EXPECT_EQ(0, renderer1.num_rendered_frames());
892 EXPECT_EQ(0, renderer2.num_rendered_frames()); 897 EXPECT_EQ(0, renderer2.num_rendered_frames());
893 std::vector<uint32> ssrcs; 898 std::vector<uint32_t> ssrcs;
894 ssrcs.push_back(1); 899 ssrcs.push_back(1);
895 ssrcs.push_back(2); 900 ssrcs.push_back(2);
896 network_interface_.SetConferenceMode(true, ssrcs); 901 network_interface_.SetConferenceMode(true, ssrcs);
897 EXPECT_TRUE(SendFrame()); 902 EXPECT_TRUE(SendFrame());
898 EXPECT_FRAME_ON_RENDERER_WAIT( 903 EXPECT_FRAME_ON_RENDERER_WAIT(
899 renderer1, 1, DefaultCodec().width, DefaultCodec().height, kTimeout); 904 renderer1, 1, DefaultCodec().width, DefaultCodec().height, kTimeout);
900 EXPECT_FRAME_ON_RENDERER_WAIT( 905 EXPECT_FRAME_ON_RENDERER_WAIT(
901 renderer2, 1, DefaultCodec().width, DefaultCodec().height, kTimeout); 906 renderer2, 1, DefaultCodec().width, DefaultCodec().height, kTimeout);
902 907
903 EXPECT_TRUE(channel_->SetSend(false)); 908 EXPECT_TRUE(channel_->SetSend(false));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 EXPECT_TRUE(channel_->SetRenderer(5678, &renderer2)); 966 EXPECT_TRUE(channel_->SetRenderer(5678, &renderer2));
962 EXPECT_TRUE(capturer->CaptureCustomFrame( 967 EXPECT_TRUE(capturer->CaptureCustomFrame(
963 kTestWidth, kTestHeight, cricket::FOURCC_I420)); 968 kTestWidth, kTestHeight, cricket::FOURCC_I420));
964 EXPECT_FRAME_ON_RENDERER_WAIT( 969 EXPECT_FRAME_ON_RENDERER_WAIT(
965 renderer2, 1, kTestWidth, kTestHeight, kTimeout); 970 renderer2, 1, kTestWidth, kTestHeight, kTimeout);
966 971
967 // Get stats, and make sure they are correct for two senders. We wait until 972 // Get stats, and make sure they are correct for two senders. We wait until
968 // the number of expected packets have been sent to avoid races where we 973 // the number of expected packets have been sent to avoid races where we
969 // check stats before it has been updated. 974 // check stats before it has been updated.
970 cricket::VideoMediaInfo info; 975 cricket::VideoMediaInfo info;
971 for (uint32 i = 0; i < kTimeout; ++i) { 976 for (uint32_t i = 0; i < kTimeout; ++i) {
972 rtc::Thread::Current()->ProcessMessages(1); 977 rtc::Thread::Current()->ProcessMessages(1);
973 EXPECT_TRUE(channel_->GetStats(&info)); 978 EXPECT_TRUE(channel_->GetStats(&info));
974 ASSERT_EQ(2U, info.senders.size()); 979 ASSERT_EQ(2U, info.senders.size());
975 if (info.senders[0].packets_sent + info.senders[1].packets_sent == 980 if (info.senders[0].packets_sent + info.senders[1].packets_sent ==
976 NumRtpPackets()) { 981 NumRtpPackets()) {
977 // Stats have been updated for both sent frames, expectations can be 982 // Stats have been updated for both sent frames, expectations can be
978 // checked now. 983 // checked now.
979 break; 984 break;
980 } 985 }
981 } 986 }
(...skipping 21 matching lines...) Expand all
1003 parameters.max_bandwidth_bps = 128 * 1024; 1008 parameters.max_bandwidth_bps = 128 * 1024;
1004 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1009 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1005 } 1010 }
1006 // Test that we can set the SSRC for the default send source. 1011 // Test that we can set the SSRC for the default send source.
1007 void SetSendSsrc() { 1012 void SetSendSsrc() {
1008 EXPECT_TRUE(SetDefaultCodec()); 1013 EXPECT_TRUE(SetDefaultCodec());
1009 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec())); 1014 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec()));
1010 EXPECT_TRUE(SetSend(true)); 1015 EXPECT_TRUE(SetSend(true));
1011 EXPECT_TRUE(SendFrame()); 1016 EXPECT_TRUE(SendFrame());
1012 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); 1017 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout);
1013 uint32 ssrc = 0; 1018 uint32_t ssrc = 0;
1014 rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0)); 1019 rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0));
1015 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); 1020 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
1016 EXPECT_EQ(kSsrc, ssrc); 1021 EXPECT_EQ(kSsrc, ssrc);
1017 EXPECT_EQ(NumRtpPackets(), NumRtpPackets(ssrc)); 1022 EXPECT_EQ(NumRtpPackets(), NumRtpPackets(ssrc));
1018 EXPECT_EQ(NumRtpBytes(), NumRtpBytes(ssrc)); 1023 EXPECT_EQ(NumRtpBytes(), NumRtpBytes(ssrc));
1019 EXPECT_EQ(1, NumSentSsrcs()); 1024 EXPECT_EQ(1, NumSentSsrcs());
1020 EXPECT_EQ(0, NumRtpPackets(kSsrc - 1)); 1025 EXPECT_EQ(0, NumRtpPackets(kSsrc - 1));
1021 EXPECT_EQ(0, NumRtpBytes(kSsrc - 1)); 1026 EXPECT_EQ(0, NumRtpBytes(kSsrc - 1));
1022 } 1027 }
1023 // Test that we can set the SSRC even after codecs are set. 1028 // Test that we can set the SSRC even after codecs are set.
1024 void SetSendSsrcAfterSetCodecs() { 1029 void SetSendSsrcAfterSetCodecs() {
1025 // Remove stream added in Setup. 1030 // Remove stream added in Setup.
1026 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); 1031 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1027 EXPECT_TRUE(SetDefaultCodec()); 1032 EXPECT_TRUE(SetDefaultCodec());
1028 EXPECT_TRUE(channel_->AddSendStream( 1033 EXPECT_TRUE(channel_->AddSendStream(
1029 cricket::StreamParams::CreateLegacy(999))); 1034 cricket::StreamParams::CreateLegacy(999)));
1030 EXPECT_TRUE(channel_->SetCapturer(999u, video_capturer_.get())); 1035 EXPECT_TRUE(channel_->SetCapturer(999u, video_capturer_.get()));
1031 EXPECT_TRUE(SetSendStreamFormat(999u, DefaultCodec())); 1036 EXPECT_TRUE(SetSendStreamFormat(999u, DefaultCodec()));
1032 EXPECT_TRUE(SetSend(true)); 1037 EXPECT_TRUE(SetSend(true));
1033 EXPECT_TRUE(WaitAndSendFrame(0)); 1038 EXPECT_TRUE(WaitAndSendFrame(0));
1034 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); 1039 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout);
1035 uint32 ssrc = 0; 1040 uint32_t ssrc = 0;
1036 rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0)); 1041 rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0));
1037 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); 1042 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
1038 EXPECT_EQ(999u, ssrc); 1043 EXPECT_EQ(999u, ssrc);
1039 EXPECT_EQ(NumRtpPackets(), NumRtpPackets(ssrc)); 1044 EXPECT_EQ(NumRtpPackets(), NumRtpPackets(ssrc));
1040 EXPECT_EQ(NumRtpBytes(), NumRtpBytes(ssrc)); 1045 EXPECT_EQ(NumRtpBytes(), NumRtpBytes(ssrc));
1041 EXPECT_EQ(1, NumSentSsrcs()); 1046 EXPECT_EQ(1, NumSentSsrcs());
1042 EXPECT_EQ(0, NumRtpPackets(kSsrc)); 1047 EXPECT_EQ(0, NumRtpPackets(kSsrc));
1043 EXPECT_EQ(0, NumRtpBytes(kSsrc)); 1048 EXPECT_EQ(0, NumRtpBytes(kSsrc));
1044 } 1049 }
1045 // Test that we can set the default video renderer before and after 1050 // Test that we can set the default video renderer before and after
1046 // media is received. 1051 // media is received.
1047 void SetRenderer() { 1052 void SetRenderer() {
1048 uint8 data1[] = { 1053 uint8_t data1[] = {
1049 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 1054 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1050 };
1051 1055
1052 rtc::Buffer packet1(data1, sizeof(data1)); 1056 rtc::Buffer packet1(data1, sizeof(data1));
1053 rtc::SetBE32(packet1.data() + 8, kSsrc); 1057 rtc::SetBE32(packet1.data() + 8, kSsrc);
1054 channel_->SetRenderer(kDefaultReceiveSsrc, NULL); 1058 channel_->SetRenderer(kDefaultReceiveSsrc, NULL);
1055 EXPECT_TRUE(SetDefaultCodec()); 1059 EXPECT_TRUE(SetDefaultCodec());
1056 EXPECT_TRUE(SetSend(true)); 1060 EXPECT_TRUE(SetSend(true));
1057 EXPECT_TRUE(channel_->SetRender(true)); 1061 EXPECT_TRUE(channel_->SetRender(true));
1058 EXPECT_EQ(0, renderer_.num_rendered_frames()); 1062 EXPECT_EQ(0, renderer_.num_rendered_frames());
1059 channel_->OnPacketReceived(&packet1, rtc::PacketTime()); 1063 channel_->OnPacketReceived(&packet1, rtc::PacketTime());
1060 EXPECT_TRUE(channel_->SetRenderer(kDefaultReceiveSsrc, &renderer_)); 1064 EXPECT_TRUE(channel_->SetRenderer(kDefaultReceiveSsrc, &renderer_));
(...skipping 14 matching lines...) Expand all
1075 1079
1076 // Tests setting up and configuring a send stream. 1080 // Tests setting up and configuring a send stream.
1077 void AddRemoveSendStreams() { 1081 void AddRemoveSendStreams() {
1078 EXPECT_TRUE(SetOneCodec(DefaultCodec())); 1082 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
1079 EXPECT_TRUE(SetSend(true)); 1083 EXPECT_TRUE(SetSend(true));
1080 EXPECT_TRUE(channel_->SetRender(true)); 1084 EXPECT_TRUE(channel_->SetRender(true));
1081 EXPECT_TRUE(channel_->SetRenderer(kDefaultReceiveSsrc, &renderer_)); 1085 EXPECT_TRUE(channel_->SetRenderer(kDefaultReceiveSsrc, &renderer_));
1082 EXPECT_TRUE(SendFrame()); 1086 EXPECT_TRUE(SendFrame());
1083 EXPECT_FRAME_WAIT(1, DefaultCodec().width, DefaultCodec().height, kTimeout); 1087 EXPECT_FRAME_WAIT(1, DefaultCodec().width, DefaultCodec().height, kTimeout);
1084 EXPECT_GT(NumRtpPackets(), 0); 1088 EXPECT_GT(NumRtpPackets(), 0);
1085 uint32 ssrc = 0; 1089 uint32_t ssrc = 0;
1086 size_t last_packet = NumRtpPackets() - 1; 1090 size_t last_packet = NumRtpPackets() - 1;
1087 rtc::scoped_ptr<const rtc::Buffer> 1091 rtc::scoped_ptr<const rtc::Buffer>
1088 p(GetRtpPacket(static_cast<int>(last_packet))); 1092 p(GetRtpPacket(static_cast<int>(last_packet)));
1089 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); 1093 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
1090 EXPECT_EQ(kSsrc, ssrc); 1094 EXPECT_EQ(kSsrc, ssrc);
1091 1095
1092 // Remove the send stream that was added during Setup. 1096 // Remove the send stream that was added during Setup.
1093 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); 1097 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1094 int rtp_packets = NumRtpPackets(); 1098 int rtp_packets = NumRtpPackets();
1095 1099
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 EXPECT_TRUE(SetSend(true)); 1254 EXPECT_TRUE(SetSend(true));
1251 EXPECT_TRUE(channel_->SetRender(true)); 1255 EXPECT_TRUE(channel_->SetRender(true));
1252 EXPECT_TRUE(channel_->AddRecvStream( 1256 EXPECT_TRUE(channel_->AddRecvStream(
1253 cricket::StreamParams::CreateLegacy(1))); 1257 cricket::StreamParams::CreateLegacy(1)));
1254 EXPECT_TRUE(channel_->AddRecvStream( 1258 EXPECT_TRUE(channel_->AddRecvStream(
1255 cricket::StreamParams::CreateLegacy(2))); 1259 cricket::StreamParams::CreateLegacy(2)));
1256 EXPECT_TRUE(channel_->SetRenderer(1, &renderer1)); 1260 EXPECT_TRUE(channel_->SetRenderer(1, &renderer1));
1257 EXPECT_TRUE(channel_->SetRenderer(2, &renderer2)); 1261 EXPECT_TRUE(channel_->SetRenderer(2, &renderer2));
1258 EXPECT_EQ(0, renderer1.num_rendered_frames()); 1262 EXPECT_EQ(0, renderer1.num_rendered_frames());
1259 EXPECT_EQ(0, renderer2.num_rendered_frames()); 1263 EXPECT_EQ(0, renderer2.num_rendered_frames());
1260 std::vector<uint32> ssrcs; 1264 std::vector<uint32_t> ssrcs;
1261 ssrcs.push_back(1); 1265 ssrcs.push_back(1);
1262 ssrcs.push_back(2); 1266 ssrcs.push_back(2);
1263 network_interface_.SetConferenceMode(true, ssrcs); 1267 network_interface_.SetConferenceMode(true, ssrcs);
1264 EXPECT_TRUE(SendFrame()); 1268 EXPECT_TRUE(SendFrame());
1265 EXPECT_FRAME_ON_RENDERER_WAIT( 1269 EXPECT_FRAME_ON_RENDERER_WAIT(
1266 renderer1, 1, DefaultCodec().width, DefaultCodec().height, kTimeout); 1270 renderer1, 1, DefaultCodec().width, DefaultCodec().height, kTimeout);
1267 EXPECT_FRAME_ON_RENDERER_WAIT( 1271 EXPECT_FRAME_ON_RENDERER_WAIT(
1268 renderer2, 1, DefaultCodec().width, DefaultCodec().height, kTimeout); 1272 renderer2, 1, DefaultCodec().width, DefaultCodec().height, kTimeout);
1269 1273
1270 rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0)); 1274 rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0));
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 void SetSendStreamFormat0x0() { 1627 void SetSendStreamFormat0x0() {
1624 EXPECT_TRUE(SetOneCodec(DefaultCodec())); 1628 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
1625 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec())); 1629 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec()));
1626 EXPECT_TRUE(SetSend(true)); 1630 EXPECT_TRUE(SetSend(true));
1627 EXPECT_TRUE(channel_->SetRender(true)); 1631 EXPECT_TRUE(channel_->SetRender(true));
1628 EXPECT_TRUE(channel_->SetRenderer(kDefaultReceiveSsrc, &renderer_)); 1632 EXPECT_TRUE(channel_->SetRenderer(kDefaultReceiveSsrc, &renderer_));
1629 EXPECT_EQ(0, renderer_.num_rendered_frames()); 1633 EXPECT_EQ(0, renderer_.num_rendered_frames());
1630 // This frame should be received. 1634 // This frame should be received.
1631 EXPECT_TRUE(SendFrame()); 1635 EXPECT_TRUE(SendFrame());
1632 EXPECT_FRAME_WAIT(1, DefaultCodec().width, DefaultCodec().height, kTimeout); 1636 EXPECT_FRAME_WAIT(1, DefaultCodec().width, DefaultCodec().height, kTimeout);
1633 const int64 interval = cricket::VideoFormat::FpsToInterval( 1637 const int64_t interval =
1634 DefaultCodec().framerate); 1638 cricket::VideoFormat::FpsToInterval(DefaultCodec().framerate);
1635 cricket::VideoFormat format( 1639 cricket::VideoFormat format(
1636 0, 1640 0,
1637 0, 1641 0,
1638 interval, 1642 interval,
1639 cricket::FOURCC_I420); 1643 cricket::FOURCC_I420);
1640 EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc, format)); 1644 EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc, format));
1641 // This frame should not be received. 1645 // This frame should not be received.
1642 EXPECT_TRUE(WaitAndSendFrame( 1646 EXPECT_TRUE(WaitAndSendFrame(
1643 static_cast<int>(interval/rtc::kNumNanosecsPerMillisec))); 1647 static_cast<int>(interval/rtc::kNumNanosecsPerMillisec)));
1644 rtc::Thread::Current()->ProcessMessages(500); 1648 rtc::Thread::Current()->ProcessMessages(500);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 void TwoStreamsReUseFirstStream(const cricket::VideoCodec& codec) { 1739 void TwoStreamsReUseFirstStream(const cricket::VideoCodec& codec) {
1736 SetUpSecondStream(); 1740 SetUpSecondStream();
1737 // Default channel used by the first stream. 1741 // Default channel used by the first stream.
1738 EXPECT_EQ(kSsrc, channel_->GetDefaultSendChannelSsrc()); 1742 EXPECT_EQ(kSsrc, channel_->GetDefaultSendChannelSsrc());
1739 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc)); 1743 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc));
1740 EXPECT_FALSE(channel_->RemoveRecvStream(kSsrc)); 1744 EXPECT_FALSE(channel_->RemoveRecvStream(kSsrc));
1741 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); 1745 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1742 EXPECT_FALSE(channel_->RemoveSendStream(kSsrc)); 1746 EXPECT_FALSE(channel_->RemoveSendStream(kSsrc));
1743 // Default channel is no longer used by a stream. 1747 // Default channel is no longer used by a stream.
1744 EXPECT_EQ(0u, channel_->GetDefaultSendChannelSsrc()); 1748 EXPECT_EQ(0u, channel_->GetDefaultSendChannelSsrc());
1745 uint32 new_ssrc = kSsrc + 100; 1749 uint32_t new_ssrc = kSsrc + 100;
1746 EXPECT_TRUE(channel_->AddSendStream( 1750 EXPECT_TRUE(channel_->AddSendStream(
1747 cricket::StreamParams::CreateLegacy(new_ssrc))); 1751 cricket::StreamParams::CreateLegacy(new_ssrc)));
1748 // Re-use default channel. 1752 // Re-use default channel.
1749 EXPECT_EQ(new_ssrc, channel_->GetDefaultSendChannelSsrc()); 1753 EXPECT_EQ(new_ssrc, channel_->GetDefaultSendChannelSsrc());
1750 EXPECT_FALSE(channel_->AddSendStream( 1754 EXPECT_FALSE(channel_->AddSendStream(
1751 cricket::StreamParams::CreateLegacy(new_ssrc))); 1755 cricket::StreamParams::CreateLegacy(new_ssrc)));
1752 EXPECT_TRUE(channel_->AddRecvStream( 1756 EXPECT_TRUE(channel_->AddRecvStream(
1753 cricket::StreamParams::CreateLegacy(new_ssrc))); 1757 cricket::StreamParams::CreateLegacy(new_ssrc)));
1754 EXPECT_TRUE(channel_->SetRenderer(new_ssrc, &renderer_)); 1758 EXPECT_TRUE(channel_->SetRenderer(new_ssrc, &renderer_));
1755 EXPECT_FALSE(channel_->AddRecvStream( 1759 EXPECT_FALSE(channel_->AddRecvStream(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1827 rtc::scoped_ptr<C> channel_; 1831 rtc::scoped_ptr<C> channel_;
1828 cricket::FakeNetworkInterface network_interface_; 1832 cricket::FakeNetworkInterface network_interface_;
1829 cricket::FakeVideoRenderer renderer_; 1833 cricket::FakeVideoRenderer renderer_;
1830 cricket::VideoMediaChannel::Error media_error_; 1834 cricket::VideoMediaChannel::Error media_error_;
1831 1835
1832 // Used by test cases where 2 streams are run on the same channel. 1836 // Used by test cases where 2 streams are run on the same channel.
1833 cricket::FakeVideoRenderer renderer2_; 1837 cricket::FakeVideoRenderer renderer2_;
1834 }; 1838 };
1835 1839
1836 #endif // TALK_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT 1840 #endif // TALK_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698