summaryrefslogtreecommitdiffstats
path: root/src/video_core/command_classes/nvdec.cpp
blob: e4f919afd1389c41dd7b497e23d07ca19767437a (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
// Copyright 2020 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include "common/assert.h"
#include "video_core/command_classes/nvdec.h"
#include "video_core/gpu.h"

namespace Tegra {

Nvdec::Nvdec(GPU& gpu_) : gpu(gpu_), codec(std::make_unique<Codec>(gpu)) {}

Nvdec::~Nvdec() = default;

void Nvdec::ProcessMethod(Method method, u32 argument) {
    if (method == Method::SetVideoCodec) {
        codec->StateWrite(static_cast<u32>(method), argument);
    } else {
        codec->StateWrite(static_cast<u32>(method), static_cast<u64>(argument) << 8);
    }

    switch (method) {
    case Method::SetVideoCodec:
        codec->SetTargetCodec(static_cast<NvdecCommon::VideoCodec>(argument));
        break;
    case Method::Execute:
        Execute();
        break;
    }
}

AVFramePtr Nvdec::GetFrame() {
    return codec->GetCurrentFrame();
}

void Nvdec::Execute() {
    switch (codec->GetCurrentCodec()) {
    case NvdecCommon::VideoCodec::H264:
    case NvdecCommon::VideoCodec::Vp9:
        codec->Decode();
        break;
    default:
        UNIMPLEMENTED_MSG("Unknown codec {}", static_cast<u32>(codec->GetCurrentCodec()));
        break;
    }
}

} // namespace Tegra