OLD | NEW |
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 Loading... |
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 Loading... |
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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 success = channel_->SetSendParameters(parameters); | 547 success = channel_->SetSendParameters(parameters); |
547 } | 548 } |
548 if (success) { | 549 if (success) { |
549 success = SetSend(sending); | 550 success = SetSend(sending); |
550 } | 551 } |
551 return success; | 552 return success; |
552 } | 553 } |
553 bool SetSend(bool send) { | 554 bool SetSend(bool send) { |
554 return channel_->SetSend(send); | 555 return channel_->SetSend(send); |
555 } | 556 } |
556 bool SetSendStreamFormat(uint32 ssrc, const cricket::VideoCodec& codec) { | 557 bool SetSendStreamFormat(uint32_t ssrc, const cricket::VideoCodec& codec) { |
557 return channel_->SetSendStreamFormat(ssrc, cricket::VideoFormat( | 558 return channel_->SetSendStreamFormat(ssrc, cricket::VideoFormat( |
558 codec.width, codec.height, | 559 codec.width, codec.height, |
559 cricket::VideoFormat::FpsToInterval(codec.framerate), | 560 cricket::VideoFormat::FpsToInterval(codec.framerate), |
560 cricket::FOURCC_ANY)); | 561 cricket::FOURCC_ANY)); |
561 } | 562 } |
562 int DrainOutgoingPackets() { | 563 int DrainOutgoingPackets() { |
563 int packets = 0; | 564 int packets = 0; |
564 do { | 565 do { |
565 packets = NumRtpPackets(); | 566 packets = NumRtpPackets(); |
566 // 100 ms should be long enough. | 567 // 100 ms should be long enough. |
(...skipping 30 matching lines...) Expand all Loading... |
597 return 0; | 598 return 0; |
598 #endif | 599 #endif |
599 } | 600 } |
600 bool SendCustomVideoFrame(int w, int h) { | 601 bool SendCustomVideoFrame(int w, int h) { |
601 if (!video_capturer_.get()) return false; | 602 if (!video_capturer_.get()) return false; |
602 return video_capturer_->CaptureCustomFrame(w, h, cricket::FOURCC_I420); | 603 return video_capturer_->CaptureCustomFrame(w, h, cricket::FOURCC_I420); |
603 } | 604 } |
604 int NumRtpBytes() { | 605 int NumRtpBytes() { |
605 return network_interface_.NumRtpBytes(); | 606 return network_interface_.NumRtpBytes(); |
606 } | 607 } |
607 int NumRtpBytes(uint32 ssrc) { | 608 int NumRtpBytes(uint32_t ssrc) { |
608 return network_interface_.NumRtpBytes(ssrc); | 609 return network_interface_.NumRtpBytes(ssrc); |
609 } | 610 } |
610 int NumRtpPackets() { | 611 int NumRtpPackets() { |
611 return network_interface_.NumRtpPackets(); | 612 return network_interface_.NumRtpPackets(); |
612 } | 613 } |
613 int NumRtpPackets(uint32 ssrc) { | 614 int NumRtpPackets(uint32_t ssrc) { |
614 return network_interface_.NumRtpPackets(ssrc); | 615 return network_interface_.NumRtpPackets(ssrc); |
615 } | 616 } |
616 int NumSentSsrcs() { | 617 int NumSentSsrcs() { |
617 return network_interface_.NumSentSsrcs(); | 618 return network_interface_.NumSentSsrcs(); |
618 } | 619 } |
619 const rtc::Buffer* GetRtpPacket(int index) { | 620 const rtc::Buffer* GetRtpPacket(int index) { |
620 return network_interface_.GetRtpPacket(index); | 621 return network_interface_.GetRtpPacket(index); |
621 } | 622 } |
622 int NumRtcpPackets() { | 623 int NumRtcpPackets() { |
623 return network_interface_.NumRtcpPackets(); | 624 return network_interface_.NumRtcpPackets(); |
624 } | 625 } |
625 const rtc::Buffer* GetRtcpPacket(int index) { | 626 const rtc::Buffer* GetRtcpPacket(int index) { |
626 return network_interface_.GetRtcpPacket(index); | 627 return network_interface_.GetRtcpPacket(index); |
627 } | 628 } |
628 static int GetPayloadType(const rtc::Buffer* p) { | 629 static int GetPayloadType(const rtc::Buffer* p) { |
629 int pt = -1; | 630 int pt = -1; |
630 ParseRtpPacket(p, NULL, &pt, NULL, NULL, NULL, NULL); | 631 ParseRtpPacket(p, NULL, &pt, NULL, NULL, NULL, NULL); |
631 return pt; | 632 return pt; |
632 } | 633 } |
633 static bool ParseRtpPacket(const rtc::Buffer* p, bool* x, int* pt, | 634 static bool ParseRtpPacket(const rtc::Buffer* p, |
634 int* seqnum, uint32* tstamp, uint32* ssrc, | 635 bool* x, |
| 636 int* pt, |
| 637 int* seqnum, |
| 638 uint32_t* tstamp, |
| 639 uint32_t* ssrc, |
635 std::string* payload) { | 640 std::string* payload) { |
636 rtc::ByteBuffer buf(*p); | 641 rtc::ByteBuffer buf(*p); |
637 uint8 u08 = 0; | 642 uint8_t u08 = 0; |
638 uint16 u16 = 0; | 643 uint16_t u16 = 0; |
639 uint32 u32 = 0; | 644 uint32_t u32 = 0; |
640 | 645 |
641 // Read X and CC fields. | 646 // Read X and CC fields. |
642 if (!buf.ReadUInt8(&u08)) return false; | 647 if (!buf.ReadUInt8(&u08)) return false; |
643 bool extension = ((u08 & 0x10) != 0); | 648 bool extension = ((u08 & 0x10) != 0); |
644 uint8 cc = (u08 & 0x0F); | 649 uint8_t cc = (u08 & 0x0F); |
645 if (x) *x = extension; | 650 if (x) *x = extension; |
646 | 651 |
647 // Read PT field. | 652 // Read PT field. |
648 if (!buf.ReadUInt8(&u08)) return false; | 653 if (!buf.ReadUInt8(&u08)) return false; |
649 if (pt) *pt = (u08 & 0x7F); | 654 if (pt) *pt = (u08 & 0x7F); |
650 | 655 |
651 // Read Sequence Number field. | 656 // Read Sequence Number field. |
652 if (!buf.ReadUInt16(&u16)) return false; | 657 if (!buf.ReadUInt16(&u16)) return false; |
653 if (seqnum) *seqnum = u16; | 658 if (seqnum) *seqnum = u16; |
654 | 659 |
655 // Read Timestamp field. | 660 // Read Timestamp field. |
656 if (!buf.ReadUInt32(&u32)) return false; | 661 if (!buf.ReadUInt32(&u32)) return false; |
657 if (tstamp) *tstamp = u32; | 662 if (tstamp) *tstamp = u32; |
658 | 663 |
659 // Read SSRC field. | 664 // Read SSRC field. |
660 if (!buf.ReadUInt32(&u32)) return false; | 665 if (!buf.ReadUInt32(&u32)) return false; |
661 if (ssrc) *ssrc = u32; | 666 if (ssrc) *ssrc = u32; |
662 | 667 |
663 // Skip CSRCs. | 668 // Skip CSRCs. |
664 for (uint8 i = 0; i < cc; ++i) { | 669 for (uint8_t i = 0; i < cc; ++i) { |
665 if (!buf.ReadUInt32(&u32)) return false; | 670 if (!buf.ReadUInt32(&u32)) return false; |
666 } | 671 } |
667 | 672 |
668 // Skip extension header. | 673 // Skip extension header. |
669 if (extension) { | 674 if (extension) { |
670 // Read Profile-specific extension header ID | 675 // Read Profile-specific extension header ID |
671 if (!buf.ReadUInt16(&u16)) return false; | 676 if (!buf.ReadUInt16(&u16)) return false; |
672 | 677 |
673 // Read Extension header length | 678 // Read Extension header length |
674 if (!buf.ReadUInt16(&u16)) return false; | 679 if (!buf.ReadUInt16(&u16)) return false; |
675 uint16 ext_header_len = u16; | 680 uint16_t ext_header_len = u16; |
676 | 681 |
677 // Read Extension header | 682 // Read Extension header |
678 for (uint16 i = 0; i < ext_header_len; ++i) { | 683 for (uint16_t i = 0; i < ext_header_len; ++i) { |
679 if (!buf.ReadUInt32(&u32)) return false; | 684 if (!buf.ReadUInt32(&u32)) return false; |
680 } | 685 } |
681 } | 686 } |
682 | 687 |
683 if (payload) { | 688 if (payload) { |
684 return buf.ReadString(payload, buf.Length()); | 689 return buf.ReadString(payload, buf.Length()); |
685 } | 690 } |
686 return true; | 691 return true; |
687 } | 692 } |
688 | 693 |
689 // Parse all RTCP packet, from start_index to stop_index, and count how many | 694 // Parse all RTCP packet, from start_index to stop_index, and count how many |
690 // FIR (PT=206 and FMT=4 according to RFC 5104). If successful, set the count | 695 // FIR (PT=206 and FMT=4 according to RFC 5104). If successful, set the count |
691 // and return true. | 696 // and return true. |
692 bool CountRtcpFir(int start_index, int stop_index, int* fir_count) { | 697 bool CountRtcpFir(int start_index, int stop_index, int* fir_count) { |
693 int count = 0; | 698 int count = 0; |
694 for (int i = start_index; i < stop_index; ++i) { | 699 for (int i = start_index; i < stop_index; ++i) { |
695 rtc::scoped_ptr<const rtc::Buffer> p(GetRtcpPacket(i)); | 700 rtc::scoped_ptr<const rtc::Buffer> p(GetRtcpPacket(i)); |
696 rtc::ByteBuffer buf(*p); | 701 rtc::ByteBuffer buf(*p); |
697 size_t total_len = 0; | 702 size_t total_len = 0; |
698 // The packet may be a compound RTCP packet. | 703 // The packet may be a compound RTCP packet. |
699 while (total_len < p->size()) { | 704 while (total_len < p->size()) { |
700 // Read FMT, type and length. | 705 // Read FMT, type and length. |
701 uint8 fmt = 0; | 706 uint8_t fmt = 0; |
702 uint8 type = 0; | 707 uint8_t type = 0; |
703 uint16 length = 0; | 708 uint16_t length = 0; |
704 if (!buf.ReadUInt8(&fmt)) return false; | 709 if (!buf.ReadUInt8(&fmt)) return false; |
705 fmt &= 0x1F; | 710 fmt &= 0x1F; |
706 if (!buf.ReadUInt8(&type)) return false; | 711 if (!buf.ReadUInt8(&type)) return false; |
707 if (!buf.ReadUInt16(&length)) return false; | 712 if (!buf.ReadUInt16(&length)) return false; |
708 buf.Consume(length * 4); // Skip RTCP data. | 713 buf.Consume(length * 4); // Skip RTCP data. |
709 total_len += (length + 1) * 4; | 714 total_len += (length + 1) * 4; |
710 if ((192 == type) || ((206 == type) && (4 == fmt))) { | 715 if ((192 == type) || ((206 == type) && (4 == fmt))) { |
711 ++count; | 716 ++count; |
712 } | 717 } |
713 } | 718 } |
714 } | 719 } |
715 | 720 |
716 if (fir_count) { | 721 if (fir_count) { |
717 *fir_count = count; | 722 *fir_count = count; |
718 } | 723 } |
719 return true; | 724 return true; |
720 } | 725 } |
721 | 726 |
722 void OnVideoChannelError(uint32 ssrc, | 727 void OnVideoChannelError(uint32_t ssrc, |
723 cricket::VideoMediaChannel::Error error) { | 728 cricket::VideoMediaChannel::Error error) { |
724 media_error_ = error; | 729 media_error_ = error; |
725 } | 730 } |
726 | 731 |
727 // Test that SetSend works. | 732 // Test that SetSend works. |
728 void SetSend() { | 733 void SetSend() { |
729 EXPECT_FALSE(channel_->sending()); | 734 EXPECT_FALSE(channel_->sending()); |
730 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get())); | 735 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get())); |
731 EXPECT_TRUE(SetOneCodec(DefaultCodec())); | 736 EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
732 EXPECT_FALSE(channel_->sending()); | 737 EXPECT_FALSE(channel_->sending()); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 EXPECT_TRUE(channel_->SetSendParameters(parameters)); | 879 EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
875 EXPECT_TRUE(SetSend(true)); | 880 EXPECT_TRUE(SetSend(true)); |
876 EXPECT_TRUE(channel_->AddRecvStream( | 881 EXPECT_TRUE(channel_->AddRecvStream( |
877 cricket::StreamParams::CreateLegacy(1))); | 882 cricket::StreamParams::CreateLegacy(1))); |
878 EXPECT_TRUE(channel_->AddRecvStream( | 883 EXPECT_TRUE(channel_->AddRecvStream( |
879 cricket::StreamParams::CreateLegacy(2))); | 884 cricket::StreamParams::CreateLegacy(2))); |
880 EXPECT_TRUE(channel_->SetRenderer(1, &renderer1)); | 885 EXPECT_TRUE(channel_->SetRenderer(1, &renderer1)); |
881 EXPECT_TRUE(channel_->SetRenderer(2, &renderer2)); | 886 EXPECT_TRUE(channel_->SetRenderer(2, &renderer2)); |
882 EXPECT_EQ(0, renderer1.num_rendered_frames()); | 887 EXPECT_EQ(0, renderer1.num_rendered_frames()); |
883 EXPECT_EQ(0, renderer2.num_rendered_frames()); | 888 EXPECT_EQ(0, renderer2.num_rendered_frames()); |
884 std::vector<uint32> ssrcs; | 889 std::vector<uint32_t> ssrcs; |
885 ssrcs.push_back(1); | 890 ssrcs.push_back(1); |
886 ssrcs.push_back(2); | 891 ssrcs.push_back(2); |
887 network_interface_.SetConferenceMode(true, ssrcs); | 892 network_interface_.SetConferenceMode(true, ssrcs); |
888 EXPECT_TRUE(SendFrame()); | 893 EXPECT_TRUE(SendFrame()); |
889 EXPECT_FRAME_ON_RENDERER_WAIT( | 894 EXPECT_FRAME_ON_RENDERER_WAIT( |
890 renderer1, 1, DefaultCodec().width, DefaultCodec().height, kTimeout); | 895 renderer1, 1, DefaultCodec().width, DefaultCodec().height, kTimeout); |
891 EXPECT_FRAME_ON_RENDERER_WAIT( | 896 EXPECT_FRAME_ON_RENDERER_WAIT( |
892 renderer2, 1, DefaultCodec().width, DefaultCodec().height, kTimeout); | 897 renderer2, 1, DefaultCodec().width, DefaultCodec().height, kTimeout); |
893 | 898 |
894 EXPECT_TRUE(channel_->SetSend(false)); | 899 EXPECT_TRUE(channel_->SetSend(false)); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 EXPECT_TRUE(channel_->SetRenderer(5678, &renderer2)); | 956 EXPECT_TRUE(channel_->SetRenderer(5678, &renderer2)); |
952 EXPECT_TRUE(capturer->CaptureCustomFrame( | 957 EXPECT_TRUE(capturer->CaptureCustomFrame( |
953 kTestWidth, kTestHeight, cricket::FOURCC_I420)); | 958 kTestWidth, kTestHeight, cricket::FOURCC_I420)); |
954 EXPECT_FRAME_ON_RENDERER_WAIT( | 959 EXPECT_FRAME_ON_RENDERER_WAIT( |
955 renderer2, 1, kTestWidth, kTestHeight, kTimeout); | 960 renderer2, 1, kTestWidth, kTestHeight, kTimeout); |
956 | 961 |
957 // Get stats, and make sure they are correct for two senders. We wait until | 962 // Get stats, and make sure they are correct for two senders. We wait until |
958 // the number of expected packets have been sent to avoid races where we | 963 // the number of expected packets have been sent to avoid races where we |
959 // check stats before it has been updated. | 964 // check stats before it has been updated. |
960 cricket::VideoMediaInfo info; | 965 cricket::VideoMediaInfo info; |
961 for (uint32 i = 0; i < kTimeout; ++i) { | 966 for (uint32_t i = 0; i < kTimeout; ++i) { |
962 rtc::Thread::Current()->ProcessMessages(1); | 967 rtc::Thread::Current()->ProcessMessages(1); |
963 EXPECT_TRUE(channel_->GetStats(&info)); | 968 EXPECT_TRUE(channel_->GetStats(&info)); |
964 ASSERT_EQ(2U, info.senders.size()); | 969 ASSERT_EQ(2U, info.senders.size()); |
965 if (info.senders[0].packets_sent + info.senders[1].packets_sent == | 970 if (info.senders[0].packets_sent + info.senders[1].packets_sent == |
966 NumRtpPackets()) { | 971 NumRtpPackets()) { |
967 // Stats have been updated for both sent frames, expectations can be | 972 // Stats have been updated for both sent frames, expectations can be |
968 // checked now. | 973 // checked now. |
969 break; | 974 break; |
970 } | 975 } |
971 } | 976 } |
(...skipping 21 matching lines...) Expand all Loading... |
993 parameters.max_bandwidth_bps = 128 * 1024; | 998 parameters.max_bandwidth_bps = 128 * 1024; |
994 EXPECT_TRUE(channel_->SetSendParameters(parameters)); | 999 EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
995 } | 1000 } |
996 // Test that we can set the SSRC for the default send source. | 1001 // Test that we can set the SSRC for the default send source. |
997 void SetSendSsrc() { | 1002 void SetSendSsrc() { |
998 EXPECT_TRUE(SetDefaultCodec()); | 1003 EXPECT_TRUE(SetDefaultCodec()); |
999 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec())); | 1004 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec())); |
1000 EXPECT_TRUE(SetSend(true)); | 1005 EXPECT_TRUE(SetSend(true)); |
1001 EXPECT_TRUE(SendFrame()); | 1006 EXPECT_TRUE(SendFrame()); |
1002 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); | 1007 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); |
1003 uint32 ssrc = 0; | 1008 uint32_t ssrc = 0; |
1004 rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0)); | 1009 rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0)); |
1005 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); | 1010 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); |
1006 EXPECT_EQ(kSsrc, ssrc); | 1011 EXPECT_EQ(kSsrc, ssrc); |
1007 EXPECT_EQ(NumRtpPackets(), NumRtpPackets(ssrc)); | 1012 EXPECT_EQ(NumRtpPackets(), NumRtpPackets(ssrc)); |
1008 EXPECT_EQ(NumRtpBytes(), NumRtpBytes(ssrc)); | 1013 EXPECT_EQ(NumRtpBytes(), NumRtpBytes(ssrc)); |
1009 EXPECT_EQ(1, NumSentSsrcs()); | 1014 EXPECT_EQ(1, NumSentSsrcs()); |
1010 EXPECT_EQ(0, NumRtpPackets(kSsrc - 1)); | 1015 EXPECT_EQ(0, NumRtpPackets(kSsrc - 1)); |
1011 EXPECT_EQ(0, NumRtpBytes(kSsrc - 1)); | 1016 EXPECT_EQ(0, NumRtpBytes(kSsrc - 1)); |
1012 } | 1017 } |
1013 // Test that we can set the SSRC even after codecs are set. | 1018 // Test that we can set the SSRC even after codecs are set. |
1014 void SetSendSsrcAfterSetCodecs() { | 1019 void SetSendSsrcAfterSetCodecs() { |
1015 // Remove stream added in Setup. | 1020 // Remove stream added in Setup. |
1016 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); | 1021 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |
1017 EXPECT_TRUE(SetDefaultCodec()); | 1022 EXPECT_TRUE(SetDefaultCodec()); |
1018 EXPECT_TRUE(channel_->AddSendStream( | 1023 EXPECT_TRUE(channel_->AddSendStream( |
1019 cricket::StreamParams::CreateLegacy(999))); | 1024 cricket::StreamParams::CreateLegacy(999))); |
1020 EXPECT_TRUE(channel_->SetCapturer(999u, video_capturer_.get())); | 1025 EXPECT_TRUE(channel_->SetCapturer(999u, video_capturer_.get())); |
1021 EXPECT_TRUE(SetSendStreamFormat(999u, DefaultCodec())); | 1026 EXPECT_TRUE(SetSendStreamFormat(999u, DefaultCodec())); |
1022 EXPECT_TRUE(SetSend(true)); | 1027 EXPECT_TRUE(SetSend(true)); |
1023 EXPECT_TRUE(WaitAndSendFrame(0)); | 1028 EXPECT_TRUE(WaitAndSendFrame(0)); |
1024 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); | 1029 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); |
1025 uint32 ssrc = 0; | 1030 uint32_t ssrc = 0; |
1026 rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0)); | 1031 rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0)); |
1027 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); | 1032 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); |
1028 EXPECT_EQ(999u, ssrc); | 1033 EXPECT_EQ(999u, ssrc); |
1029 EXPECT_EQ(NumRtpPackets(), NumRtpPackets(ssrc)); | 1034 EXPECT_EQ(NumRtpPackets(), NumRtpPackets(ssrc)); |
1030 EXPECT_EQ(NumRtpBytes(), NumRtpBytes(ssrc)); | 1035 EXPECT_EQ(NumRtpBytes(), NumRtpBytes(ssrc)); |
1031 EXPECT_EQ(1, NumSentSsrcs()); | 1036 EXPECT_EQ(1, NumSentSsrcs()); |
1032 EXPECT_EQ(0, NumRtpPackets(kSsrc)); | 1037 EXPECT_EQ(0, NumRtpPackets(kSsrc)); |
1033 EXPECT_EQ(0, NumRtpBytes(kSsrc)); | 1038 EXPECT_EQ(0, NumRtpBytes(kSsrc)); |
1034 } | 1039 } |
1035 // Test that we can set the default video renderer before and after | 1040 // Test that we can set the default video renderer before and after |
1036 // media is received. | 1041 // media is received. |
1037 void SetRenderer() { | 1042 void SetRenderer() { |
1038 uint8 data1[] = { | 1043 uint8_t data1[] = { |
1039 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | 1044 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
1040 }; | |
1041 | 1045 |
1042 rtc::Buffer packet1(data1, sizeof(data1)); | 1046 rtc::Buffer packet1(data1, sizeof(data1)); |
1043 rtc::SetBE32(packet1.data() + 8, kSsrc); | 1047 rtc::SetBE32(packet1.data() + 8, kSsrc); |
1044 channel_->SetRenderer(kDefaultReceiveSsrc, NULL); | 1048 channel_->SetRenderer(kDefaultReceiveSsrc, NULL); |
1045 EXPECT_TRUE(SetDefaultCodec()); | 1049 EXPECT_TRUE(SetDefaultCodec()); |
1046 EXPECT_TRUE(SetSend(true)); | 1050 EXPECT_TRUE(SetSend(true)); |
1047 EXPECT_EQ(0, renderer_.num_rendered_frames()); | 1051 EXPECT_EQ(0, renderer_.num_rendered_frames()); |
1048 channel_->OnPacketReceived(&packet1, rtc::PacketTime()); | 1052 channel_->OnPacketReceived(&packet1, rtc::PacketTime()); |
1049 EXPECT_TRUE(channel_->SetRenderer(kDefaultReceiveSsrc, &renderer_)); | 1053 EXPECT_TRUE(channel_->SetRenderer(kDefaultReceiveSsrc, &renderer_)); |
1050 EXPECT_TRUE(SendFrame()); | 1054 EXPECT_TRUE(SendFrame()); |
(...skipping 12 matching lines...) Expand all Loading... |
1063 } | 1067 } |
1064 | 1068 |
1065 // Tests setting up and configuring a send stream. | 1069 // Tests setting up and configuring a send stream. |
1066 void AddRemoveSendStreams() { | 1070 void AddRemoveSendStreams() { |
1067 EXPECT_TRUE(SetOneCodec(DefaultCodec())); | 1071 EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
1068 EXPECT_TRUE(SetSend(true)); | 1072 EXPECT_TRUE(SetSend(true)); |
1069 EXPECT_TRUE(channel_->SetRenderer(kDefaultReceiveSsrc, &renderer_)); | 1073 EXPECT_TRUE(channel_->SetRenderer(kDefaultReceiveSsrc, &renderer_)); |
1070 EXPECT_TRUE(SendFrame()); | 1074 EXPECT_TRUE(SendFrame()); |
1071 EXPECT_FRAME_WAIT(1, DefaultCodec().width, DefaultCodec().height, kTimeout); | 1075 EXPECT_FRAME_WAIT(1, DefaultCodec().width, DefaultCodec().height, kTimeout); |
1072 EXPECT_GT(NumRtpPackets(), 0); | 1076 EXPECT_GT(NumRtpPackets(), 0); |
1073 uint32 ssrc = 0; | 1077 uint32_t ssrc = 0; |
1074 size_t last_packet = NumRtpPackets() - 1; | 1078 size_t last_packet = NumRtpPackets() - 1; |
1075 rtc::scoped_ptr<const rtc::Buffer> | 1079 rtc::scoped_ptr<const rtc::Buffer> |
1076 p(GetRtpPacket(static_cast<int>(last_packet))); | 1080 p(GetRtpPacket(static_cast<int>(last_packet))); |
1077 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); | 1081 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); |
1078 EXPECT_EQ(kSsrc, ssrc); | 1082 EXPECT_EQ(kSsrc, ssrc); |
1079 | 1083 |
1080 // Remove the send stream that was added during Setup. | 1084 // Remove the send stream that was added during Setup. |
1081 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); | 1085 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |
1082 int rtp_packets = NumRtpPackets(); | 1086 int rtp_packets = NumRtpPackets(); |
1083 | 1087 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1236 EXPECT_TRUE(channel_->SetSendParameters(parameters)); | 1240 EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
1237 EXPECT_TRUE(SetSend(true)); | 1241 EXPECT_TRUE(SetSend(true)); |
1238 EXPECT_TRUE(channel_->AddRecvStream( | 1242 EXPECT_TRUE(channel_->AddRecvStream( |
1239 cricket::StreamParams::CreateLegacy(1))); | 1243 cricket::StreamParams::CreateLegacy(1))); |
1240 EXPECT_TRUE(channel_->AddRecvStream( | 1244 EXPECT_TRUE(channel_->AddRecvStream( |
1241 cricket::StreamParams::CreateLegacy(2))); | 1245 cricket::StreamParams::CreateLegacy(2))); |
1242 EXPECT_TRUE(channel_->SetRenderer(1, &renderer1)); | 1246 EXPECT_TRUE(channel_->SetRenderer(1, &renderer1)); |
1243 EXPECT_TRUE(channel_->SetRenderer(2, &renderer2)); | 1247 EXPECT_TRUE(channel_->SetRenderer(2, &renderer2)); |
1244 EXPECT_EQ(0, renderer1.num_rendered_frames()); | 1248 EXPECT_EQ(0, renderer1.num_rendered_frames()); |
1245 EXPECT_EQ(0, renderer2.num_rendered_frames()); | 1249 EXPECT_EQ(0, renderer2.num_rendered_frames()); |
1246 std::vector<uint32> ssrcs; | 1250 std::vector<uint32_t> ssrcs; |
1247 ssrcs.push_back(1); | 1251 ssrcs.push_back(1); |
1248 ssrcs.push_back(2); | 1252 ssrcs.push_back(2); |
1249 network_interface_.SetConferenceMode(true, ssrcs); | 1253 network_interface_.SetConferenceMode(true, ssrcs); |
1250 EXPECT_TRUE(SendFrame()); | 1254 EXPECT_TRUE(SendFrame()); |
1251 EXPECT_FRAME_ON_RENDERER_WAIT( | 1255 EXPECT_FRAME_ON_RENDERER_WAIT( |
1252 renderer1, 1, DefaultCodec().width, DefaultCodec().height, kTimeout); | 1256 renderer1, 1, DefaultCodec().width, DefaultCodec().height, kTimeout); |
1253 EXPECT_FRAME_ON_RENDERER_WAIT( | 1257 EXPECT_FRAME_ON_RENDERER_WAIT( |
1254 renderer2, 1, DefaultCodec().width, DefaultCodec().height, kTimeout); | 1258 renderer2, 1, DefaultCodec().width, DefaultCodec().height, kTimeout); |
1255 | 1259 |
1256 rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0)); | 1260 rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0)); |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1601 // frames being dropped. | 1605 // frames being dropped. |
1602 void SetSendStreamFormat0x0() { | 1606 void SetSendStreamFormat0x0() { |
1603 EXPECT_TRUE(SetOneCodec(DefaultCodec())); | 1607 EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
1604 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec())); | 1608 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec())); |
1605 EXPECT_TRUE(SetSend(true)); | 1609 EXPECT_TRUE(SetSend(true)); |
1606 EXPECT_TRUE(channel_->SetRenderer(kDefaultReceiveSsrc, &renderer_)); | 1610 EXPECT_TRUE(channel_->SetRenderer(kDefaultReceiveSsrc, &renderer_)); |
1607 EXPECT_EQ(0, renderer_.num_rendered_frames()); | 1611 EXPECT_EQ(0, renderer_.num_rendered_frames()); |
1608 // This frame should be received. | 1612 // This frame should be received. |
1609 EXPECT_TRUE(SendFrame()); | 1613 EXPECT_TRUE(SendFrame()); |
1610 EXPECT_FRAME_WAIT(1, DefaultCodec().width, DefaultCodec().height, kTimeout); | 1614 EXPECT_FRAME_WAIT(1, DefaultCodec().width, DefaultCodec().height, kTimeout); |
1611 const int64 interval = cricket::VideoFormat::FpsToInterval( | 1615 const int64_t interval = |
1612 DefaultCodec().framerate); | 1616 cricket::VideoFormat::FpsToInterval(DefaultCodec().framerate); |
1613 cricket::VideoFormat format( | 1617 cricket::VideoFormat format( |
1614 0, | 1618 0, |
1615 0, | 1619 0, |
1616 interval, | 1620 interval, |
1617 cricket::FOURCC_I420); | 1621 cricket::FOURCC_I420); |
1618 EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc, format)); | 1622 EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc, format)); |
1619 // This frame should not be received. | 1623 // This frame should not be received. |
1620 EXPECT_TRUE(WaitAndSendFrame( | 1624 EXPECT_TRUE(WaitAndSendFrame( |
1621 static_cast<int>(interval/rtc::kNumNanosecsPerMillisec))); | 1625 static_cast<int>(interval/rtc::kNumNanosecsPerMillisec))); |
1622 rtc::Thread::Current()->ProcessMessages(500); | 1626 rtc::Thread::Current()->ProcessMessages(500); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1712 void TwoStreamsReUseFirstStream(const cricket::VideoCodec& codec) { | 1716 void TwoStreamsReUseFirstStream(const cricket::VideoCodec& codec) { |
1713 SetUpSecondStream(); | 1717 SetUpSecondStream(); |
1714 // Default channel used by the first stream. | 1718 // Default channel used by the first stream. |
1715 EXPECT_EQ(kSsrc, channel_->GetDefaultSendChannelSsrc()); | 1719 EXPECT_EQ(kSsrc, channel_->GetDefaultSendChannelSsrc()); |
1716 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc)); | 1720 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc)); |
1717 EXPECT_FALSE(channel_->RemoveRecvStream(kSsrc)); | 1721 EXPECT_FALSE(channel_->RemoveRecvStream(kSsrc)); |
1718 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); | 1722 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |
1719 EXPECT_FALSE(channel_->RemoveSendStream(kSsrc)); | 1723 EXPECT_FALSE(channel_->RemoveSendStream(kSsrc)); |
1720 // Default channel is no longer used by a stream. | 1724 // Default channel is no longer used by a stream. |
1721 EXPECT_EQ(0u, channel_->GetDefaultSendChannelSsrc()); | 1725 EXPECT_EQ(0u, channel_->GetDefaultSendChannelSsrc()); |
1722 uint32 new_ssrc = kSsrc + 100; | 1726 uint32_t new_ssrc = kSsrc + 100; |
1723 EXPECT_TRUE(channel_->AddSendStream( | 1727 EXPECT_TRUE(channel_->AddSendStream( |
1724 cricket::StreamParams::CreateLegacy(new_ssrc))); | 1728 cricket::StreamParams::CreateLegacy(new_ssrc))); |
1725 // Re-use default channel. | 1729 // Re-use default channel. |
1726 EXPECT_EQ(new_ssrc, channel_->GetDefaultSendChannelSsrc()); | 1730 EXPECT_EQ(new_ssrc, channel_->GetDefaultSendChannelSsrc()); |
1727 EXPECT_FALSE(channel_->AddSendStream( | 1731 EXPECT_FALSE(channel_->AddSendStream( |
1728 cricket::StreamParams::CreateLegacy(new_ssrc))); | 1732 cricket::StreamParams::CreateLegacy(new_ssrc))); |
1729 EXPECT_TRUE(channel_->AddRecvStream( | 1733 EXPECT_TRUE(channel_->AddRecvStream( |
1730 cricket::StreamParams::CreateLegacy(new_ssrc))); | 1734 cricket::StreamParams::CreateLegacy(new_ssrc))); |
1731 EXPECT_TRUE(channel_->SetRenderer(new_ssrc, &renderer_)); | 1735 EXPECT_TRUE(channel_->SetRenderer(new_ssrc, &renderer_)); |
1732 EXPECT_FALSE(channel_->AddRecvStream( | 1736 EXPECT_FALSE(channel_->AddRecvStream( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1802 rtc::scoped_ptr<C> channel_; | 1806 rtc::scoped_ptr<C> channel_; |
1803 cricket::FakeNetworkInterface network_interface_; | 1807 cricket::FakeNetworkInterface network_interface_; |
1804 cricket::FakeVideoRenderer renderer_; | 1808 cricket::FakeVideoRenderer renderer_; |
1805 cricket::VideoMediaChannel::Error media_error_; | 1809 cricket::VideoMediaChannel::Error media_error_; |
1806 | 1810 |
1807 // Used by test cases where 2 streams are run on the same channel. | 1811 // Used by test cases where 2 streams are run on the same channel. |
1808 cricket::FakeVideoRenderer renderer2_; | 1812 cricket::FakeVideoRenderer renderer2_; |
1809 }; | 1813 }; |
1810 | 1814 |
1811 #endif // TALK_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT | 1815 #endif // TALK_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT |
OLD | NEW |