Bug 2005729 - Unit test that GMP encoder input frames dropped by plugin are tracked. r=bwc

Differential Revision: https://phabricator.services.mozilla.com/D284809
This commit is contained in:
Andreas Pehrson authored and [email protected] committed 2026-02-27 10:51:46 +00:00
1 parent 1e4695f228
commit 1829412f2a
2 files changed
+64

No files matched your search

@@ -129,6 +129,7 @@ class FakeVideoEncoder : public GMPVideoEncoder {
GMPVideoEncoderCallback* callback, int32_t numberOfCores,
uint32_t maxPayloadSize) override {
callback_ = callback;
frame_drop_state_ = codecSettings.mFrameDroppingOn ? KeepNext : NoDrop;
frame_size_ = (maxPayloadSize > 0 && maxPayloadSize < BIG_FRAME)
? maxPayloadSize
: BIG_FRAME;
@@ -146,6 +147,14 @@ class FakeVideoEncoder : public GMPVideoEncoder {
void SendFrame(GMPVideoi420Frame* inputImage, GMPVideoFrameType frame_type,
int nal_type) {
if (frame_drop_state_ == KeepNext) {
GMPLOG(GL_DEBUG, "Frame dropping is on. Keeping.");
frame_drop_state_ = DropNext;
} else if (frame_drop_state_ == DropNext) {
GMPLOG(GL_DEBUG, "Frame dropping is on. Dropping.");
frame_drop_state_ = KeepNext;
return;
}
// Encode this in a frame that looks a little bit like H.264.
// Send SPS/PPS/IDR to avoid confusing people
// Copy the data. This really should convert this to network byte order.
@@ -271,6 +280,7 @@ class FakeVideoEncoder : public GMPVideoEncoder {
GMPVideoHost* host_;
GMPVideoEncoderCallback* callback_ = nullptr;
enum { NoDrop, DropNext, KeepNext } frame_drop_state_ = NoDrop;
uint32_t frame_size_ = BIG_FRAME;
uint32_t frames_encoded_ = 0;
};
+54
View File
@@ -225,4 +225,58 @@ TEST_F(TestWebrtcGmpVideoEncoder, ReUse) {
WEBRTC_VIDEO_CODEC_OK);
EXPECT_EQ(WaitForResolve(donePromise), true);
}
TEST_F(TestWebrtcGmpVideoEncoder, TrackedFrameDrops) {
using Result = webrtc::EncodedImageCallback::Result;
// Tell the fakeopenh264 plugin to drop some allocated input frames without
// telling us. It will drop every second input frame. This shall get tracked
// as frame drops.
mCodecSettings.SetFrameDropEnabled(true);
mEncoder->InitEncode(&mCodecSettings, mSettings);
WaitFor(*mEncoder->InitPluginEvent());
MozPromiseHolder<GenericPromise> encodedHolder, encodedHolder2;
RefPtr encodedPromise = encodedHolder.Ensure(__func__);
MockEncodedImageCallback callback;
constexpr uint32_t ntpTime = 55;
constexpr uint32_t ntpTime2 = ntpTime * 2;
EXPECT_CALL(
callback,
OnEncodedImage(Property(&webrtc::EncodedImage::NtpTimeMs, ntpTime), _))
.WillOnce([&] {
encodedHolder.Resolve(true,
"TestWebrtcGmpVideoEncoder::TrackedFrameDrops");
return Result(Result::OK);
});
EXPECT_CALL(
callback,
OnDroppedFrame(MockEncodedImageCallback::DropReason::kDroppedByEncoder))
.WillOnce([&] {
encodedHolder2.Resolve(false,
"TestWebrtcGmpVideoEncoder::TrackedFrameDrops");
});
mEncoder->RegisterEncodeCompleteCallback(&callback);
std::vector<webrtc::VideoFrameType> types = {
webrtc::VideoFrameType::kVideoFrameKey};
EXPECT_EQ(
mEncoder->Encode(webrtc::VideoFrame::Builder()
.set_ntp_time_ms(ntpTime)
.set_video_frame_buffer(CreateBlackFrame(
mCodecSettings.width, mCodecSettings.height))
.build(),
&types),
WEBRTC_VIDEO_CODEC_OK);
EXPECT_EQ(WaitForResolve(encodedPromise), true);
encodedPromise = encodedHolder2.Ensure(__func__);
EXPECT_EQ(
mEncoder->Encode(webrtc::VideoFrame::Builder()
.set_ntp_time_ms(ntpTime2)
.set_video_frame_buffer(CreateBlackFrame(
mCodecSettings.width, mCodecSettings.height))
.build(),
&types),
WEBRTC_VIDEO_CODEC_OK);
EXPECT_EQ(WaitForResolve(encodedPromise), false);
}
} // namespace mozilla