nvjpeg_decoder.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // Part of the following code in this file refs to
  16. // https://github.com/CVCUDA/CV-CUDA/blob/release_v0.2.x/samples/common/NvDecoder.h
  17. //
  18. // Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
  19. // Licensed under the Apache-2.0 license
  20. // \brief
  21. // \author NVIDIA
  22. #pragma once
  23. #ifdef ENABLE_NVJPEG
  24. #include "ultra_infer/core/fd_tensor.h"
  25. #include <cuda_runtime_api.h>
  26. #include <nvjpeg.h>
  27. namespace ultra_infer {
  28. namespace vision {
  29. namespace nvjpeg {
  30. typedef std::vector<std::string> FileNames;
  31. typedef std::vector<std::vector<char>> FileData;
  32. struct decode_params_t {
  33. int batch_size;
  34. nvjpegJpegState_t nvjpeg_state;
  35. nvjpegHandle_t nvjpeg_handle;
  36. cudaStream_t stream;
  37. // used with decoupled API
  38. nvjpegJpegState_t nvjpeg_decoupled_state;
  39. nvjpegBufferPinned_t pinned_buffers[2]; // 2 buffers for pipelining
  40. nvjpegBufferDevice_t device_buffer;
  41. nvjpegJpegStream_t jpeg_streams[2]; // 2 streams for pipelining
  42. nvjpegDecodeParams_t nvjpeg_decode_params;
  43. nvjpegJpegDecoder_t nvjpeg_decoder;
  44. nvjpegOutputFormat_t fmt;
  45. bool hw_decode_available;
  46. };
  47. void init_decoder(decode_params_t &params);
  48. void destroy_decoder(decode_params_t &params);
  49. double process_images(const FileNames &image_names, decode_params_t &params,
  50. double &total, std::vector<nvjpegImage_t> &iout,
  51. std::vector<FDTensor *> &output_buffers,
  52. std::vector<int> &widths, std::vector<int> &heights);
  53. } // namespace nvjpeg
  54. } // namespace vision
  55. } // namespace ultra_infer
  56. #endif // ENABLE_NVJPEG