From 322acdcd0fa514aa4612edb1cba0a1bec792cba8 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 24 May 2022 22:33:06 +0200 Subject: fixup! Playback sort of works. --- src/lib/cuda_decoder.h | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/lib/cuda_decoder.h (limited to 'src/lib/cuda_decoder.h') diff --git a/src/lib/cuda_decoder.h b/src/lib/cuda_decoder.h new file mode 100644 index 000000000..63983861f --- /dev/null +++ b/src/lib/cuda_decoder.h @@ -0,0 +1,79 @@ +/* + Copyright (C) 2022 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + + +#include "image.h" +#include +extern "C" { +#include +} +#include +#include +#include +#include +#include +#include + + +class CUDADecoder +{ +public: + CUDADecoder(); + ~CUDADecoder(); + + CUDADecoder(CUDADecoder &) = delete; + CUDADecoder(CUDADecoder &&) = delete; + + std::shared_ptr decode(std::shared_ptr j2k_data, int reduce, AVPixelFormat pixel_format, Image::Alignment alignment); + + static CUDADecoder* instance(); + +private: + typedef uint64_t ID; + + class QueueItem + { + public: + ID id; + std::shared_ptr data; + int reduce; + AVPixelFormat pixel_format; + Image::Alignment alignment; + }; + + void thread(); + std::shared_ptr decode_one(QueueItem const& input, nvjpeg2kHandle_t handle, nvjpeg2kDecodeState_t state, nvjpeg2kStream_t jpeg2k_stream); + void check_jpeg2k(std::string name, nvjpeg2kStatus_t status); + + std::queue _queue; + std::map> _output; + boost::condition _queue_empty_condition; + boost::condition _complete_condition; + boost::mutex _mutex; + boost::thread _thread; + ID _next_id = 0; + dcp::Size _allocation; + uint16_t* _device[3] = { nullptr, nullptr, nullptr }; + size_t _pitch[3]; + std::vector _host[3]; + + static CUDADecoder* _instance; +}; + -- cgit v1.2.3