This is a reland of bc900cb1d1810fcf678fe41cf1e3966daa39c88c Original change's description: > Move rtp-specific config out of EncoderSettings. > > In VideoSendStream::Config, move payload_name and payload_type from > EncoderSettings to Rtp. > > EncoderSettings now contains configuration for VideoStreamEncoder only, > and should perhaps be renamed in a follow up cl. It's no longer > passed as an argument to VideoCodecInitializer::SetupCodec. > > The latter then needs a different way to know the codec type, > which is provided by a new codec_type member in VideoEncoderConfig. > > Bug: webrtc:8830 > Change-Id: Ifcc691aef1ee6a95e43c0452c5e630d92a511cd6 > Reviewed-on: https://webrtc-review.googlesource.com/62062 > Commit-Queue: Niels Moller <nisse@webrtc.org> > Reviewed-by: Magnus Jedvert <magjed@webrtc.org> > Reviewed-by: Stefan Holmer <stefan@webrtc.org> > Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#22532} Bug: webrtc:8830 Change-Id: If88ef7d57cdaa4fae3c7b2a97ea5a6e1b833e019 Reviewed-on: https://webrtc-review.googlesource.com/63721 Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> Reviewed-by: Stefan Holmer <stefan@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22595}
118 lines
3.7 KiB
C++
118 lines
3.7 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 "modules/video_coding/codecs/vp8/include/vp8.h"
|
|
#include "rtc_base/file.h"
|
|
#include "test/call_test.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 LogSend(bool open) {
|
|
if (open) {
|
|
video_send_stream_->EnableEncodedFrameRecording(
|
|
std::vector<rtc::PlatformFile>(1, OpenFile(AddFile())), 0);
|
|
} else {
|
|
video_send_stream_->DisableEncodedFrameRecording();
|
|
}
|
|
}
|
|
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),
|
|
recorded_frames_(0) {}
|
|
|
|
void PerformTest() override {
|
|
fixture_->LogSend(true);
|
|
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 {
|
|
encoder_ = VP8Encoder::Create();
|
|
decoder_ = VP8Decoder::Create();
|
|
|
|
send_config->post_encode_callback = this;
|
|
send_config->rtp.payload_name = "VP8";
|
|
send_config->encoder_settings.encoder = encoder_.get();
|
|
|
|
(*receive_configs)[0].decoders.resize(1);
|
|
(*receive_configs)[0].decoders[0].payload_type =
|
|
send_config->rtp.payload_type;
|
|
(*receive_configs)[0].decoders[0].payload_name =
|
|
send_config->rtp.payload_name;
|
|
(*receive_configs)[0].decoders[0].decoder = decoder_.get();
|
|
}
|
|
|
|
void EncodedFrameCallback(const EncodedFrame& encoded_frame) override {
|
|
rtc::CritScope lock(&crit_);
|
|
if (recorded_frames_++ > kNumFramesToRecord) {
|
|
fixture_->LogSend(false);
|
|
fixture_->LogReceive(false);
|
|
rtc::File send_file(fixture_->OpenFile(0));
|
|
rtc::File receive_file(fixture_->OpenFile(1));
|
|
uint8_t out[100];
|
|
// If logging has worked correctly neither file should be empty, i.e.
|
|
// we should be able to read something from them.
|
|
EXPECT_LT(0u, send_file.Read(out, 100));
|
|
EXPECT_LT(0u, receive_file.Read(out, 100));
|
|
observation_complete_.Set();
|
|
}
|
|
}
|
|
|
|
private:
|
|
LogEndToEndTest* const fixture_;
|
|
std::unique_ptr<VideoEncoder> encoder_;
|
|
std::unique_ptr<VideoDecoder> decoder_;
|
|
rtc::CriticalSection crit_;
|
|
int recorded_frames_ RTC_GUARDED_BY(crit_);
|
|
} test(this);
|
|
|
|
RunBaseTest(&test);
|
|
}
|
|
} // namespace webrtc
|