summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/test/fake_vp8_decoder.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/libwebrtc/test/fake_vp8_decoder.cc
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/test/fake_vp8_decoder.cc')
-rw-r--r--third_party/libwebrtc/test/fake_vp8_decoder.cc91
1 files changed, 91 insertions, 0 deletions
diff --git a/third_party/libwebrtc/test/fake_vp8_decoder.cc b/third_party/libwebrtc/test/fake_vp8_decoder.cc
new file mode 100644
index 0000000000..4ed2523c82
--- /dev/null
+++ b/third_party/libwebrtc/test/fake_vp8_decoder.cc
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2018 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 "test/fake_vp8_decoder.h"
+
+#include <stddef.h>
+
+#include "absl/types/optional.h"
+#include "api/scoped_refptr.h"
+#include "api/video/i420_buffer.h"
+#include "api/video/video_frame.h"
+#include "api/video/video_frame_buffer.h"
+#include "api/video/video_rotation.h"
+#include "modules/video_coding/include/video_error_codes.h"
+#include "rtc_base/time_utils.h"
+
+namespace webrtc {
+namespace test {
+
+namespace {
+// Read width and height from the payload of the frame if it is a key frame the
+// same way as the real VP8 decoder.
+// FakeEncoder writes width, height and frame type.
+void ParseFakeVp8(const unsigned char* data, int* width, int* height) {
+ bool key_frame = data[0] == 0;
+ if (key_frame) {
+ *width = ((data[7] << 8) + data[6]) & 0x3FFF;
+ *height = ((data[9] << 8) + data[8]) & 0x3FFF;
+ }
+}
+} // namespace
+
+FakeVp8Decoder::FakeVp8Decoder() : callback_(nullptr), width_(0), height_(0) {}
+
+bool FakeVp8Decoder::Configure(const Settings& settings) {
+ return true;
+}
+
+int32_t FakeVp8Decoder::Decode(const EncodedImage& input,
+ int64_t render_time_ms) {
+ constexpr size_t kMinPayLoadHeaderLength = 10;
+ if (input.size() < kMinPayLoadHeaderLength) {
+ return WEBRTC_VIDEO_CODEC_ERROR;
+ }
+ ParseFakeVp8(input.data(), &width_, &height_);
+
+ VideoFrame frame =
+ VideoFrame::Builder()
+ .set_video_frame_buffer(I420Buffer::Create(width_, height_))
+ .set_rotation(webrtc::kVideoRotation_0)
+ .set_timestamp_ms(render_time_ms)
+ .build();
+ frame.set_timestamp(input.RtpTimestamp());
+ frame.set_ntp_time_ms(input.ntp_time_ms_);
+
+ callback_->Decoded(frame, /*decode_time_ms=*/absl::nullopt,
+ /*qp=*/absl::nullopt);
+
+ return WEBRTC_VIDEO_CODEC_OK;
+}
+
+int32_t FakeVp8Decoder::RegisterDecodeCompleteCallback(
+ DecodedImageCallback* callback) {
+ callback_ = callback;
+ return WEBRTC_VIDEO_CODEC_OK;
+}
+
+int32_t FakeVp8Decoder::Release() {
+ return WEBRTC_VIDEO_CODEC_OK;
+}
+
+VideoDecoder::DecoderInfo FakeVp8Decoder::GetDecoderInfo() const {
+ DecoderInfo info;
+ info.implementation_name = kImplementationName;
+ info.is_hardware_accelerated = false;
+ return info;
+}
+
+const char* FakeVp8Decoder::ImplementationName() const {
+ return kImplementationName;
+}
+
+} // namespace test
+} // namespace webrtc