webrtc_m130/modules/video_coding/codecs/test/video_codec_unittest.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

171 lines
6.0 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2017 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 <utility>
#include "api/video_codecs/video_encoder.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "modules/video_coding/codecs/test/video_codec_unittest.h"
#include "modules/video_coding/include/video_error_codes.h"
#include "test/video_codec_settings.h"
static const int kEncodeTimeoutMs = 100;
static const int kDecodeTimeoutMs = 25;
// Set bitrate to get higher quality.
static const int kStartBitrate = 300;
static const int kMaxBitrate = 4000;
static const int kWidth = 176; // Width of the input image.
static const int kHeight = 144; // Height of the input image.
static const int kMaxFramerate = 30; // Arbitrary value.
namespace webrtc {
namespace {
const VideoEncoder::Capabilities kCapabilities(false);
}
EncodedImageCallback::Result
VideoCodecUnitTest::FakeEncodeCompleteCallback::OnEncodedImage(
const EncodedImage& frame,
const CodecSpecificInfo* codec_specific_info,
const RTPFragmentationHeader* fragmentation) {
rtc::CritScope lock(&test_->encoded_frame_section_);
Reland "Add stereo codec header and pass it through RTP" This is a reland of 20f2133d5dbd1591b89425b24db3b1e09fbcf0b1 Original change's description: > Add stereo codec header and pass it through RTP > > - Defines CodecSpecificInfoStereo that carries stereo specific header info from > encoded image. > - Defines RTPVideoHeaderStereo that carries the above info to packetizer, > see module_common_types.h. > - Adds an RTPPacketizer and RTPDepacketizer that supports passing specific stereo > header. > - Uses new data containers in StereoAdapter classes. > > This CL is the step 3 for adding alpha channel support over the wire in webrtc. > See https://webrtc-review.googlesource.com/c/src/+/7800 for the experimental > CL that gives an idea about how it will come together. > Design Doc: https://goo.gl/sFeSUT > > Bug: webrtc:7671 > Change-Id: Ia932568fdd7065ba104afd2bc0ecf25a765748ab > Reviewed-on: https://webrtc-review.googlesource.com/22900 > Reviewed-by: Emircan Uysaler <emircan@webrtc.org> > Reviewed-by: Erik Språng <sprang@webrtc.org> > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > Reviewed-by: Niklas Enbom <niklas.enbom@webrtc.org> > Commit-Queue: Emircan Uysaler <emircan@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#20920} TBR=danilchap@webrtc.org, sprang@webrtc.org, niklas.enbom@webrtc.org Bug: webrtc:7671 Change-Id: If8f0c7e6e3a2a704f19161f0e8bf1880906e7fe0 Reviewed-on: https://webrtc-review.googlesource.com/27160 Reviewed-by: Emircan Uysaler <emircan@webrtc.org> Commit-Queue: Emircan Uysaler <emircan@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20946}
2017-11-28 09:45:25 -08:00
test_->encoded_frames_.push_back(frame);
RTC_DCHECK(codec_specific_info);
Reland "Add stereo codec header and pass it through RTP" This is a reland of 20f2133d5dbd1591b89425b24db3b1e09fbcf0b1 Original change's description: > Add stereo codec header and pass it through RTP > > - Defines CodecSpecificInfoStereo that carries stereo specific header info from > encoded image. > - Defines RTPVideoHeaderStereo that carries the above info to packetizer, > see module_common_types.h. > - Adds an RTPPacketizer and RTPDepacketizer that supports passing specific stereo > header. > - Uses new data containers in StereoAdapter classes. > > This CL is the step 3 for adding alpha channel support over the wire in webrtc. > See https://webrtc-review.googlesource.com/c/src/+/7800 for the experimental > CL that gives an idea about how it will come together. > Design Doc: https://goo.gl/sFeSUT > > Bug: webrtc:7671 > Change-Id: Ia932568fdd7065ba104afd2bc0ecf25a765748ab > Reviewed-on: https://webrtc-review.googlesource.com/22900 > Reviewed-by: Emircan Uysaler <emircan@webrtc.org> > Reviewed-by: Erik Språng <sprang@webrtc.org> > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > Reviewed-by: Niklas Enbom <niklas.enbom@webrtc.org> > Commit-Queue: Emircan Uysaler <emircan@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#20920} TBR=danilchap@webrtc.org, sprang@webrtc.org, niklas.enbom@webrtc.org Bug: webrtc:7671 Change-Id: If8f0c7e6e3a2a704f19161f0e8bf1880906e7fe0 Reviewed-on: https://webrtc-review.googlesource.com/27160 Reviewed-by: Emircan Uysaler <emircan@webrtc.org> Commit-Queue: Emircan Uysaler <emircan@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20946}
2017-11-28 09:45:25 -08:00
test_->codec_specific_infos_.push_back(*codec_specific_info);
if (!test_->wait_for_encoded_frames_threshold_) {
test_->encoded_frame_event_.Set();
return Result(Result::OK);
}
if (test_->encoded_frames_.size() ==
test_->wait_for_encoded_frames_threshold_) {
test_->wait_for_encoded_frames_threshold_ = 1;
test_->encoded_frame_event_.Set();
}
return Result(Result::OK);
}
void VideoCodecUnitTest::FakeDecodeCompleteCallback::Decoded(
VideoFrame& frame,
absl::optional<int32_t> decode_time_ms,
absl::optional<uint8_t> qp) {
rtc::CritScope lock(&test_->decoded_frame_section_);
test_->decoded_frame_.emplace(frame);
test_->decoded_qp_ = qp;
test_->decoded_frame_event_.Set();
}
void VideoCodecUnitTest::SetUp() {
webrtc::test::CodecSettings(kVideoCodecVP8, &codec_settings_);
codec_settings_.startBitrate = kStartBitrate;
codec_settings_.maxBitrate = kMaxBitrate;
codec_settings_.maxFramerate = kMaxFramerate;
codec_settings_.width = kWidth;
codec_settings_.height = kHeight;
ModifyCodecSettings(&codec_settings_);
input_frame_generator_ = test::FrameGenerator::CreateSquareGenerator(
codec_settings_.width, codec_settings_.height,
test::FrameGenerator::OutputType::I420, absl::optional<int>());
Reland "Update internal SW codecs to return unique_ptrs" This reverts commit 34c8e6bce8af0c31f2b0b31d691a6a931fa3cb7b. Reason for revert: Fix Android compilation Original change's description: > Revert "Update internal SW codecs to return unique_ptrs" > > This reverts commit 4fe6adc06a8524ac25f85260bfe392eb31dae6b4. > > Reason for revert: Breaks android compile. > > Original change's description: > > Update internal SW codecs to return unique_ptrs > > > > TBR=stefan@webrtc.org > > > > Bug: webrtc:7925 > > Change-Id: I84239b071a2608d928f09b06809090eec5eafb14 > > Reviewed-on: https://webrtc-review.googlesource.com/21165 > > Commit-Queue: Magnus Jedvert <magjed@webrtc.org> > > Reviewed-by: Erik Språng <sprang@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#20650} > > TBR=magjed@webrtc.org,sprang@webrtc.org,stefan@webrtc.org > > Change-Id: If33c3a0ee0dfce63d105558a2897a472f0633306 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:7925 > Reviewed-on: https://webrtc-review.googlesource.com/22540 > Reviewed-by: Magnus Jedvert <magjed@webrtc.org> > Commit-Queue: Magnus Jedvert <magjed@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#20652} TBR=magjed@webrtc.org,sprang@webrtc.org,stefan@webrtc.org Change-Id: Ic8551af4687e927c9b605060155abdd5bc6208b2 Bug: webrtc:7925 Reviewed-on: https://webrtc-review.googlesource.com/22541 Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20655}
2017-11-13 14:10:02 +01:00
encoder_ = CreateEncoder();
decoder_ = CreateDecoder();
encoder_->RegisterEncodeCompleteCallback(&encode_complete_callback_);
decoder_->RegisterDecodeCompleteCallback(&decode_complete_callback_);
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->InitEncode(
&codec_settings_,
VideoEncoder::Settings(kCapabilities, 1 /* number of cores */,
0 /* max payload size (unused) */)));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
decoder_->InitDecode(&codec_settings_, 1 /* number of cores */));
}
void VideoCodecUnitTest::ModifyCodecSettings(VideoCodec* codec_settings) {}
VideoFrame* VideoCodecUnitTest::NextInputFrame() {
VideoFrame* input_frame = input_frame_generator_->NextFrame();
const uint32_t timestamp =
last_input_frame_timestamp_ +
kVideoPayloadTypeFrequency / codec_settings_.maxFramerate;
input_frame->set_timestamp(timestamp);
last_input_frame_timestamp_ = timestamp;
return input_frame;
}
bool VideoCodecUnitTest::WaitForEncodedFrame(
EncodedImage* frame,
CodecSpecificInfo* codec_specific_info) {
Reland "Add stereo codec header and pass it through RTP" This is a reland of 20f2133d5dbd1591b89425b24db3b1e09fbcf0b1 Original change's description: > Add stereo codec header and pass it through RTP > > - Defines CodecSpecificInfoStereo that carries stereo specific header info from > encoded image. > - Defines RTPVideoHeaderStereo that carries the above info to packetizer, > see module_common_types.h. > - Adds an RTPPacketizer and RTPDepacketizer that supports passing specific stereo > header. > - Uses new data containers in StereoAdapter classes. > > This CL is the step 3 for adding alpha channel support over the wire in webrtc. > See https://webrtc-review.googlesource.com/c/src/+/7800 for the experimental > CL that gives an idea about how it will come together. > Design Doc: https://goo.gl/sFeSUT > > Bug: webrtc:7671 > Change-Id: Ia932568fdd7065ba104afd2bc0ecf25a765748ab > Reviewed-on: https://webrtc-review.googlesource.com/22900 > Reviewed-by: Emircan Uysaler <emircan@webrtc.org> > Reviewed-by: Erik Språng <sprang@webrtc.org> > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > Reviewed-by: Niklas Enbom <niklas.enbom@webrtc.org> > Commit-Queue: Emircan Uysaler <emircan@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#20920} TBR=danilchap@webrtc.org, sprang@webrtc.org, niklas.enbom@webrtc.org Bug: webrtc:7671 Change-Id: If8f0c7e6e3a2a704f19161f0e8bf1880906e7fe0 Reviewed-on: https://webrtc-review.googlesource.com/27160 Reviewed-by: Emircan Uysaler <emircan@webrtc.org> Commit-Queue: Emircan Uysaler <emircan@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20946}
2017-11-28 09:45:25 -08:00
std::vector<EncodedImage> frames;
std::vector<CodecSpecificInfo> codec_specific_infos;
if (!WaitForEncodedFrames(&frames, &codec_specific_infos))
return false;
EXPECT_EQ(frames.size(), static_cast<size_t>(1));
EXPECT_EQ(frames.size(), codec_specific_infos.size());
*frame = frames[0];
*codec_specific_info = codec_specific_infos[0];
return true;
}
void VideoCodecUnitTest::SetWaitForEncodedFramesThreshold(size_t num_frames) {
Reland "Add stereo codec header and pass it through RTP" This is a reland of 20f2133d5dbd1591b89425b24db3b1e09fbcf0b1 Original change's description: > Add stereo codec header and pass it through RTP > > - Defines CodecSpecificInfoStereo that carries stereo specific header info from > encoded image. > - Defines RTPVideoHeaderStereo that carries the above info to packetizer, > see module_common_types.h. > - Adds an RTPPacketizer and RTPDepacketizer that supports passing specific stereo > header. > - Uses new data containers in StereoAdapter classes. > > This CL is the step 3 for adding alpha channel support over the wire in webrtc. > See https://webrtc-review.googlesource.com/c/src/+/7800 for the experimental > CL that gives an idea about how it will come together. > Design Doc: https://goo.gl/sFeSUT > > Bug: webrtc:7671 > Change-Id: Ia932568fdd7065ba104afd2bc0ecf25a765748ab > Reviewed-on: https://webrtc-review.googlesource.com/22900 > Reviewed-by: Emircan Uysaler <emircan@webrtc.org> > Reviewed-by: Erik Språng <sprang@webrtc.org> > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > Reviewed-by: Niklas Enbom <niklas.enbom@webrtc.org> > Commit-Queue: Emircan Uysaler <emircan@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#20920} TBR=danilchap@webrtc.org, sprang@webrtc.org, niklas.enbom@webrtc.org Bug: webrtc:7671 Change-Id: If8f0c7e6e3a2a704f19161f0e8bf1880906e7fe0 Reviewed-on: https://webrtc-review.googlesource.com/27160 Reviewed-by: Emircan Uysaler <emircan@webrtc.org> Commit-Queue: Emircan Uysaler <emircan@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20946}
2017-11-28 09:45:25 -08:00
rtc::CritScope lock(&encoded_frame_section_);
wait_for_encoded_frames_threshold_ = num_frames;
}
bool VideoCodecUnitTest::WaitForEncodedFrames(
Reland "Add stereo codec header and pass it through RTP" This is a reland of 20f2133d5dbd1591b89425b24db3b1e09fbcf0b1 Original change's description: > Add stereo codec header and pass it through RTP > > - Defines CodecSpecificInfoStereo that carries stereo specific header info from > encoded image. > - Defines RTPVideoHeaderStereo that carries the above info to packetizer, > see module_common_types.h. > - Adds an RTPPacketizer and RTPDepacketizer that supports passing specific stereo > header. > - Uses new data containers in StereoAdapter classes. > > This CL is the step 3 for adding alpha channel support over the wire in webrtc. > See https://webrtc-review.googlesource.com/c/src/+/7800 for the experimental > CL that gives an idea about how it will come together. > Design Doc: https://goo.gl/sFeSUT > > Bug: webrtc:7671 > Change-Id: Ia932568fdd7065ba104afd2bc0ecf25a765748ab > Reviewed-on: https://webrtc-review.googlesource.com/22900 > Reviewed-by: Emircan Uysaler <emircan@webrtc.org> > Reviewed-by: Erik Språng <sprang@webrtc.org> > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > Reviewed-by: Niklas Enbom <niklas.enbom@webrtc.org> > Commit-Queue: Emircan Uysaler <emircan@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#20920} TBR=danilchap@webrtc.org, sprang@webrtc.org, niklas.enbom@webrtc.org Bug: webrtc:7671 Change-Id: If8f0c7e6e3a2a704f19161f0e8bf1880906e7fe0 Reviewed-on: https://webrtc-review.googlesource.com/27160 Reviewed-by: Emircan Uysaler <emircan@webrtc.org> Commit-Queue: Emircan Uysaler <emircan@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20946}
2017-11-28 09:45:25 -08:00
std::vector<EncodedImage>* frames,
std::vector<CodecSpecificInfo>* codec_specific_info) {
EXPECT_TRUE(encoded_frame_event_.Wait(kEncodeTimeoutMs))
<< "Timed out while waiting for encoded frame.";
// This becomes unsafe if there are multiple threads waiting for frames.
rtc::CritScope lock(&encoded_frame_section_);
Reland "Add stereo codec header and pass it through RTP" This is a reland of 20f2133d5dbd1591b89425b24db3b1e09fbcf0b1 Original change's description: > Add stereo codec header and pass it through RTP > > - Defines CodecSpecificInfoStereo that carries stereo specific header info from > encoded image. > - Defines RTPVideoHeaderStereo that carries the above info to packetizer, > see module_common_types.h. > - Adds an RTPPacketizer and RTPDepacketizer that supports passing specific stereo > header. > - Uses new data containers in StereoAdapter classes. > > This CL is the step 3 for adding alpha channel support over the wire in webrtc. > See https://webrtc-review.googlesource.com/c/src/+/7800 for the experimental > CL that gives an idea about how it will come together. > Design Doc: https://goo.gl/sFeSUT > > Bug: webrtc:7671 > Change-Id: Ia932568fdd7065ba104afd2bc0ecf25a765748ab > Reviewed-on: https://webrtc-review.googlesource.com/22900 > Reviewed-by: Emircan Uysaler <emircan@webrtc.org> > Reviewed-by: Erik Språng <sprang@webrtc.org> > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > Reviewed-by: Niklas Enbom <niklas.enbom@webrtc.org> > Commit-Queue: Emircan Uysaler <emircan@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#20920} TBR=danilchap@webrtc.org, sprang@webrtc.org, niklas.enbom@webrtc.org Bug: webrtc:7671 Change-Id: If8f0c7e6e3a2a704f19161f0e8bf1880906e7fe0 Reviewed-on: https://webrtc-review.googlesource.com/27160 Reviewed-by: Emircan Uysaler <emircan@webrtc.org> Commit-Queue: Emircan Uysaler <emircan@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20946}
2017-11-28 09:45:25 -08:00
EXPECT_FALSE(encoded_frames_.empty());
EXPECT_FALSE(codec_specific_infos_.empty());
EXPECT_EQ(encoded_frames_.size(), codec_specific_infos_.size());
if (!encoded_frames_.empty()) {
*frames = encoded_frames_;
encoded_frames_.clear();
RTC_DCHECK(!codec_specific_infos_.empty());
*codec_specific_info = codec_specific_infos_;
codec_specific_infos_.clear();
return true;
} else {
return false;
}
}
bool VideoCodecUnitTest::WaitForDecodedFrame(std::unique_ptr<VideoFrame>* frame,
absl::optional<uint8_t>* qp) {
bool ret = decoded_frame_event_.Wait(kDecodeTimeoutMs);
EXPECT_TRUE(ret) << "Timed out while waiting for a decoded frame.";
// This becomes unsafe if there are multiple threads waiting for frames.
rtc::CritScope lock(&decoded_frame_section_);
EXPECT_TRUE(decoded_frame_);
if (decoded_frame_) {
frame->reset(new VideoFrame(std::move(*decoded_frame_)));
*qp = decoded_qp_;
decoded_frame_.reset();
return true;
} else {
return false;
}
}
size_t VideoCodecUnitTest::GetNumEncodedFrames() {
rtc::CritScope lock(&encoded_frame_section_);
return encoded_frames_.size();
}
} // namespace webrtc