2015-05-18 19:42:03 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2015 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "media/engine/videodecodersoftwarefallbackwrapper.h"
|
|
|
|
|
#include "api/video_codecs/video_decoder.h"
|
2017-11-09 13:43:42 +01:00
|
|
|
#include "modules/video_coding/codecs/vp8/include/vp8.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_coding/include/video_error_codes.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "test/gtest.h"
|
2015-05-18 19:42:03 +02:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
class VideoDecoderSoftwareFallbackWrapperTest : public ::testing::Test {
|
|
|
|
|
protected:
|
|
|
|
|
VideoDecoderSoftwareFallbackWrapperTest()
|
2017-09-11 11:50:51 -07:00
|
|
|
: fake_decoder_(new CountingFakeDecoder()),
|
2017-11-09 13:43:42 +01:00
|
|
|
fallback_wrapper_(std::unique_ptr<VideoDecoder>(VP8Decoder::Create()),
|
2017-09-11 11:50:51 -07:00
|
|
|
std::unique_ptr<VideoDecoder>(fake_decoder_)) {}
|
2015-05-18 19:42:03 +02:00
|
|
|
|
|
|
|
|
class CountingFakeDecoder : public VideoDecoder {
|
|
|
|
|
public:
|
|
|
|
|
int32_t InitDecode(const VideoCodec* codec_settings,
|
|
|
|
|
int32_t number_of_cores) override {
|
|
|
|
|
++init_decode_count_;
|
2017-02-13 17:11:08 -05:00
|
|
|
return init_decode_return_code_;
|
2015-05-18 19:42:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t Decode(const EncodedImage& input_image,
|
|
|
|
|
bool missing_frames,
|
|
|
|
|
const RTPFragmentationHeader* fragmentation,
|
|
|
|
|
const CodecSpecificInfo* codec_specific_info,
|
|
|
|
|
int64_t render_time_ms) override {
|
|
|
|
|
++decode_count_;
|
|
|
|
|
return decode_return_code_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t RegisterDecodeCompleteCallback(
|
|
|
|
|
DecodedImageCallback* callback) override {
|
|
|
|
|
decode_complete_callback_ = callback;
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t Release() override {
|
|
|
|
|
++release_count_;
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-18 16:01:11 +01:00
|
|
|
const char* ImplementationName() const override {
|
|
|
|
|
return "fake-decoder";
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 19:42:03 +02:00
|
|
|
int init_decode_count_ = 0;
|
|
|
|
|
int decode_count_ = 0;
|
2017-02-13 17:11:08 -05:00
|
|
|
int32_t init_decode_return_code_ = WEBRTC_VIDEO_CODEC_OK;
|
2015-05-18 19:42:03 +02:00
|
|
|
int32_t decode_return_code_ = WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
DecodedImageCallback* decode_complete_callback_ = nullptr;
|
|
|
|
|
int release_count_ = 0;
|
|
|
|
|
int reset_count_ = 0;
|
|
|
|
|
};
|
2017-09-11 11:50:51 -07:00
|
|
|
// |fake_decoder_| is owned and released by |fallback_wrapper_|.
|
|
|
|
|
CountingFakeDecoder* fake_decoder_;
|
2015-05-18 19:42:03 +02:00
|
|
|
VideoDecoderSoftwareFallbackWrapper fallback_wrapper_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(VideoDecoderSoftwareFallbackWrapperTest, InitializesDecoder) {
|
|
|
|
|
VideoCodec codec = {};
|
|
|
|
|
fallback_wrapper_.InitDecode(&codec, 2);
|
2017-09-11 11:50:51 -07:00
|
|
|
EXPECT_EQ(1, fake_decoder_->init_decode_count_);
|
2017-02-13 17:11:08 -05:00
|
|
|
|
|
|
|
|
EncodedImage encoded_image;
|
|
|
|
|
encoded_image._frameType = kVideoFrameKey;
|
|
|
|
|
fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1);
|
2017-09-11 11:50:51 -07:00
|
|
|
EXPECT_EQ(1, fake_decoder_->init_decode_count_)
|
2017-02-13 17:11:08 -05:00
|
|
|
<< "Initialized decoder should not be reinitialized.";
|
2017-09-11 11:50:51 -07:00
|
|
|
EXPECT_EQ(1, fake_decoder_->decode_count_);
|
2017-02-13 17:11:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(VideoDecoderSoftwareFallbackWrapperTest,
|
2017-10-31 17:15:22 -07:00
|
|
|
UsesFallbackDecoderAfterAnyInitDecodeFailure) {
|
2017-02-13 17:11:08 -05:00
|
|
|
VideoCodec codec = {};
|
2017-09-11 11:50:51 -07:00
|
|
|
fake_decoder_->init_decode_return_code_ =
|
2017-10-31 17:15:22 -07:00
|
|
|
WEBRTC_VIDEO_CODEC_UNINITIALIZED;
|
2017-02-13 17:11:08 -05:00
|
|
|
fallback_wrapper_.InitDecode(&codec, 2);
|
2017-09-11 11:50:51 -07:00
|
|
|
EXPECT_EQ(1, fake_decoder_->init_decode_count_);
|
2017-02-13 17:11:08 -05:00
|
|
|
|
|
|
|
|
EncodedImage encoded_image;
|
|
|
|
|
encoded_image._frameType = kVideoFrameKey;
|
|
|
|
|
fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1);
|
2017-09-11 11:50:51 -07:00
|
|
|
EXPECT_EQ(2, fake_decoder_->init_decode_count_)
|
2017-02-13 17:11:08 -05:00
|
|
|
<< "Should have attempted reinitializing the fallback decoder on "
|
|
|
|
|
"keyframe.";
|
|
|
|
|
// Unfortunately faking a VP8 frame is hard. Rely on no Decode -> using SW
|
|
|
|
|
// decoder.
|
2017-09-11 11:50:51 -07:00
|
|
|
EXPECT_EQ(0, fake_decoder_->decode_count_)
|
2017-02-13 17:11:08 -05:00
|
|
|
<< "Decoder used even though no InitDecode had succeeded.";
|
2015-05-18 19:42:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(VideoDecoderSoftwareFallbackWrapperTest,
|
|
|
|
|
CanRecoverFromSoftwareFallback) {
|
|
|
|
|
VideoCodec codec = {};
|
|
|
|
|
fallback_wrapper_.InitDecode(&codec, 2);
|
|
|
|
|
// Unfortunately faking a VP8 frame is hard. Rely on no Decode -> using SW
|
|
|
|
|
// decoder.
|
2017-09-11 11:50:51 -07:00
|
|
|
fake_decoder_->decode_return_code_ = WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE;
|
2015-05-18 19:42:03 +02:00
|
|
|
EncodedImage encoded_image;
|
|
|
|
|
fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1);
|
2017-09-11 11:50:51 -07:00
|
|
|
EXPECT_EQ(1, fake_decoder_->decode_count_);
|
2015-05-18 19:42:03 +02:00
|
|
|
|
|
|
|
|
// Fail -> fake_decoder shouldn't be used anymore.
|
|
|
|
|
fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1);
|
2017-09-11 11:50:51 -07:00
|
|
|
EXPECT_EQ(1, fake_decoder_->decode_count_)
|
2015-05-18 19:42:03 +02:00
|
|
|
<< "Decoder used even though fallback should be active.";
|
|
|
|
|
|
|
|
|
|
// Should be able to recover on a keyframe.
|
2015-10-23 15:58:18 +02:00
|
|
|
encoded_image._frameType = kVideoFrameKey;
|
2017-09-11 11:50:51 -07:00
|
|
|
fake_decoder_->decode_return_code_ = WEBRTC_VIDEO_CODEC_OK;
|
2015-05-18 19:42:03 +02:00
|
|
|
fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1);
|
2017-09-11 11:50:51 -07:00
|
|
|
EXPECT_EQ(2, fake_decoder_->decode_count_)
|
2015-05-18 19:42:03 +02:00
|
|
|
<< "Wrapper did not try to decode a keyframe using registered decoder.";
|
|
|
|
|
|
2015-10-23 15:58:18 +02:00
|
|
|
encoded_image._frameType = kVideoFrameDelta;
|
2015-05-18 19:42:03 +02:00
|
|
|
fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1);
|
2017-09-11 11:50:51 -07:00
|
|
|
EXPECT_EQ(3, fake_decoder_->decode_count_)
|
2015-05-18 19:42:03 +02:00
|
|
|
<< "Decoder not used on future delta frames.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(VideoDecoderSoftwareFallbackWrapperTest, DoesNotFallbackOnEveryError) {
|
|
|
|
|
VideoCodec codec = {};
|
|
|
|
|
fallback_wrapper_.InitDecode(&codec, 2);
|
2017-09-11 11:50:51 -07:00
|
|
|
fake_decoder_->decode_return_code_ = WEBRTC_VIDEO_CODEC_ERROR;
|
2015-05-18 19:42:03 +02:00
|
|
|
EncodedImage encoded_image;
|
|
|
|
|
EXPECT_EQ(
|
2017-09-11 11:50:51 -07:00
|
|
|
fake_decoder_->decode_return_code_,
|
2015-05-18 19:42:03 +02:00
|
|
|
fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1));
|
2017-09-11 11:50:51 -07:00
|
|
|
EXPECT_EQ(1, fake_decoder_->decode_count_);
|
2015-05-18 19:42:03 +02:00
|
|
|
|
|
|
|
|
fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1);
|
2017-09-11 11:50:51 -07:00
|
|
|
EXPECT_EQ(2, fake_decoder_->decode_count_)
|
2015-05-18 19:42:03 +02:00
|
|
|
<< "Decoder should be active even though previous decode failed.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(VideoDecoderSoftwareFallbackWrapperTest, ForwardsReleaseCall) {
|
|
|
|
|
VideoCodec codec = {};
|
|
|
|
|
fallback_wrapper_.InitDecode(&codec, 2);
|
|
|
|
|
fallback_wrapper_.Release();
|
2017-09-11 11:50:51 -07:00
|
|
|
EXPECT_EQ(1, fake_decoder_->release_count_);
|
2015-05-18 19:42:03 +02:00
|
|
|
|
2017-09-11 11:50:51 -07:00
|
|
|
fake_decoder_->decode_return_code_ = WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE;
|
2015-05-18 19:42:03 +02:00
|
|
|
EncodedImage encoded_image;
|
|
|
|
|
fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1);
|
2017-09-11 11:50:51 -07:00
|
|
|
EXPECT_EQ(1, fake_decoder_->release_count_)
|
2015-05-18 19:42:03 +02:00
|
|
|
<< "Decoder should not be released during fallback.";
|
|
|
|
|
fallback_wrapper_.Release();
|
2017-09-11 11:50:51 -07:00
|
|
|
EXPECT_EQ(2, fake_decoder_->release_count_);
|
2015-05-18 19:42:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(pbos): Fake a VP8 frame well enough to actually receive a callback from
|
2015-12-18 16:01:11 +01:00
|
|
|
// the software decoder.
|
2015-05-18 19:42:03 +02:00
|
|
|
TEST_F(VideoDecoderSoftwareFallbackWrapperTest,
|
|
|
|
|
ForwardsRegisterDecodeCompleteCallback) {
|
|
|
|
|
class FakeDecodedImageCallback : public DecodedImageCallback {
|
2015-05-29 17:21:40 -07:00
|
|
|
int32_t Decoded(VideoFrame& decodedImage) override { return 0; }
|
2015-11-10 14:00:27 +01:00
|
|
|
int32_t Decoded(
|
|
|
|
|
webrtc::VideoFrame& decodedImage, int64_t decode_time_ms) override {
|
|
|
|
|
RTC_NOTREACHED();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
Reland of Add QP sum stats for received streams. (patchset #2 id:300001 of https://codereview.webrtc.org/2680893002/ )
Reason for revert:
Fix the problem.
Original issue's description:
> Revert of Add QP sum stats for received streams. (patchset #10 id:180001 of https://codereview.webrtc.org/2649133005/ )
>
> Reason for revert:
> Breaks downstream build.
>
> Original issue's description:
> > Add QP sum stats for received streams.
> >
> > This is not implemented yet in any of the decoders.
> >
> > BUG=webrtc:6541
> >
> > Review-Url: https://codereview.webrtc.org/2649133005
> > Cr-Commit-Position: refs/heads/master@{#16475}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/ff0e72fd165facac27f0313aa178648782e63bc4
>
> TBR=hta@webrtc.org,hbos@webrtc.org,sprang@webrtc.org,magjed@webrtc.org,stefan@webrtc.org,sakal@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:6541
>
> Review-Url: https://codereview.webrtc.org/2680893002 .
> Cr-Commit-Position: refs/heads/master@{#16480}
> Committed: https://chromium.googlesource.com/external/webrtc/+/69fb2cca4d54f3df7ceddcd1c3e9b0ad80fa849b
TBR=hta@webrtc.org,hbos@webrtc.org,sprang@webrtc.org,magjed@webrtc.org,stefan@webrtc.org,skvlad@webrtc.org
BUG=webrtc:6541
Review-Url: https://codereview.webrtc.org/2681663005
Cr-Commit-Position: refs/heads/master@{#16511}
2017-02-09 04:53:45 -08:00
|
|
|
void Decoded(webrtc::VideoFrame& decodedImage,
|
|
|
|
|
rtc::Optional<int32_t> decode_time_ms,
|
|
|
|
|
rtc::Optional<uint8_t> qp) override {
|
|
|
|
|
RTC_NOTREACHED();
|
|
|
|
|
}
|
2015-05-18 19:42:03 +02:00
|
|
|
} callback, callback2;
|
|
|
|
|
|
|
|
|
|
VideoCodec codec = {};
|
|
|
|
|
fallback_wrapper_.InitDecode(&codec, 2);
|
|
|
|
|
fallback_wrapper_.RegisterDecodeCompleteCallback(&callback);
|
2017-09-11 11:50:51 -07:00
|
|
|
EXPECT_EQ(&callback, fake_decoder_->decode_complete_callback_);
|
2015-05-18 19:42:03 +02:00
|
|
|
|
2017-09-11 11:50:51 -07:00
|
|
|
fake_decoder_->decode_return_code_ = WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE;
|
2015-05-18 19:42:03 +02:00
|
|
|
EncodedImage encoded_image;
|
|
|
|
|
fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1);
|
|
|
|
|
fallback_wrapper_.RegisterDecodeCompleteCallback(&callback2);
|
2017-09-11 11:50:51 -07:00
|
|
|
EXPECT_EQ(&callback2, fake_decoder_->decode_complete_callback_);
|
2015-05-18 19:42:03 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-18 16:01:11 +01:00
|
|
|
TEST_F(VideoDecoderSoftwareFallbackWrapperTest,
|
|
|
|
|
ReportsFallbackImplementationName) {
|
|
|
|
|
VideoCodec codec = {};
|
|
|
|
|
fallback_wrapper_.InitDecode(&codec, 2);
|
|
|
|
|
|
2017-09-11 11:50:51 -07:00
|
|
|
fake_decoder_->decode_return_code_ = WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE;
|
2015-12-18 16:01:11 +01:00
|
|
|
EncodedImage encoded_image;
|
|
|
|
|
fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1);
|
|
|
|
|
// Hard coded expected value since libvpx is the software implementation name
|
|
|
|
|
// for VP8. Change accordingly if the underlying implementation does.
|
|
|
|
|
EXPECT_STREQ("libvpx (fallback from: fake-decoder)",
|
|
|
|
|
fallback_wrapper_.ImplementationName());
|
|
|
|
|
fallback_wrapper_.Release();
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 19:42:03 +02:00
|
|
|
} // namespace webrtc
|