nvdec.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/assert.h"
  5. #include "video_core/command_classes/nvdec.h"
  6. #include "video_core/gpu.h"
  7. namespace Tegra {
  8. #define NVDEC_REG_INDEX(field_name) \
  9. (offsetof(NvdecCommon::NvdecRegisters, field_name) / sizeof(u64))
  10. Nvdec::Nvdec(GPU& gpu_) : gpu(gpu_), state{}, codec(std::make_unique<Codec>(gpu, 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::Vp9:
  30. codec->Decode();
  31. break;
  32. default:
  33. UNIMPLEMENTED_MSG("Unknown codec {}", static_cast<u32>(codec->GetCurrentCodec()));
  34. break;
  35. }
  36. }
  37. } // namespace Tegra