Skip to content

File nvdec_decoder.hpp

File List > plugins > semantic_python > nvdec_decoder.hpp

Go to the documentation of this file

#pragma once

#include "nv12_to_rgb.cuh"

#include 
#include 
#include 
#include 
#include 
#include 

namespace ILLIXR {

class nvdec_decoder {
public:
    explicit nvdec_decoder(cudaVideoCodec codec = cudaVideoCodec_HEVC);

    ~nvdec_decoder();

    // Non-copyable, non-movable - owns CUDA context
    nvdec_decoder(const nvdec_decoder&)            = delete;
    nvdec_decoder& operator=(const nvdec_decoder&) = delete;

    const uint8_t* decode(const uint8_t* data, size_t size, int64_t frame_number, int64_t& out_frame_number);

    int width() const {
        return width_;
    }

    int height() const {
        return height_;
    }

private:
    void ensure_buffers(int w, int h);

    void free_pinned();

    cudaVideoCodec             codec_;
    CUcontext                  cuda_ctx_ = nullptr;
    std::unique_ptr<NvDecoder> decoder_;

    uint8_t*     pinned_rgb_ = nullptr; // pinned host buffer, H*W*3 bytes
    uint8_t*     device_rgb_ = nullptr; // device buffer for GPU RGB conversion
    cudaStream_t stream_     = nullptr;
    int          width_      = 0;
    int          height_     = 0;
};

} // namespace ILLIXR