Unwrap the presentation timestamp before calling aom_codec_encode in LibaomAv1Encoder.
Bug: webrtc:14673 Change-Id: I0358fed5ac0839994482c5fb049c13e442f82c82 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/283701 Reviewed-by: Erik Språng <sprang@webrtc.org> Commit-Queue: Philip Eliasson <philipel@webrtc.org> Cr-Commit-Position: refs/heads/main@{#38657}
This commit is contained in:
@ -61,6 +61,7 @@ rtc_library("libaom_av1_encoder") {
|
|||||||
"../../../../common_video",
|
"../../../../common_video",
|
||||||
"../../../../rtc_base:checks",
|
"../../../../rtc_base:checks",
|
||||||
"../../../../rtc_base:logging",
|
"../../../../rtc_base:logging",
|
||||||
|
"../../../../rtc_base:rtc_numerics",
|
||||||
"../../svc:scalability_structures",
|
"../../svc:scalability_structures",
|
||||||
"../../svc:scalable_video_controller",
|
"../../svc:scalable_video_controller",
|
||||||
"//third_party/libaom",
|
"//third_party/libaom",
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "modules/video_coding/svc/scalable_video_controller_no_layering.h"
|
#include "modules/video_coding/svc/scalable_video_controller_no_layering.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
|
#include "rtc_base/numerics/sequence_number_util.h"
|
||||||
#include "third_party/libaom/source/libaom/aom/aom_codec.h"
|
#include "third_party/libaom/source/libaom/aom/aom_codec.h"
|
||||||
#include "third_party/libaom/source/libaom/aom/aom_encoder.h"
|
#include "third_party/libaom/source/libaom/aom/aom_encoder.h"
|
||||||
#include "third_party/libaom/source/libaom/aom/aomcx.h"
|
#include "third_party/libaom/source/libaom/aom/aomcx.h"
|
||||||
@ -117,6 +118,7 @@ class LibaomAv1Encoder final : public VideoEncoder {
|
|||||||
aom_codec_ctx_t ctx_;
|
aom_codec_ctx_t ctx_;
|
||||||
aom_codec_enc_cfg_t cfg_;
|
aom_codec_enc_cfg_t cfg_;
|
||||||
EncodedImageCallback* encoded_image_callback_;
|
EncodedImageCallback* encoded_image_callback_;
|
||||||
|
SeqNumUnwrapper<uint32_t> rtp_timestamp_unwrapper_;
|
||||||
};
|
};
|
||||||
|
|
||||||
int32_t VerifyCodecSettings(const VideoCodec& codec_settings) {
|
int32_t VerifyCodecSettings(const VideoCodec& codec_settings) {
|
||||||
@ -636,9 +638,11 @@ int32_t LibaomAv1Encoder::Encode(
|
|||||||
layer_frame->TemporalId() > 0 ? 1 : 0);
|
layer_frame->TemporalId() > 0 ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode a frame.
|
// Encode a frame. The presentation timestamp `pts` should never wrap, hence
|
||||||
aom_codec_err_t ret = aom_codec_encode(&ctx_, frame_for_encode_,
|
// the unwrapping.
|
||||||
frame.timestamp(), duration, flags);
|
aom_codec_err_t ret = aom_codec_encode(
|
||||||
|
&ctx_, frame_for_encode_,
|
||||||
|
rtp_timestamp_unwrapper_.Unwrap(frame.timestamp()), duration, flags);
|
||||||
if (ret != AOM_CODEC_OK) {
|
if (ret != AOM_CODEC_OK) {
|
||||||
RTC_LOG(LS_WARNING) << "LibaomAv1Encoder::Encode returned " << ret
|
RTC_LOG(LS_WARNING) << "LibaomAv1Encoder::Encode returned " << ret
|
||||||
<< " on aom_codec_encode.";
|
<< " on aom_codec_encode.";
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "modules/video_coding/codecs/av1/libaom_av1_encoder.h"
|
#include "modules/video_coding/codecs/av1/libaom_av1_encoder.h"
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -235,5 +236,29 @@ TEST(LibaomAv1EncoderTest, PopulatesEncodedFrameSize) {
|
|||||||
codec_settings.height)))));
|
codec_settings.height)))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(LibaomAv1EncoderTest, RtpTimestampWrap) {
|
||||||
|
std::unique_ptr<VideoEncoder> encoder = CreateLibaomAv1Encoder();
|
||||||
|
VideoCodec codec_settings = DefaultCodecSettings();
|
||||||
|
codec_settings.SetScalabilityMode(ScalabilityMode::kL1T1);
|
||||||
|
ASSERT_EQ(encoder->InitEncode(&codec_settings, DefaultEncoderSettings()),
|
||||||
|
WEBRTC_VIDEO_CODEC_OK);
|
||||||
|
|
||||||
|
VideoEncoder::RateControlParameters rate_parameters;
|
||||||
|
rate_parameters.framerate_fps = 30;
|
||||||
|
rate_parameters.bitrate.SetBitrate(/*spatial_index=*/0, 0, 300'000);
|
||||||
|
encoder->SetRates(rate_parameters);
|
||||||
|
|
||||||
|
std::vector<EncodedVideoFrameProducer::EncodedFrame> encoded_frames =
|
||||||
|
EncodedVideoFrameProducer(*encoder)
|
||||||
|
.SetNumInputFrames(2)
|
||||||
|
.SetRtpTimestamp(std::numeric_limits<uint32_t>::max())
|
||||||
|
.Encode();
|
||||||
|
ASSERT_THAT(encoded_frames, SizeIs(2));
|
||||||
|
EXPECT_THAT(encoded_frames[0].encoded_image._frameType,
|
||||||
|
Eq(VideoFrameType::kVideoFrameKey));
|
||||||
|
EXPECT_THAT(encoded_frames[1].encoded_image._frameType,
|
||||||
|
Eq(VideoFrameType::kVideoFrameDelta));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
@ -47,6 +47,8 @@ class EncodedVideoFrameProducer {
|
|||||||
|
|
||||||
EncodedVideoFrameProducer& SetFramerateFps(int value);
|
EncodedVideoFrameProducer& SetFramerateFps(int value);
|
||||||
|
|
||||||
|
EncodedVideoFrameProducer& SetRtpTimestamp(uint32_t value);
|
||||||
|
|
||||||
// Generates input video frames and encodes them with `encoder` provided in
|
// Generates input video frames and encodes them with `encoder` provided in
|
||||||
// the constructor. Returns frame passed to the `OnEncodedImage` by wraping
|
// the constructor. Returns frame passed to the `OnEncodedImage` by wraping
|
||||||
// `EncodedImageCallback` underneath.
|
// `EncodedImageCallback` underneath.
|
||||||
@ -88,5 +90,11 @@ inline EncodedVideoFrameProducer& EncodedVideoFrameProducer::SetFramerateFps(
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline EncodedVideoFrameProducer& EncodedVideoFrameProducer::SetRtpTimestamp(
|
||||||
|
uint32_t value) {
|
||||||
|
rtp_timestamp_ = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
#endif // MODULES_VIDEO_CODING_CODECS_TEST_ENCODED_VIDEO_FRAME_PRODUCER_H_
|
#endif // MODULES_VIDEO_CODING_CODECS_TEST_ENCODED_VIDEO_FRAME_PRODUCER_H_
|
||||||
|
Reference in New Issue
Block a user