video_decode.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (c) 2016-2019, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of NVIDIA CORPORATION nor the names of its
  13. * contributors may be used to endorse or promote products derived
  14. * from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  24. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #include "NvVideoDecoder.h"
  29. #include "NvVideoConverter.h"
  30. #include "NvEglRenderer.h"
  31. #include <queue>
  32. #include <fstream>
  33. #include <pthread.h>
  34. #include <semaphore.h>
  35. #define USE_NVBUF_TRANSFORM_API
  36. #define MAX_BUFFERS 32
  37. typedef struct
  38. {
  39. NvVideoDecoder *dec;
  40. NvVideoConverter *conv;
  41. uint32_t decoder_pixfmt;
  42. NvEglRenderer *renderer;
  43. char **in_file_path;
  44. std::ifstream **in_file;
  45. char *out_file_path;
  46. std::ofstream *out_file;
  47. bool disable_rendering;
  48. bool fullscreen;
  49. uint32_t window_height;
  50. uint32_t window_width;
  51. uint32_t window_x;
  52. uint32_t window_y;
  53. uint32_t out_pixfmt;
  54. uint32_t video_height;
  55. uint32_t video_width;
  56. uint32_t display_height;
  57. uint32_t display_width;
  58. uint32_t file_count;
  59. float fps;
  60. bool disable_dpb;
  61. bool input_nalu;
  62. bool copy_timestamp;
  63. bool flag_copyts;
  64. uint32_t start_ts;
  65. float dec_fps;
  66. uint64_t timestamp;
  67. uint64_t timestampincr;
  68. bool stats;
  69. int stress_test;
  70. bool enable_metadata;
  71. bool bLoop;
  72. bool bQueue;
  73. bool enable_input_metadata;
  74. enum v4l2_skip_frames_type skip_frames;
  75. enum v4l2_memory output_plane_mem_type;
  76. enum v4l2_memory capture_plane_mem_type;
  77. #ifndef USE_NVBUF_TRANSFORM_API
  78. enum v4l2_yuv_rescale_method rescale_method;
  79. #endif
  80. std::queue < NvBuffer * > *conv_output_plane_buf_queue;
  81. pthread_mutex_t queue_lock;
  82. pthread_cond_t queue_cond;
  83. sem_t pollthread_sema; // Polling thread waits on this to be signalled to issue Poll
  84. sem_t decoderthread_sema; // Decoder thread waits on this to be signalled to continue q/dq loop
  85. pthread_t dec_pollthread; // Polling thread, created if running in non-blocking mode.
  86. pthread_t dec_capture_loop; // Decoder capture thread, created if running in blocking mode.
  87. bool got_error;
  88. bool got_eos;
  89. bool vp9_file_header_flag;
  90. bool vp8_file_header_flag;
  91. int dst_dma_fd;
  92. int dmabuff_fd[MAX_BUFFERS];
  93. int numCapBuffers;
  94. int loop_count;
  95. int max_perf;
  96. int extra_cap_plane_buffer;
  97. int blocking_mode; // Set to true if running in blocking mode
  98. } context_t;
  99. int parse_csv_args(context_t * ctx, int argc, char *argv[]);