nvdec.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "common/assert.h"
  4. #include "video_core/host1x/host1x.h"
  5. #include "video_core/host1x/nvdec.h"
  6. namespace Tegra::Host1x {
  7. #define NVDEC_REG_INDEX(field_name) \
  8. (offsetof(NvdecCommon::NvdecRegisters, field_name) / sizeof(u64))
  9. Nvdec::Nvdec(Host1x& host1x_)
  10. : host1x(host1x_), state{}, codec(std::make_unique<Codec>(host1x, state)) {}
  11. Nvdec::~Nvdec() = default;
  12. void Nvdec::ProcessMethod(u32 method, u32 argument) {
  13. state.reg_array[method] = static_cast<u64>(argument) << 8;
  14. switch (method) {
  15. case NVDEC_REG_INDEX(set_codec_id):
  16. codec->SetTargetCodec(static_cast<NvdecCommon::VideoCodec>(argument));
  17. break;
  18. case NVDEC_REG_INDEX(execute):
  19. Execute();
  20. break;
  21. }
  22. }
  23. AVFramePtr Nvdec::GetFrame() {
  24. return codec->GetCurrentFrame();
  25. }
  26. void Nvdec::Execute() {
  27. switch (codec->GetCurrentCodec()) {
  28. case NvdecCommon::VideoCodec::H264:
  29. case NvdecCommon::VideoCodec::VP8:
  30. case NvdecCommon::VideoCodec::VP9:
  31. codec->Decode();
  32. break;
  33. default:
  34. UNIMPLEMENTED_MSG("Codec {}", codec->GetCurrentCodecName());
  35. break;
  36. }
  37. }
  38. } // namespace Tegra::Host1x