aboutsummaryrefslogtreecommitdiff
path: root/src/video_core/host1x/codecs/decoder.cpp
blob: c75059db6f5c5cb82af3368077a94080e4ca8d94 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later

// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "common/assert.h"
#include "common/settings.h"
#include "video_core/host1x/codecs/decoder.h"
#include "video_core/host1x/host1x.h"
#include "video_core/memory_manager.h"

namespace Tegra {

Decoder::Decoder(Host1x::Host1x& host1x_, s32 id_, const Host1x::NvdecCommon::NvdecRegisters& regs_)
    : host1x(host1x_)
    , regs{regs_}
    , id{id_}
{}

Decoder::~Decoder() = default;

void Decoder::Decode() {
    if (!initialized) {
        return;
    }

    const auto packet_data = ComposeFrame();
    // Send assembled bitstream to decoder.
    if (!decode_api.SendPacket(packet_data)) {
        return;
    }

    // Only receive/store visible frames.
    if (vp9_hidden_frame) {
        return;
    }

    // Receive output frames from decoder.
    auto frame = decode_api.ReceiveFrame();

    if (!frame) {
        return;
    }

    if (IsInterlaced()) {
        auto [luma_top, luma_bottom, chroma_top, chroma_bottom] = GetInterlacedOffsets();
        auto frame_copy = frame;

        if (!frame.get()) {
            LOG_ERROR(HW_GPU,
                      "Nvdec {} failed to decode interlaced frame for top {:#X} bottom 0x{:X}", id,
                      luma_top, luma_bottom);
        }

        if (UsingDecodeOrder()) {
            host1x.frame_queue.PushDecodeOrder(id, luma_top, std::move(frame));
            host1x.frame_queue.PushDecodeOrder(id, luma_bottom, std::move(frame_copy));
        } else {
            host1x.frame_queue.PushPresentOrder(id, luma_top, std::move(frame));
            host1x.frame_queue.PushPresentOrder(id, luma_bottom, std::move(frame_copy));
        }
    } else {
        auto [luma_offset, chroma_offset] = GetProgressiveOffsets();

        if (!frame.get()) {
            LOG_ERROR(HW_GPU, "Nvdec {} failed to decode progressive frame for luma {:#X}", id,
                      luma_offset);
        }

        if (UsingDecodeOrder()) {
            host1x.frame_queue.PushDecodeOrder(id, luma_offset, std::move(frame));
        } else {
            host1x.frame_queue.PushPresentOrder(id, luma_offset, std::move(frame));
        }
    }
}

} // namespace Tegra