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> |
11 #include <list> | 11 #include <list> |
12 #include <map> | 12 #include <map> |
13 #include <memory> | 13 #include <memory> |
14 #include <sstream> | 14 #include <sstream> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 #include "webrtc/base/checks.h" | 20 #include "webrtc/base/checks.h" |
21 #include "webrtc/base/event.h" | 21 #include "webrtc/base/event.h" |
| 22 #include "webrtc/base/file.h" |
22 #include "webrtc/base/optional.h" | 23 #include "webrtc/base/optional.h" |
23 #include "webrtc/base/rate_limiter.h" | 24 #include "webrtc/base/rate_limiter.h" |
24 #include "webrtc/call.h" | 25 #include "webrtc/call.h" |
25 #include "webrtc/call/transport_adapter.h" | 26 #include "webrtc/call/transport_adapter.h" |
26 #include "webrtc/common_video/include/frame_callback.h" | 27 #include "webrtc/common_video/include/frame_callback.h" |
27 #include "webrtc/modules/include/module_common_types.h" | 28 #include "webrtc/modules/include/module_common_types.h" |
28 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 29 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
29 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 30 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
30 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.h" | 31 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.h" |
31 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rapid_resync_request.h" | 32 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rapid_resync_request.h" |
(...skipping 3704 matching lines...) Loading... |
3736 | 3737 |
3737 private: | 3738 private: |
3738 bool video_observed_; | 3739 bool video_observed_; |
3739 bool audio_observed_; | 3740 bool audio_observed_; |
3740 SequenceNumberUnwrapper unwrapper_; | 3741 SequenceNumberUnwrapper unwrapper_; |
3741 std::set<int64_t> received_packet_ids_; | 3742 std::set<int64_t> received_packet_ids_; |
3742 } test; | 3743 } test; |
3743 | 3744 |
3744 RunBaseTest(&test); | 3745 RunBaseTest(&test); |
3745 } | 3746 } |
| 3747 |
| 3748 class EndToEndLogTest : public EndToEndTest { |
| 3749 void SetUp() { paths_.clear(); } |
| 3750 void TearDown() { |
| 3751 for (const auto& path : paths_) { |
| 3752 rtc::RemoveFile(path); |
| 3753 } |
| 3754 } |
| 3755 |
| 3756 public: |
| 3757 int AddFile() { |
| 3758 paths_.push_back(test::TempFilename(test::OutputPath(), "test_file")); |
| 3759 return static_cast<int>(paths_.size()) - 1; |
| 3760 } |
| 3761 |
| 3762 rtc::PlatformFile OpenFile(int idx) { |
| 3763 return rtc::OpenPlatformFile(paths_[idx]); |
| 3764 } |
| 3765 |
| 3766 void LogSend(bool open) { |
| 3767 if (open) { |
| 3768 video_send_stream_->EnableEncodedFrameRecording( |
| 3769 std::vector<rtc::PlatformFile>(1, OpenFile(AddFile())), 0); |
| 3770 } else { |
| 3771 video_send_stream_->DisableEncodedFrameRecording(); |
| 3772 } |
| 3773 } |
| 3774 void LogReceive(bool open) { |
| 3775 if (open) { |
| 3776 video_receive_streams_[0]->EnableEncodedFrameRecording( |
| 3777 OpenFile(AddFile()), 0); |
| 3778 } else { |
| 3779 video_receive_streams_[0]->DisableEncodedFrameRecording(); |
| 3780 } |
| 3781 } |
| 3782 |
| 3783 std::vector<std::string> paths_; |
| 3784 }; |
| 3785 |
| 3786 TEST_F(EndToEndLogTest, LogsEncodedFramesWhenRequested) { |
| 3787 static const int kNumFramesToRecord = 10; |
| 3788 class LogEncodingObserver : public test::EndToEndTest, |
| 3789 public EncodedFrameObserver { |
| 3790 public: |
| 3791 explicit LogEncodingObserver(EndToEndLogTest* fixture) |
| 3792 : EndToEndTest(kDefaultTimeoutMs), |
| 3793 fixture_(fixture), |
| 3794 recorded_frames_(0) {} |
| 3795 |
| 3796 void PerformTest() override { |
| 3797 fixture_->LogSend(true); |
| 3798 fixture_->LogReceive(true); |
| 3799 ASSERT_TRUE(Wait()) << "Timed out while waiting for frame logging."; |
| 3800 } |
| 3801 |
| 3802 void ModifyVideoConfigs( |
| 3803 VideoSendStream::Config* send_config, |
| 3804 std::vector<VideoReceiveStream::Config>* receive_configs, |
| 3805 VideoEncoderConfig* encoder_config) override { |
| 3806 encoder_.reset(VideoEncoder::Create(VideoEncoder::kVp8)); |
| 3807 decoder_.reset(VP8Decoder::Create()); |
| 3808 |
| 3809 send_config->post_encode_callback = this; |
| 3810 send_config->encoder_settings.payload_name = "VP8"; |
| 3811 send_config->encoder_settings.encoder = encoder_.get(); |
| 3812 |
| 3813 (*receive_configs)[0].decoders.resize(1); |
| 3814 (*receive_configs)[0].decoders[0].payload_type = |
| 3815 send_config->encoder_settings.payload_type; |
| 3816 (*receive_configs)[0].decoders[0].payload_name = |
| 3817 send_config->encoder_settings.payload_name; |
| 3818 (*receive_configs)[0].decoders[0].decoder = decoder_.get(); |
| 3819 } |
| 3820 |
| 3821 void EncodedFrameCallback(const EncodedFrame& encoded_frame) override { |
| 3822 rtc::CritScope lock(&crit_); |
| 3823 if (recorded_frames_++ > kNumFramesToRecord) { |
| 3824 fixture_->LogSend(false); |
| 3825 fixture_->LogReceive(false); |
| 3826 rtc::File send_file(fixture_->OpenFile(0)); |
| 3827 rtc::File receive_file(fixture_->OpenFile(1)); |
| 3828 uint8_t out[100]; |
| 3829 // If logging has worked correctly neither file should be empty, i.e. |
| 3830 // we should be able to read something from them. |
| 3831 EXPECT_LT(0u, send_file.Read(out, 100)); |
| 3832 EXPECT_LT(0u, receive_file.Read(out, 100)); |
| 3833 observation_complete_.Set(); |
| 3834 } |
| 3835 } |
| 3836 |
| 3837 private: |
| 3838 EndToEndLogTest* const fixture_; |
| 3839 std::unique_ptr<VideoEncoder> encoder_; |
| 3840 std::unique_ptr<VideoDecoder> decoder_; |
| 3841 rtc::CriticalSection crit_; |
| 3842 int recorded_frames_ GUARDED_BY(crit_); |
| 3843 } test(this); |
| 3844 |
| 3845 RunBaseTest(&test); |
| 3846 } |
| 3847 |
3746 } // namespace webrtc | 3848 } // namespace webrtc |
OLD | NEW |