Preparation for deleting EnableFrameRecordning, and also a step towards landing of the new VideoStreamDecoder. Bug: webrtc:9106 Change-Id: I50964ee458b08a702ec69b82a62e4995c57cee82 Reviewed-on: https://webrtc-review.googlesource.com/97660 Commit-Queue: Niels Moller <nisse@webrtc.org> Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> Reviewed-by: Anders Carlsson <andersc@webrtc.org> Reviewed-by: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Erik Språng <sprang@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24861}
107 lines
3.5 KiB
C++
107 lines
3.5 KiB
C++
/*
|
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "media/engine/internaldecoderfactory.h"
|
|
#include "modules/video_coding/codecs/vp8/include/vp8.h"
|
|
#include "rtc_base/file.h"
|
|
#include "test/call_test.h"
|
|
#include "test/function_video_encoder_factory.h"
|
|
#include "test/testsupport/fileutils.h"
|
|
|
|
namespace webrtc {
|
|
|
|
class LogEndToEndTest : public test::CallTest {
|
|
void SetUp() { paths_.clear(); }
|
|
void TearDown() {
|
|
for (const auto& path : paths_) {
|
|
rtc::RemoveFile(path);
|
|
}
|
|
}
|
|
|
|
public:
|
|
int AddFile() {
|
|
paths_.push_back(test::TempFilename(test::OutputPath(), "test_file"));
|
|
return static_cast<int>(paths_.size()) - 1;
|
|
}
|
|
|
|
rtc::PlatformFile OpenFile(int idx) {
|
|
return rtc::OpenPlatformFile(paths_[idx]);
|
|
}
|
|
|
|
void LogReceive(bool open) {
|
|
if (open) {
|
|
video_receive_streams_[0]->EnableEncodedFrameRecording(
|
|
OpenFile(AddFile()), 0);
|
|
} else {
|
|
video_receive_streams_[0]->DisableEncodedFrameRecording();
|
|
}
|
|
}
|
|
|
|
std::vector<std::string> paths_;
|
|
};
|
|
|
|
TEST_F(LogEndToEndTest, LogsEncodedFramesWhenRequested) {
|
|
static const int kNumFramesToRecord = 10;
|
|
class LogEncodingObserver : public test::EndToEndTest,
|
|
public EncodedFrameObserver {
|
|
public:
|
|
explicit LogEncodingObserver(LogEndToEndTest* fixture)
|
|
: EndToEndTest(kDefaultTimeoutMs),
|
|
fixture_(fixture),
|
|
encoder_factory_([]() { return VP8Encoder::Create(); }),
|
|
recorded_frames_(0) {}
|
|
|
|
void PerformTest() override {
|
|
fixture_->LogReceive(true);
|
|
ASSERT_TRUE(Wait()) << "Timed out while waiting for frame logging.";
|
|
}
|
|
|
|
void ModifyVideoConfigs(
|
|
VideoSendStream::Config* send_config,
|
|
std::vector<VideoReceiveStream::Config>* receive_configs,
|
|
VideoEncoderConfig* encoder_config) override {
|
|
send_config->post_encode_callback = this;
|
|
send_config->rtp.payload_name = "VP8";
|
|
send_config->encoder_settings.encoder_factory = &encoder_factory_;
|
|
encoder_config->codec_type = kVideoCodecVP8;
|
|
|
|
(*receive_configs)[0].decoders.resize(1);
|
|
(*receive_configs)[0].decoders[0].payload_type =
|
|
send_config->rtp.payload_type;
|
|
(*receive_configs)[0].decoders[0].video_format =
|
|
SdpVideoFormat(send_config->rtp.payload_name);
|
|
(*receive_configs)[0].decoders[0].decoder_factory = &decoder_factory_;
|
|
}
|
|
|
|
void EncodedFrameCallback(const EncodedFrame& encoded_frame) override {
|
|
rtc::CritScope lock(&crit_);
|
|
if (recorded_frames_++ > kNumFramesToRecord) {
|
|
fixture_->LogReceive(false);
|
|
rtc::File receive_file(fixture_->OpenFile(0));
|
|
uint8_t out[100];
|
|
// If logging has worked correctly file shouldn't be empty, i.e.
|
|
// we should be able to read something from them.
|
|
EXPECT_LT(0u, receive_file.Read(out, 100));
|
|
observation_complete_.Set();
|
|
}
|
|
}
|
|
|
|
private:
|
|
LogEndToEndTest* const fixture_;
|
|
test::FunctionVideoEncoderFactory encoder_factory_;
|
|
InternalDecoderFactory decoder_factory_;
|
|
rtc::CriticalSection crit_;
|
|
int recorded_frames_ RTC_GUARDED_BY(crit_);
|
|
} test(this);
|
|
|
|
RunBaseTest(&test);
|
|
}
|
|
} // namespace webrtc
|