blob: 3a4793986bc05a27a8957bfdccb805129a22a327 [file] [log] [blame]
Per Kjellander841c9122018-10-04 16:40:281/*
2 * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "test/fake_vp8_decoder.h"
12
Yves Gerey3e707812018-11-28 15:47:4913#include <stddef.h>
14
Florent Castelli8037fc62024-08-29 13:00:4015#include <optional>
16
Mirko Bonadeid9708072019-01-25 19:26:4817#include "api/scoped_refptr.h"
Per Kjellander841c9122018-10-04 16:40:2818#include "api/video/i420_buffer.h"
Yves Gerey3e707812018-11-28 15:47:4919#include "api/video/video_frame.h"
20#include "api/video/video_frame_buffer.h"
21#include "api/video/video_rotation.h"
22#include "modules/video_coding/include/video_error_codes.h"
Steve Anton10542f22019-01-11 17:11:0023#include "rtc_base/time_utils.h"
Per Kjellander841c9122018-10-04 16:40:2824
25namespace webrtc {
26namespace test {
27
28namespace {
29// Read width and height from the payload of the frame if it is a key frame the
30// same way as the real VP8 decoder.
31// FakeEncoder writes width, height and frame type.
32void ParseFakeVp8(const unsigned char* data, int* width, int* height) {
33 bool key_frame = data[0] == 0;
34 if (key_frame) {
35 *width = ((data[7] << 8) + data[6]) & 0x3FFF;
36 *height = ((data[9] << 8) + data[8]) & 0x3FFF;
37 }
38}
39} // namespace
40
41FakeVp8Decoder::FakeVp8Decoder() : callback_(nullptr), width_(0), height_(0) {}
42
Danil Chapovalovd08930d2021-08-12 11:26:5543bool FakeVp8Decoder::Configure(const Settings& settings) {
44 return true;
Per Kjellander841c9122018-10-04 16:40:2845}
46
47int32_t FakeVp8Decoder::Decode(const EncodedImage& input,
Per Kjellander841c9122018-10-04 16:40:2848 int64_t render_time_ms) {
49 constexpr size_t kMinPayLoadHeaderLength = 10;
Niels Möller77536a22019-01-15 07:50:0150 if (input.size() < kMinPayLoadHeaderLength) {
Per Kjellander841c9122018-10-04 16:40:2851 return WEBRTC_VIDEO_CODEC_ERROR;
52 }
Niels Möller24871e42019-01-17 10:31:1353 ParseFakeVp8(input.data(), &width_, &height_);
Per Kjellander841c9122018-10-04 16:40:2854
Artem Titov1ebfb6a2019-01-03 22:49:3755 VideoFrame frame =
56 VideoFrame::Builder()
57 .set_video_frame_buffer(I420Buffer::Create(width_, height_))
58 .set_rotation(webrtc::kVideoRotation_0)
59 .set_timestamp_ms(render_time_ms)
60 .build();
Per K0fa90882024-03-13 08:52:4161 frame.set_rtp_timestamp(input.RtpTimestamp());
Per Kjellander841c9122018-10-04 16:40:2862 frame.set_ntp_time_ms(input.ntp_time_ms_);
63
Florent Castelli8037fc62024-08-29 13:00:4064 callback_->Decoded(frame, /*decode_time_ms=*/std::nullopt,
65 /*qp=*/std::nullopt);
Per Kjellander841c9122018-10-04 16:40:2866
67 return WEBRTC_VIDEO_CODEC_OK;
68}
69
70int32_t FakeVp8Decoder::RegisterDecodeCompleteCallback(
71 DecodedImageCallback* callback) {
72 callback_ = callback;
73 return WEBRTC_VIDEO_CODEC_OK;
74}
75
76int32_t FakeVp8Decoder::Release() {
77 return WEBRTC_VIDEO_CODEC_OK;
78}
79
Erik Språngc12f6252021-01-13 20:49:5980VideoDecoder::DecoderInfo FakeVp8Decoder::GetDecoderInfo() const {
81 DecoderInfo info;
82 info.implementation_name = kImplementationName;
83 info.is_hardware_accelerated = false;
84 return info;
85}
86
Per Kjellander841c9122018-10-04 16:40:2887const char* FakeVp8Decoder::ImplementationName() const {
88 return kImplementationName;
89}
90
91} // namespace test
92} // namespace webrtc