| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 } | 857 } |
| 858 | 858 |
| 859 TEST_F(EndToEndTest, DecodesRetransmittedFrameByRed) { | 859 TEST_F(EndToEndTest, DecodesRetransmittedFrameByRed) { |
| 860 DecodesRetransmittedFrame(false, true); | 860 DecodesRetransmittedFrame(false, true); |
| 861 } | 861 } |
| 862 | 862 |
| 863 TEST_F(EndToEndTest, DecodesRetransmittedFrameByRedOverRtx) { | 863 TEST_F(EndToEndTest, DecodesRetransmittedFrameByRedOverRtx) { |
| 864 DecodesRetransmittedFrame(true, true); | 864 DecodesRetransmittedFrame(true, true); |
| 865 } | 865 } |
| 866 | 866 |
| 867 TEST_F(EndToEndTest, UsesFrameCallbacks) { | |
| 868 static const int kWidth = 320; | |
| 869 static const int kHeight = 240; | |
| 870 | |
| 871 class Renderer : public rtc::VideoSinkInterface<VideoFrame> { | |
| 872 public: | |
| 873 Renderer() : event_(false, false) {} | |
| 874 | |
| 875 void OnFrame(const VideoFrame& video_frame) override { | |
| 876 EXPECT_EQ(0, *video_frame.buffer(kYPlane)) | |
| 877 << "Rendered frame should have zero luma which is applied by the " | |
| 878 "pre-render callback."; | |
| 879 event_.Set(); | |
| 880 } | |
| 881 | |
| 882 bool Wait() { return event_.Wait(kDefaultTimeoutMs); } | |
| 883 rtc::Event event_; | |
| 884 } renderer; | |
| 885 | |
| 886 class TestFrameCallback : public I420FrameCallback { | |
| 887 public: | |
| 888 TestFrameCallback(int expected_luma_byte, int next_luma_byte) | |
| 889 : event_(false, false), | |
| 890 expected_luma_byte_(expected_luma_byte), | |
| 891 next_luma_byte_(next_luma_byte) {} | |
| 892 | |
| 893 bool Wait() { return event_.Wait(kDefaultTimeoutMs); } | |
| 894 | |
| 895 private: | |
| 896 virtual void FrameCallback(VideoFrame* frame) { | |
| 897 EXPECT_EQ(kWidth, frame->width()) | |
| 898 << "Width not as expected, callback done before resize?"; | |
| 899 EXPECT_EQ(kHeight, frame->height()) | |
| 900 << "Height not as expected, callback done before resize?"; | |
| 901 | |
| 902 // Previous luma specified, observed luma should be fairly close. | |
| 903 if (expected_luma_byte_ != -1) { | |
| 904 EXPECT_NEAR(expected_luma_byte_, *frame->buffer(kYPlane), 10); | |
| 905 } | |
| 906 | |
| 907 memset(frame->buffer(kYPlane), | |
| 908 next_luma_byte_, | |
| 909 frame->allocated_size(kYPlane)); | |
| 910 | |
| 911 event_.Set(); | |
| 912 } | |
| 913 | |
| 914 rtc::Event event_; | |
| 915 int expected_luma_byte_; | |
| 916 int next_luma_byte_; | |
| 917 }; | |
| 918 | |
| 919 TestFrameCallback pre_encode_callback(-1, 255); // Changes luma to 255. | |
| 920 TestFrameCallback pre_render_callback(255, 0); // Changes luma from 255 to 0. | |
| 921 | |
| 922 CreateCalls(Call::Config(), Call::Config()); | |
| 923 | |
| 924 test::DirectTransport sender_transport(sender_call_.get()); | |
| 925 test::DirectTransport receiver_transport(receiver_call_.get()); | |
| 926 sender_transport.SetReceiver(receiver_call_->Receiver()); | |
| 927 receiver_transport.SetReceiver(sender_call_->Receiver()); | |
| 928 | |
| 929 CreateSendConfig(1, 0, &sender_transport); | |
| 930 std::unique_ptr<VideoEncoder> encoder( | |
| 931 VideoEncoder::Create(VideoEncoder::kVp8)); | |
| 932 video_send_config_.encoder_settings.encoder = encoder.get(); | |
| 933 video_send_config_.encoder_settings.payload_name = "VP8"; | |
| 934 ASSERT_EQ(1u, video_encoder_config_.streams.size()) << "Test setup error."; | |
| 935 video_encoder_config_.streams[0].width = kWidth; | |
| 936 video_encoder_config_.streams[0].height = kHeight; | |
| 937 video_send_config_.pre_encode_callback = &pre_encode_callback; | |
| 938 | |
| 939 CreateMatchingReceiveConfigs(&receiver_transport); | |
| 940 video_receive_configs_[0].pre_render_callback = &pre_render_callback; | |
| 941 video_receive_configs_[0].renderer = &renderer; | |
| 942 | |
| 943 CreateVideoStreams(); | |
| 944 Start(); | |
| 945 | |
| 946 // Create frames that are smaller than the send width/height, this is done to | |
| 947 // check that the callbacks are done after processing video. | |
| 948 std::unique_ptr<test::FrameGenerator> frame_generator( | |
| 949 test::FrameGenerator::CreateChromaGenerator(kWidth / 2, kHeight / 2)); | |
| 950 video_send_stream_->Input()->IncomingCapturedFrame( | |
| 951 *frame_generator->NextFrame()); | |
| 952 | |
| 953 EXPECT_TRUE(pre_encode_callback.Wait()) | |
| 954 << "Timed out while waiting for pre-encode callback."; | |
| 955 EXPECT_TRUE(pre_render_callback.Wait()) | |
| 956 << "Timed out while waiting for pre-render callback."; | |
| 957 EXPECT_TRUE(renderer.Wait()) | |
| 958 << "Timed out while waiting for the frame to render."; | |
| 959 | |
| 960 Stop(); | |
| 961 | |
| 962 sender_transport.StopSending(); | |
| 963 receiver_transport.StopSending(); | |
| 964 | |
| 965 DestroyStreams(); | |
| 966 } | |
| 967 | |
| 968 void EndToEndTest::ReceivesPliAndRecovers(int rtp_history_ms) { | 867 void EndToEndTest::ReceivesPliAndRecovers(int rtp_history_ms) { |
| 969 static const int kPacketsToDrop = 1; | 868 static const int kPacketsToDrop = 1; |
| 970 | 869 |
| 971 class PliObserver : public test::EndToEndTest, | 870 class PliObserver : public test::EndToEndTest, |
| 972 public rtc::VideoSinkInterface<VideoFrame> { | 871 public rtc::VideoSinkInterface<VideoFrame> { |
| 973 public: | 872 public: |
| 974 explicit PliObserver(int rtp_history_ms) | 873 explicit PliObserver(int rtp_history_ms) |
| 975 : EndToEndTest(kLongTimeoutMs), | 874 : EndToEndTest(kLongTimeoutMs), |
| 976 rtp_history_ms_(rtp_history_ms), | 875 rtp_history_ms_(rtp_history_ms), |
| 977 nack_enabled_(rtp_history_ms > 0), | 876 nack_enabled_(rtp_history_ms > 0), |
| (...skipping 1588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2566 VideoSendStream* send_stream_; | 2465 VideoSendStream* send_stream_; |
| 2567 uint32_t bitrate_kbps_ GUARDED_BY(crit_); | 2466 uint32_t bitrate_kbps_ GUARDED_BY(crit_); |
| 2568 } test; | 2467 } test; |
| 2569 | 2468 |
| 2570 RunBaseTest(&test); | 2469 RunBaseTest(&test); |
| 2571 } | 2470 } |
| 2572 | 2471 |
| 2573 TEST_F(EndToEndTest, GetStats) { | 2472 TEST_F(EndToEndTest, GetStats) { |
| 2574 static const int kStartBitrateBps = 3000000; | 2473 static const int kStartBitrateBps = 3000000; |
| 2575 static const int kExpectedRenderDelayMs = 20; | 2474 static const int kExpectedRenderDelayMs = 20; |
| 2576 class StatsObserver : public test::EndToEndTest, public I420FrameCallback { | 2475 class StatsObserver : public test::EndToEndTest, |
| 2476 public rtc::VideoSinkInterface<VideoFrame> { |
| 2577 public: | 2477 public: |
| 2578 StatsObserver() | 2478 StatsObserver() |
| 2579 : EndToEndTest(kLongTimeoutMs), | 2479 : EndToEndTest(kLongTimeoutMs), |
| 2580 encoder_(Clock::GetRealTimeClock(), 10), | 2480 encoder_(Clock::GetRealTimeClock(), 10), |
| 2581 send_stream_(nullptr), | 2481 send_stream_(nullptr), |
| 2582 expected_send_ssrcs_(), | 2482 expected_send_ssrcs_(), |
| 2583 check_stats_event_(false, false) {} | 2483 check_stats_event_(false, false) {} |
| 2584 | 2484 |
| 2585 private: | 2485 private: |
| 2586 Action OnSendRtp(const uint8_t* packet, size_t length) override { | 2486 Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 2587 check_stats_event_.Set(); | 2487 check_stats_event_.Set(); |
| 2588 return SEND_PACKET; | 2488 return SEND_PACKET; |
| 2589 } | 2489 } |
| 2590 | 2490 |
| 2591 Action OnSendRtcp(const uint8_t* packet, size_t length) override { | 2491 Action OnSendRtcp(const uint8_t* packet, size_t length) override { |
| 2592 check_stats_event_.Set(); | 2492 check_stats_event_.Set(); |
| 2593 return SEND_PACKET; | 2493 return SEND_PACKET; |
| 2594 } | 2494 } |
| 2595 | 2495 |
| 2596 Action OnReceiveRtp(const uint8_t* packet, size_t length) override { | 2496 Action OnReceiveRtp(const uint8_t* packet, size_t length) override { |
| 2597 check_stats_event_.Set(); | 2497 check_stats_event_.Set(); |
| 2598 return SEND_PACKET; | 2498 return SEND_PACKET; |
| 2599 } | 2499 } |
| 2600 | 2500 |
| 2601 Action OnReceiveRtcp(const uint8_t* packet, size_t length) override { | 2501 Action OnReceiveRtcp(const uint8_t* packet, size_t length) override { |
| 2602 check_stats_event_.Set(); | 2502 check_stats_event_.Set(); |
| 2603 return SEND_PACKET; | 2503 return SEND_PACKET; |
| 2604 } | 2504 } |
| 2605 | 2505 |
| 2606 void FrameCallback(VideoFrame* video_frame) override { | 2506 void OnFrame(const VideoFrame& video_frame) override { |
| 2607 // Ensure that we have at least 5ms send side delay. | 2507 // Ensure that we have at least 5ms send side delay. |
| 2608 int64_t render_time = video_frame->render_time_ms(); | 2508 SleepMs(5); |
| 2609 if (render_time > 0) | |
| 2610 video_frame->set_render_time_ms(render_time - 5); | |
| 2611 } | 2509 } |
| 2612 | 2510 |
| 2613 bool CheckReceiveStats() { | 2511 bool CheckReceiveStats() { |
| 2614 for (size_t i = 0; i < receive_streams_.size(); ++i) { | 2512 for (size_t i = 0; i < receive_streams_.size(); ++i) { |
| 2615 VideoReceiveStream::Stats stats = receive_streams_[i]->GetStats(); | 2513 VideoReceiveStream::Stats stats = receive_streams_[i]->GetStats(); |
| 2616 EXPECT_EQ(expected_receive_ssrcs_[i], stats.ssrc); | 2514 EXPECT_EQ(expected_receive_ssrcs_[i], stats.ssrc); |
| 2617 | 2515 |
| 2618 // Make sure all fields have been populated. | 2516 // Make sure all fields have been populated. |
| 2619 // TODO(pbos): Use CompoundKey if/when we ever know that all stats are | 2517 // TODO(pbos): Use CompoundKey if/when we ever know that all stats are |
| 2620 // always filled for all receivers. | 2518 // always filled for all receivers. |
| (...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3608 private: | 3506 private: |
| 3609 bool video_observed_; | 3507 bool video_observed_; |
| 3610 bool audio_observed_; | 3508 bool audio_observed_; |
| 3611 SequenceNumberUnwrapper unwrapper_; | 3509 SequenceNumberUnwrapper unwrapper_; |
| 3612 std::set<int64_t> received_packet_ids_; | 3510 std::set<int64_t> received_packet_ids_; |
| 3613 } test; | 3511 } test; |
| 3614 | 3512 |
| 3615 RunBaseTest(&test); | 3513 RunBaseTest(&test); |
| 3616 } | 3514 } |
| 3617 } // namespace webrtc | 3515 } // namespace webrtc |
| OLD | NEW |