2017-03-06 03:52:55 -08:00
|
|
|
/*
|
|
|
|
|
* 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 "webrtc/modules/video_coding/codecs/test/video_codec_test.h"
|
|
|
|
|
|
Reland of Delete deprecated and transitional stuff related to video frame refactoring. (patchset #1 id:1 of https://codereview.webrtc.org/2853383005/ )
Reason for revert:
Downstream projects have been fixed.
Original issue's description:
> Revert of Delete deprecated and transitional stuff related to video frame refactoring. (patchset #1 id:1 of https://codereview.webrtc.org/2854873003/ )
>
> Reason for revert:
> More downstream breakage discovered.
>
> Original issue's description:
> > Reland of Delete deprecated and transitional stuff related to video frame refactoring. (patchset #1 id:1 of https://codereview.webrtc.org/2854883002/ )
> >
> > Reason for revert:
> > Will make another attempt to track down and fix downstream projects.
> >
> > Original issue's description:
> > > Revert of Delete deprecated and transitional stuff related to video frame refactoring. (patchset #1 id:1 of https://codereview.webrtc.org/2852303002/ )
> > >
> > > Reason for revert:
> > > Unfortunately, more downstream updates needed.
> > >
> > > Original issue's description:
> > > > Reland of Delete deprecated and transitional stuff related to video frame refactoring. (patchset #1 id:1 of https://codereview.webrtc.org/2845333002/ )
> > > >
> > > > Reason for revert:
> > > > Downstream projects being updated.
> > > >
> > > > For Chrome, relanding depends on cl
> > > > https://codereview.chromium.org/2855783003/
> > > >
> > > > Original issue's description:
> > > > > Revert of Delete deprecated and transitional stuff related to video frame refactoring. (patchset #17 id:320001 of https://codereview.webrtc.org/2622263002/ )
> > > > >
> > > > > Reason for revert:
> > > > > Broke Chrome build, see, e.g.,
> > > > > http://build.chromium.org/p/chromium.webrtc.fyi/builders/Linux%20Builder/builds/16237
> > > > >
> > > > > Original issue's description:
> > > > > > Delete deprecated and transitional stuff related to video frame refactoring.
> > > > > >
> > > > > > BUG=webrtc:5880
> > > > > >
> > > > > > Review-Url: https://codereview.webrtc.org/2622263002
> > > > > > Cr-Commit-Position: refs/heads/master@{#17928}
> > > > > > Committed: https://chromium.googlesource.com/external/webrtc/+/713a3bbcc74a4c1a1f54d6dbd0bdaa715f5c1ae1
> > > > >
> > > > > TBR=mflodman@webrtc.org,perkj@webrtc.org
> > > > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > > > NOPRESUBMIT=true
> > > > > NOTREECHECKS=true
> > > > > NOTRY=true
> > > > > BUG=webrtc:5880
> > > > >
> > > > > Review-Url: https://codereview.webrtc.org/2845333002
> > > > > Cr-Commit-Position: refs/heads/master@{#17929}
> > > > > Committed: https://chromium.googlesource.com/external/webrtc/+/aec49d2b49e1beceb286cbb29ad220aefd0ac648
> > > >
> > > > TBR=mflodman@webrtc.org,perkj@webrtc.org
> > > > # Not skipping CQ checks because original CL landed more than 1 days ago.
> > > > BUG=webrtc:5880
> > > >
> > > > Review-Url: https://codereview.webrtc.org/2852303002
> > > > Cr-Commit-Position: refs/heads/master@{#17974}
> > > > Committed: https://chromium.googlesource.com/external/webrtc/+/d71ebd70f6c40a37559a7ee2930002a804ad3f13
> > >
> > > TBR=mflodman@webrtc.org,perkj@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:5880
> > >
> > > Review-Url: https://codereview.webrtc.org/2854883002
> > > Cr-Commit-Position: refs/heads/master@{#17978}
> > > Committed: https://chromium.googlesource.com/external/webrtc/+/6e6a485a028799501ea4753ceefc811dd826f52f
> >
> > TBR=mflodman@webrtc.org,perkj@webrtc.org
> > # Skipping CQ checks because original CL landed less than 1 days ago.
> > NOPRESUBMIT=true
> >
> > BUG=webrtc:5880
> >
> > Review-Url: https://codereview.webrtc.org/2854873003
> > Cr-Commit-Position: refs/heads/master@{#18006}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/3870a071c452dc2e782196bc5bba0375d019b653
>
> TBR=mflodman@webrtc.org,perkj@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5880
>
> Review-Url: https://codereview.webrtc.org/2853383005
> Cr-Commit-Position: refs/heads/master@{#18008}
> Committed: https://chromium.googlesource.com/external/webrtc/+/61b22dde133aff91a0db6a628d87b2ea9134fa15
TBR=mflodman@webrtc.org,perkj@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5880
Review-Url: https://codereview.webrtc.org/2867703002
Cr-Commit-Position: refs/heads/master@{#18081}
2017-05-10 05:25:59 -07:00
|
|
|
#include "webrtc/api/video/i420_buffer.h"
|
2017-03-06 03:52:55 -08:00
|
|
|
#include "webrtc/modules/video_coding/include/video_error_codes.h"
|
|
|
|
|
#include "webrtc/test/frame_utils.h"
|
|
|
|
|
#include "webrtc/test/testsupport/fileutils.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 kTargetBitrate = 2000;
|
|
|
|
|
static const int kMaxBitrate = 4000;
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
EncodedImageCallback::Result
|
|
|
|
|
VideoCodecTest::FakeEncodeCompleteCallback::OnEncodedImage(
|
|
|
|
|
const EncodedImage& frame,
|
|
|
|
|
const CodecSpecificInfo* codec_specific_info,
|
|
|
|
|
const RTPFragmentationHeader* fragmentation) {
|
|
|
|
|
rtc::CritScope lock(&test_->encoded_frame_section_);
|
|
|
|
|
test_->encoded_frame_.emplace(frame);
|
2017-05-03 03:25:53 -07:00
|
|
|
RTC_DCHECK(codec_specific_info);
|
|
|
|
|
test_->codec_specific_info_.codecType = codec_specific_info->codecType;
|
|
|
|
|
// Skip |codec_name|, to avoid allocating.
|
|
|
|
|
test_->codec_specific_info_.codecSpecific =
|
|
|
|
|
codec_specific_info->codecSpecific;
|
2017-03-06 03:52:55 -08:00
|
|
|
test_->encoded_frame_event_.Set();
|
|
|
|
|
return Result(Result::OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VideoCodecTest::FakeDecodeCompleteCallback::Decoded(
|
|
|
|
|
VideoFrame& frame,
|
|
|
|
|
rtc::Optional<int32_t> decode_time_ms,
|
|
|
|
|
rtc::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 VideoCodecTest::SetUp() {
|
|
|
|
|
// 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(CreateEncoder());
|
|
|
|
|
decoder_.reset(CreateDecoder());
|
|
|
|
|
encoder_->RegisterEncodeCompleteCallback(&encode_complete_callback_);
|
|
|
|
|
decoder_->RegisterDecodeCompleteCallback(&decode_complete_callback_);
|
|
|
|
|
|
|
|
|
|
InitCodecs();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-03 03:25:53 -07:00
|
|
|
bool VideoCodecTest::WaitForEncodedFrame(
|
|
|
|
|
EncodedImage* frame,
|
|
|
|
|
CodecSpecificInfo* codec_specific_info) {
|
2017-03-06 03:52:55 -08:00
|
|
|
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();
|
2017-05-03 03:25:53 -07:00
|
|
|
RTC_DCHECK(codec_specific_info);
|
|
|
|
|
codec_specific_info->codecType = codec_specific_info_.codecType;
|
|
|
|
|
codec_specific_info->codecSpecific = codec_specific_info_.codecSpecific;
|
2017-03-06 03:52:55 -08:00
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VideoCodecTest::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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VideoCodecTest::InitCodecs() {
|
2017-05-03 03:25:53 -07:00
|
|
|
codec_settings_ = codec_settings();
|
|
|
|
|
codec_settings_.startBitrate = kStartBitrate;
|
|
|
|
|
codec_settings_.targetBitrate = kTargetBitrate;
|
|
|
|
|
codec_settings_.maxBitrate = kMaxBitrate;
|
|
|
|
|
codec_settings_.maxFramerate = kMaxFramerate;
|
|
|
|
|
codec_settings_.width = kWidth;
|
|
|
|
|
codec_settings_.height = kHeight;
|
2017-03-06 03:52:55 -08:00
|
|
|
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
|
2017-05-03 03:25:53 -07:00
|
|
|
encoder_->InitEncode(&codec_settings_, 1 /* number of cores */,
|
2017-03-06 03:52:55 -08:00
|
|
|
0 /* max payload size (unused) */));
|
|
|
|
|
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
|
2017-05-03 03:25:53 -07:00
|
|
|
decoder_->InitDecode(&codec_settings_, 1 /* number of cores */));
|
2017-03-06 03:52:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|