tdav_codec_h264_cuda.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) 2011-2014 Mamadou DIOP.
  3. * Copyright (C) 2011-2014 Doubango Telecom <http://www.doubango.org>.
  4. *
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. /**@file tdav_codec_h264_cuda.h
  23. * @brief H.264 codec plugin using NVIDIA CUDA for encoding/decoding.
  24. * Env: gpucomputingsdk_4.0.17_win_32, cudatoolkit_4.0.17_win_32 and 280.26-notebook-win7-winvista-32bit-international-whql.
  25. * http://developer.download.nvidia.com/compute/DevZone/docs/html/C/doc/CUDA_VideoDecoder_Library.pdf
  26. * http://developer.download.nvidia.com/compute/DevZone/docs/html/C/doc/CUDA_VideoEncoder_Library.pdf
  27. * RTP payloader/depayloader follows RFC 3984.
  28. *
  29. */
  30. #ifndef TINYDAV_CODEC_H264_CUDA_H
  31. #define TINYDAV_CODEC_H264_CUDA_H
  32. #include "tinydav_config.h"
  33. #if HAVE_CUDA
  34. #include "tinydav/codecs/h264/tdav_codec_h264_common.h"
  35. // I really don't want to use C++ code :(
  36. #if !defined(__cplusplus)
  37. typedef enum NVVE_FrameRate NVVE_FrameRate;
  38. typedef enum NVVE_GPUOffloadLevel NVVE_GPUOffloadLevel;
  39. typedef enum NVVE_ASPECT_RATIO_TYPE NVVE_ASPECT_RATIO_TYPE;
  40. typedef enum NVVE_SurfaceFormat NVVE_SurfaceFormat;
  41. typedef enum NVVE_PicStruct NVVE_PicStruct;
  42. typedef enum NVVE_FIELD_MODE NVVE_FIELD_MODE;
  43. typedef enum NVVE_RateCtrlType NVVE_RateCtrlType;
  44. typedef enum NVVE_DI_MODE NVVE_DI_MODE;
  45. typedef enum NVVE_PRESETS_TARGET NVVE_PRESETS_TARGET;
  46. typedef enum NVVE_DI_MODE NVVE_DI_MODE;
  47. typedef struct NVEncoderParams NVEncoderParams;
  48. #endif /* __cplusplus */
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51. #include <windows.h>
  52. #include <unknwn.h>
  53. #include <nvcuvid.h>
  54. #include <cuviddec.h>
  55. #include <NVEncoderAPI.h>
  56. #include <NVEncodeDataTypes.h>
  57. #include <d3d9.h>
  58. #include <cudad3d9.h>
  59. #include <cuda/types.h>
  60. #include "tsk_mutex.h"
  61. TDAV_BEGIN_DECLS
  62. typedef struct tdav_codec_h264_cuda_s {
  63. TDAV_DECLARE_CODEC_H264_COMMON;
  64. struct {
  65. NVEncoder context;
  66. NVEncoderParams ctx_params;
  67. NVVE_CallbackParams clb_params;
  68. void *buffer;
  69. tsk_size_t buffer_size;
  70. int64_t frame_count;
  71. } encoder;
  72. struct {
  73. tsk_mutex_handle_t *mutex;
  74. CUvideodecoder context;
  75. CUVIDDECODECREATEINFO info;
  76. CUvideoparser cu_parser;
  77. CUVIDPARSERPARAMS cu_paser_params;
  78. CUdevice cu_device;
  79. IDirect3D9 *dx_d3d;
  80. IDirect3DDevice9 *dx_d3ddevice;
  81. CUcontext cu_context;
  82. void* accumulator;
  83. tsk_size_t accumulator_pos;
  84. tsk_size_t accumulator_size;
  85. void *cu_buffer;
  86. tsk_size_t cu_buffer_size;
  87. tsk_size_t cu_buffer_pitch;
  88. tsk_bool_t cu_buffer_avail;
  89. uint16_t last_seq;
  90. } decoder;
  91. }
  92. tdav_codec_h264_cuda_t;
  93. TINYDAV_GEXTERN const tmedia_codec_plugin_def_t *tdav_codec_h264_cuda_bp10_plugin_def_t;
  94. TINYDAV_GEXTERN const tmedia_codec_plugin_def_t *tdav_codec_h264_cuda_bp20_plugin_def_t;
  95. TINYDAV_GEXTERN const tmedia_codec_plugin_def_t *tdav_codec_h264_cuda_bp30_plugin_def_t;
  96. tsk_bool_t tdav_codec_h264_cuda_is_supported();
  97. static inline tsk_bool_t tdav_codec_h264_is_cuda_plugin(const tmedia_codec_plugin_def_t *plugin)
  98. {
  99. if(plugin && (plugin == tdav_codec_h264_cuda_bp10_plugin_def_t || plugin == tdav_codec_h264_cuda_bp20_plugin_def_t || plugin == tdav_codec_h264_cuda_bp30_plugin_def_t)) {
  100. return tsk_true;
  101. }
  102. return tsk_false;
  103. }
  104. TDAV_END_DECLS
  105. #endif /* HAVE_CUDA */
  106. #endif /* TINYDAV_CODEC_H264_CUDA_H */