Reland of Add QP for FFmpeg H264 decoder. (patchset #1 id:1 of https://codereview.webrtc.org/2726973003/ )
Reason for revert: The issue is now hopefully fixed. Original issue's description: > Revert of Add QP for FFmpeg H264 decoder. (patchset #4 id:200001 of https://codereview.webrtc.org/2649133007/ ) > > Reason for revert: > Let's revert this while we investigate a problem in H264 bitstream parser. > > Original issue's description: > > Add QP for FFmpeg H264 decoder. > > > > BUG=webrtc:6541 > > > > Review-Url: https://codereview.webrtc.org/2649133007 > > Cr-Commit-Position: refs/heads/master@{#16942} > > Committed:879f4f6c31> > TBR=sprang@webrtc.org > # Not skipping CQ checks because original CL landed more than 1 days ago. > BUG=webrtc:6541, chromium:697795 > > Review-Url: https://codereview.webrtc.org/2726973003 > Cr-Commit-Position: refs/heads/master@{#16974} > Committed:4c6df8893eTBR=sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:6541, chromium:697795 Review-Url: https://codereview.webrtc.org/2735733002 Cr-Commit-Position: refs/heads/master@{#17061}
This commit is contained in:
@ -8,161 +8,25 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "webrtc/base/criticalsection.h"
|
||||
#include "webrtc/base/event.h"
|
||||
#include "webrtc/base/thread_annotations.h"
|
||||
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
|
||||
#include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h"
|
||||
#include "webrtc/test/frame_utils.h"
|
||||
#include "webrtc/test/gtest.h"
|
||||
#include "webrtc/test/testsupport/fileutils.h"
|
||||
#include "webrtc/modules/video_coding/codecs/test/video_codec_test.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
static const int kEncodeTimeoutMs = 100;
|
||||
static const int kDecodeTimeoutMs = 25;
|
||||
// Set a start bitrate to get higher quality.
|
||||
static const int kStartBitrate = 300;
|
||||
static const int kWidth = 172; // Width of the input image.
|
||||
static const int kHeight = 144; // Height of the input image.
|
||||
static const int kMaxFramerate = 30; // Arbitrary value.
|
||||
|
||||
class TestVp9Impl : public ::testing::Test {
|
||||
public:
|
||||
TestVp9Impl()
|
||||
: encode_complete_callback_(this),
|
||||
decode_complete_callback_(this),
|
||||
encoded_frame_event_(false /* manual reset */,
|
||||
false /* initially signaled */),
|
||||
decoded_frame_event_(false /* manual reset */,
|
||||
false /* initially signaled */) {}
|
||||
|
||||
class TestVp9Impl : public VideoCodecTest {
|
||||
protected:
|
||||
class FakeEncodeCompleteCallback : public webrtc::EncodedImageCallback {
|
||||
public:
|
||||
explicit FakeEncodeCompleteCallback(TestVp9Impl* test) : test_(test) {}
|
||||
VideoEncoder* CreateEncoder() override { return VP9Encoder::Create(); }
|
||||
|
||||
Result OnEncodedImage(const EncodedImage& frame,
|
||||
const CodecSpecificInfo* codec_specific_info,
|
||||
const RTPFragmentationHeader* fragmentation) {
|
||||
rtc::CritScope lock(&test_->encoded_frame_section_);
|
||||
test_->encoded_frame_ = rtc::Optional<EncodedImage>(frame);
|
||||
test_->encoded_frame_event_.Set();
|
||||
return Result(Result::OK);
|
||||
}
|
||||
VideoDecoder* CreateDecoder() override { return VP9Decoder::Create(); }
|
||||
|
||||
private:
|
||||
TestVp9Impl* const test_;
|
||||
};
|
||||
|
||||
class FakeDecodeCompleteCallback : public webrtc::DecodedImageCallback {
|
||||
public:
|
||||
explicit FakeDecodeCompleteCallback(TestVp9Impl* test) : test_(test) {}
|
||||
|
||||
int32_t Decoded(VideoFrame& frame) override {
|
||||
RTC_NOTREACHED();
|
||||
return -1;
|
||||
}
|
||||
int32_t Decoded(VideoFrame& frame, int64_t decode_time_ms) override {
|
||||
RTC_NOTREACHED();
|
||||
return -1;
|
||||
}
|
||||
void Decoded(VideoFrame& frame,
|
||||
rtc::Optional<int32_t> decode_time_ms,
|
||||
rtc::Optional<uint8_t> qp) override {
|
||||
rtc::CritScope lock(&test_->decoded_frame_section_);
|
||||
test_->decoded_frame_ = rtc::Optional<VideoFrame>(frame);
|
||||
test_->decoded_qp_ = qp;
|
||||
test_->decoded_frame_event_.Set();
|
||||
}
|
||||
|
||||
private:
|
||||
TestVp9Impl* const test_;
|
||||
};
|
||||
|
||||
void SetUp() override {
|
||||
// Using a QCIF image. Processing only one frame.
|
||||
FILE* source_file_ =
|
||||
fopen(test::ResourcePath("paris_qcif", "yuv").c_str(), "rb");
|
||||
ASSERT_TRUE(source_file_ != NULL);
|
||||
rtc::scoped_refptr<VideoFrameBuffer> video_frame_buffer(
|
||||
test::ReadI420Buffer(kWidth, kHeight, source_file_));
|
||||
input_frame_.reset(new VideoFrame(video_frame_buffer, kVideoRotation_0, 0));
|
||||
fclose(source_file_);
|
||||
|
||||
encoder_.reset(VP9Encoder::Create());
|
||||
decoder_.reset(VP9Decoder::Create());
|
||||
encoder_->RegisterEncodeCompleteCallback(&encode_complete_callback_);
|
||||
decoder_->RegisterDecodeCompleteCallback(&decode_complete_callback_);
|
||||
|
||||
InitCodecs();
|
||||
VideoCodec codec_settings() override {
|
||||
VideoCodec codec_inst;
|
||||
codec_inst.codecType = webrtc::kVideoCodecVP9;
|
||||
codec_inst.VP9()->numberOfTemporalLayers = 1;
|
||||
codec_inst.VP9()->numberOfSpatialLayers = 1;
|
||||
return codec_inst;
|
||||
}
|
||||
|
||||
void InitCodecs() {
|
||||
VideoCodec codec_inst_;
|
||||
codec_inst_.startBitrate = kStartBitrate;
|
||||
codec_inst_.codecType = webrtc::kVideoCodecVP9;
|
||||
codec_inst_.maxFramerate = kMaxFramerate;
|
||||
codec_inst_.width = kWidth;
|
||||
codec_inst_.height = kHeight;
|
||||
codec_inst_.VP9()->numberOfTemporalLayers = 1;
|
||||
codec_inst_.VP9()->numberOfSpatialLayers = 1;
|
||||
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
|
||||
encoder_->InitEncode(&codec_inst_, 1 /* number of cores */,
|
||||
0 /* max payload size (unused) */));
|
||||
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
|
||||
decoder_->InitDecode(&codec_inst_, 1 /* number of cores */));
|
||||
}
|
||||
|
||||
bool WaitForEncodedFrame(EncodedImage* frame) {
|
||||
bool ret = encoded_frame_event_.Wait(kEncodeTimeoutMs);
|
||||
EXPECT_TRUE(ret) << "Timed out while waiting for an encoded frame.";
|
||||
// This becomes unsafe if there are multiple threads waiting for frames.
|
||||
rtc::CritScope lock(&encoded_frame_section_);
|
||||
EXPECT_TRUE(encoded_frame_);
|
||||
if (encoded_frame_) {
|
||||
*frame = std::move(*encoded_frame_);
|
||||
encoded_frame_.reset();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool WaitForDecodedFrame(std::unique_ptr<VideoFrame>* frame,
|
||||
rtc::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;
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<VideoFrame> input_frame_;
|
||||
|
||||
std::unique_ptr<VideoEncoder> encoder_;
|
||||
std::unique_ptr<VideoDecoder> decoder_;
|
||||
|
||||
private:
|
||||
FakeEncodeCompleteCallback encode_complete_callback_;
|
||||
FakeDecodeCompleteCallback decode_complete_callback_;
|
||||
|
||||
rtc::Event encoded_frame_event_;
|
||||
rtc::CriticalSection encoded_frame_section_;
|
||||
rtc::Optional<EncodedImage> encoded_frame_ GUARDED_BY(encoded_frame_section_);
|
||||
|
||||
rtc::Event decoded_frame_event_;
|
||||
rtc::CriticalSection decoded_frame_section_;
|
||||
rtc::Optional<VideoFrame> decoded_frame_ GUARDED_BY(decoded_frame_section_);
|
||||
rtc::Optional<uint8_t> decoded_qp_ GUARDED_BY(decoded_frame_section_);
|
||||
};
|
||||
|
||||
TEST_F(TestVp9Impl, EncodeDecode) {
|
||||
|
||||
Reference in New Issue
Block a user