Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 45 #include "webrtc/test/fake_encoder.h" | 46 #include "webrtc/test/fake_encoder.h" |
| 46 #include "webrtc/test/frame_generator.h" | 47 #include "webrtc/test/frame_generator.h" |
| 47 #include "webrtc/test/frame_generator_capturer.h" | 48 #include "webrtc/test/frame_generator_capturer.h" |
| 48 #include "webrtc/test/null_transport.h" | 49 #include "webrtc/test/null_transport.h" |
| 49 #include "webrtc/test/rtcp_packet_parser.h" | 50 #include "webrtc/test/rtcp_packet_parser.h" |
| 50 #include "webrtc/test/rtp_rtcp_observer.h" | 51 #include "webrtc/test/rtp_rtcp_observer.h" |
| 51 #include "webrtc/test/testsupport/fileutils.h" | 52 #include "webrtc/test/testsupport/fileutils.h" |
| 52 #include "webrtc/test/testsupport/perf_test.h" | 53 #include "webrtc/test/testsupport/perf_test.h" |
| 53 #include "webrtc/video_encoder.h" | 54 #include "webrtc/video_encoder.h" |
| 54 | 55 |
| 56 #if defined(WEBRTC_WIN) | |
| 57 #include "webrtc/base/win32.h" | |
| 58 #else | |
| 59 #include <fcntl.h> | |
| 60 #include <unistd.h> | |
| 61 #endif | |
| 62 | |
| 55 namespace webrtc { | 63 namespace webrtc { |
| 56 | 64 |
| 57 static const int kSilenceTimeoutMs = 2000; | 65 static const int kSilenceTimeoutMs = 2000; |
| 58 | 66 |
| 59 class EndToEndTest : public test::CallTest { | 67 class EndToEndTest : public test::CallTest { |
| 60 public: | 68 public: |
| 61 EndToEndTest() {} | 69 EndToEndTest() {} |
| 62 | 70 |
| 63 virtual ~EndToEndTest() { | 71 virtual ~EndToEndTest() { |
| 64 EXPECT_EQ(nullptr, video_send_stream_); | 72 EXPECT_EQ(nullptr, video_send_stream_); |
| (...skipping 3668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3733 | 3741 |
| 3734 private: | 3742 private: |
| 3735 bool video_observed_; | 3743 bool video_observed_; |
| 3736 bool audio_observed_; | 3744 bool audio_observed_; |
| 3737 SequenceNumberUnwrapper unwrapper_; | 3745 SequenceNumberUnwrapper unwrapper_; |
| 3738 std::set<int64_t> received_packet_ids_; | 3746 std::set<int64_t> received_packet_ids_; |
| 3739 } test; | 3747 } test; |
| 3740 | 3748 |
| 3741 RunBaseTest(&test); | 3749 RunBaseTest(&test); |
| 3742 } | 3750 } |
| 3751 | |
| 3752 class EndToEndLogTest : public EndToEndTest { | |
| 3753 void SetUp() { paths_.clear(); } | |
| 3754 void TearDown() { | |
| 3755 for (const auto& path : paths_) { | |
| 3756 #if defined(WEBRTC_WIN) | |
| 3757 ::DeleteFile(rtc::ToUtf16(path).c_str()); | |
| 3758 #else | |
| 3759 ::unlink(path.c_str()); | |
| 3760 #endif | |
|
sprang_webrtc
2016/09/04 14:48:47
Can we add this as a static delete method to File
| |
| 3761 } | |
| 3762 } | |
| 3763 | |
| 3764 public: | |
| 3765 int AddFile() { | |
| 3766 paths_.push_back(test::TempFilename(test::OutputPath(), "test_file")); | |
| 3767 return paths_.size() - 1; | |
| 3768 } | |
| 3769 | |
| 3770 rtc::PlatformFile OpenFile(int idx) { | |
| 3771 #if defined(WEBRTC_WIN) | |
| 3772 return ::CreateFile(rtc::ToUtf16(paths_[idx]).c_str(), | |
| 3773 GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, | |
| 3774 FILE_ATTRIBUTE_NORMAL, nullptr); | |
| 3775 #else | |
| 3776 return ::open(paths_[idx].c_str(), O_RDWR); | |
| 3777 #endif | |
|
sprang_webrtc
2016/09/04 14:48:47
Maybe even add this to File itself?
palmkvist
2016/09/05 11:57:37
Thinking about it, platform_file seems like a more
| |
| 3778 } | |
| 3779 | |
| 3780 void LogSend(bool open) { | |
| 3781 if (open) | |
| 3782 video_send_stream_->SetLogFiles(OpenFile(AddFile())); | |
| 3783 else | |
| 3784 video_send_stream_->SetLogFiles(); | |
|
sprang_webrtc
2016/09/04 14:48:47
use brackets for if/else
| |
| 3785 } | |
| 3786 void LogReceive(bool open) { | |
| 3787 if (open) | |
| 3788 video_receive_streams_[0]->SetLogFile(OpenFile(AddFile())); | |
| 3789 else | |
| 3790 video_receive_streams_[0]->SetLogFile(); | |
| 3791 } | |
| 3792 | |
| 3793 std::vector<std::string> paths_; | |
| 3794 }; | |
| 3795 | |
| 3796 TEST_F(EndToEndLogTest, LogsEncodedFramesWhenRequested) { | |
| 3797 static const int kNumFramesToRecord = 10; | |
| 3798 class LogEncodingObserver : public test::EndToEndTest, | |
| 3799 public EncodedFrameObserver { | |
| 3800 public: | |
| 3801 explicit LogEncodingObserver(EndToEndLogTest* fixture) | |
| 3802 : EndToEndTest(kDefaultTimeoutMs), fixture_(fixture) {} | |
| 3803 | |
| 3804 void PerformTest() override { | |
| 3805 fixture_->LogSend(true); | |
| 3806 fixture_->LogReceive(true); | |
| 3807 ASSERT_TRUE(Wait()) << "Timed out while waiting for frame logging."; | |
| 3808 } | |
| 3809 | |
| 3810 void ModifyVideoConfigs( | |
| 3811 VideoSendStream::Config* send_config, | |
| 3812 std::vector<VideoReceiveStream::Config>* receive_configs, | |
| 3813 VideoEncoderConfig* encoder_config) override { | |
| 3814 encoder_.reset(VideoEncoder::Create(VideoEncoder::kVp8)); | |
| 3815 decoder_.reset(VP8Decoder::Create()); | |
| 3816 | |
| 3817 send_config->post_encode_callback = this; | |
| 3818 send_config->encoder_settings.payload_name = "VP8"; | |
| 3819 send_config->encoder_settings.encoder = encoder_.get(); | |
| 3820 | |
| 3821 (*receive_configs)[0].decoders.resize(1); | |
| 3822 (*receive_configs)[0].decoders[0].payload_type = | |
| 3823 send_config->encoder_settings.payload_type; | |
| 3824 (*receive_configs)[0].decoders[0].payload_name = | |
| 3825 send_config->encoder_settings.payload_name; | |
| 3826 (*receive_configs)[0].decoders[0].decoder = decoder_.get(); | |
| 3827 } | |
| 3828 | |
| 3829 void EncodedFrameCallback(const EncodedFrame& encoded_frame) override { | |
| 3830 rtc::CritScope lock(&crit_); | |
| 3831 if (recorded_frames_++ > kNumFramesToRecord) { | |
| 3832 fixture_->LogSend(false); | |
| 3833 fixture_->LogReceive(false); | |
| 3834 rtc::File send_file(fixture_->OpenFile(0)); | |
| 3835 rtc::File receive_file(fixture_->OpenFile(1)); | |
| 3836 uint8_t out[100]; | |
| 3837 EXPECT_LT(0u, receive_file.Read(out, 100)); | |
|
sprang_webrtc
2016/09/04 14:48:47
Please add some comments about the intentions here
| |
| 3838 observation_complete_.Set(); | |
| 3839 } | |
| 3840 } | |
| 3841 | |
| 3842 private: | |
| 3843 EndToEndLogTest* fixture_; | |
|
sprang_webrtc
2016/09/04 14:48:48
EndToEndLogTest* const fixture_;
| |
| 3844 std::unique_ptr<VideoEncoder> encoder_; | |
| 3845 std::unique_ptr<VideoDecoder> decoder_; | |
| 3846 rtc::CriticalSection crit_; | |
| 3847 int recorded_frames_ GUARDED_BY(crit_) = 0; | |
|
sprang_webrtc
2016/09/04 14:48:47
prefer setting values in the initializer list
| |
| 3848 } test(this); | |
| 3849 | |
| 3850 RunBaseTest(&test); | |
| 3851 } | |
| 3852 | |
| 3743 } // namespace webrtc | 3853 } // namespace webrtc |
| OLD | NEW |