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 3671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3736 | 3744 |
| 3737 private: | 3745 private: |
| 3738 bool video_observed_; | 3746 bool video_observed_; |
| 3739 bool audio_observed_; | 3747 bool audio_observed_; |
| 3740 SequenceNumberUnwrapper unwrapper_; | 3748 SequenceNumberUnwrapper unwrapper_; |
| 3741 std::set<int64_t> received_packet_ids_; | 3749 std::set<int64_t> received_packet_ids_; |
| 3742 } test; | 3750 } test; |
| 3743 | 3751 |
| 3744 RunBaseTest(&test); | 3752 RunBaseTest(&test); |
| 3745 } | 3753 } |
| 3754 | |
| 3755 class EndToEndLogTest : public EndToEndTest { | |
| 3756 void SetUp() { paths_.clear(); } | |
| 3757 void TearDown() { | |
| 3758 for (const auto& path : paths_) { | |
| 3759 #if defined(WEBRTC_WIN) | |
| 3760 ::DeleteFile(rtc::ToUtf16(path).c_str()); | |
| 3761 #else | |
| 3762 ::unlink(path.c_str()); | |
| 3763 #endif | |
|
stefan-webrtc
2016/09/13 10:53:17
Don't we have platform independent wrappers for th
palmkvist
2016/09/13 11:59:37
Nothing that is approved. The idea is to put it in
| |
| 3764 } | |
| 3765 } | |
| 3766 | |
| 3767 public: | |
| 3768 int AddFile() { | |
| 3769 paths_.push_back(test::TempFilename(test::OutputPath(), "test_file")); | |
| 3770 return static_cast<int>(paths_.size()) - 1; | |
| 3771 } | |
| 3772 | |
| 3773 rtc::PlatformFile OpenFile(int idx) { | |
| 3774 #if defined(WEBRTC_WIN) | |
| 3775 return ::CreateFile(rtc::ToUtf16(paths_[idx]).c_str(), | |
| 3776 GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, | |
| 3777 FILE_ATTRIBUTE_NORMAL, nullptr); | |
| 3778 #else | |
| 3779 return ::open(paths_[idx].c_str(), O_RDWR); | |
| 3780 #endif | |
| 3781 } | |
| 3782 | |
| 3783 void LogSend(bool open) { | |
| 3784 if (open) { | |
| 3785 video_send_stream_->EnableEncodedFrameRecording( | |
| 3786 std::vector<rtc::PlatformFile>(1, OpenFile(AddFile())), 0); | |
| 3787 } else { | |
| 3788 video_send_stream_->DisableEncodedFrameRecording(); | |
| 3789 } | |
| 3790 } | |
| 3791 void LogReceive(bool open) { | |
| 3792 if (open) { | |
| 3793 video_receive_streams_[0]->EnableEncodedFrameRecording( | |
| 3794 OpenFile(AddFile()), 0); | |
| 3795 } else { | |
| 3796 video_receive_streams_[0]->DisableEncodedFrameRecording(); | |
| 3797 } | |
| 3798 } | |
| 3799 | |
| 3800 std::vector<std::string> paths_; | |
| 3801 }; | |
| 3802 | |
| 3803 TEST_F(EndToEndLogTest, LogsEncodedFramesWhenRequested) { | |
| 3804 static const int kNumFramesToRecord = 10; | |
| 3805 class LogEncodingObserver : public test::EndToEndTest, | |
| 3806 public EncodedFrameObserver { | |
| 3807 public: | |
| 3808 explicit LogEncodingObserver(EndToEndLogTest* fixture) | |
| 3809 : EndToEndTest(kDefaultTimeoutMs), | |
| 3810 fixture_(fixture), | |
| 3811 recorded_frames_(0) {} | |
| 3812 | |
| 3813 void PerformTest() override { | |
| 3814 fixture_->LogSend(true); | |
| 3815 fixture_->LogReceive(true); | |
| 3816 ASSERT_TRUE(Wait()) << "Timed out while waiting for frame logging."; | |
| 3817 } | |
| 3818 | |
| 3819 void ModifyVideoConfigs( | |
| 3820 VideoSendStream::Config* send_config, | |
| 3821 std::vector<VideoReceiveStream::Config>* receive_configs, | |
| 3822 VideoEncoderConfig* encoder_config) override { | |
| 3823 encoder_.reset(VideoEncoder::Create(VideoEncoder::kVp8)); | |
| 3824 decoder_.reset(VP8Decoder::Create()); | |
| 3825 | |
| 3826 send_config->post_encode_callback = this; | |
| 3827 send_config->encoder_settings.payload_name = "VP8"; | |
| 3828 send_config->encoder_settings.encoder = encoder_.get(); | |
| 3829 | |
| 3830 (*receive_configs)[0].decoders.resize(1); | |
| 3831 (*receive_configs)[0].decoders[0].payload_type = | |
| 3832 send_config->encoder_settings.payload_type; | |
| 3833 (*receive_configs)[0].decoders[0].payload_name = | |
| 3834 send_config->encoder_settings.payload_name; | |
| 3835 (*receive_configs)[0].decoders[0].decoder = decoder_.get(); | |
| 3836 } | |
| 3837 | |
| 3838 void EncodedFrameCallback(const EncodedFrame& encoded_frame) override { | |
| 3839 rtc::CritScope lock(&crit_); | |
| 3840 if (recorded_frames_++ > kNumFramesToRecord) { | |
| 3841 fixture_->LogSend(false); | |
| 3842 fixture_->LogReceive(false); | |
| 3843 rtc::File send_file(fixture_->OpenFile(0)); | |
| 3844 rtc::File receive_file(fixture_->OpenFile(1)); | |
| 3845 uint8_t out[100]; | |
| 3846 // If logging has worked correctly neither file should be empty, i.e. | |
| 3847 // we should be able to read something from them. | |
| 3848 EXPECT_LT(0u, send_file.Read(out, 100)); | |
| 3849 EXPECT_LT(0u, receive_file.Read(out, 100)); | |
| 3850 observation_complete_.Set(); | |
| 3851 } | |
| 3852 } | |
| 3853 | |
| 3854 private: | |
| 3855 EndToEndLogTest* const fixture_; | |
| 3856 std::unique_ptr<VideoEncoder> encoder_; | |
| 3857 std::unique_ptr<VideoDecoder> decoder_; | |
| 3858 rtc::CriticalSection crit_; | |
| 3859 int recorded_frames_ GUARDED_BY(crit_); | |
| 3860 } test(this); | |
| 3861 | |
| 3862 RunBaseTest(&test); | |
| 3863 } | |
| 3864 | |
| 3746 } // namespace webrtc | 3865 } // namespace webrtc |
| OLD | NEW |