You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.5KB

  1. /*
  2. * V4L2 buffer helper functions.
  3. *
  4. * Copyright (C) 2017 Alexis Ballier <aballier@gentoo.org>
  5. * Copyright (C) 2017 Jorge Ramirez <jorge.ramirez-ortiz@linaro.org>
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #ifndef AVCODEC_V4L2_BUFFERS_H
  24. #define AVCODEC_V4L2_BUFFERS_H
  25. #include <linux/videodev2.h>
  26. enum V4L2Buffer_status {
  27. V4L2BUF_AVAILABLE,
  28. V4L2BUF_IN_DRIVER,
  29. V4L2BUF_RET_USER,
  30. };
  31. /**
  32. * V4L2Buffer (wrapper for v4l2_buffer management)
  33. */
  34. typedef struct V4L2Buffer {
  35. /* each buffer needs to have a reference to its context */
  36. struct V4L2Context *context;
  37. /* keep track of the mmap address and mmap length */
  38. struct V4L2Plane_info {
  39. int bytesperline;
  40. void * mm_addr;
  41. size_t length;
  42. } plane_info[VIDEO_MAX_PLANES];
  43. int num_planes;
  44. /* the v4l2_buffer buf.m.planes pointer uses the planes[] mem */
  45. struct v4l2_buffer buf;
  46. struct v4l2_plane planes[VIDEO_MAX_PLANES];
  47. int flags;
  48. enum V4L2Buffer_status status;
  49. } V4L2Buffer;
  50. /**
  51. * Extracts the data from a V4L2Buffer to an AVFrame
  52. *
  53. * @param[in] frame The AVFRame to push the information to
  54. * @param[in] buf The V4L2Buffer to get the information from
  55. *
  56. * @returns 0 in case of success, EINVAL if the number of planes is incorrect,
  57. * ENOMEM if the AVBufferRef cant be created.
  58. */
  59. int ff_v4l2_buffer_buf_to_avframe(AVFrame *frame, V4L2Buffer *buf);
  60. /**
  61. * Extracts the data from a V4L2Buffer to an AVPacket
  62. *
  63. * @param[in] pkt The AVPacket to push the information to
  64. * @param[in] buf The V4L2Buffer to get the information from
  65. *
  66. * @returns 0 in case of success, EINVAL if the number of planes is incorrect,
  67. * ENOMEM if the AVBufferRef cant be created.
  68. *
  69. */
  70. int ff_v4l2_buffer_buf_to_avpkt(AVPacket *pkt, V4L2Buffer *buf);
  71. /**
  72. * Extracts the data from an AVPacket to a V4L2Buffer
  73. *
  74. * @param[in] frame AVPacket to get the data from
  75. * @param[in] avbuf V4L2Bfuffer to push the information to
  76. *
  77. * @returns 0 in case of success, negative otherwise
  78. */
  79. int ff_v4l2_buffer_avpkt_to_buf(const AVPacket *pkt, V4L2Buffer *out);
  80. /**
  81. * Extracts the data from an AVFrame to a V4L2Buffer
  82. *
  83. * @param[in] frame AVFrame to get the data from
  84. * @param[in] avbuf V4L2Bfuffer to push the information to
  85. *
  86. * @returns 0 in case of success, negative otherwise
  87. */
  88. int ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, V4L2Buffer* out);
  89. /**
  90. * Initializes a V4L2Buffer
  91. *
  92. * @param[in] avbuf V4L2Bfuffer to initialize
  93. * @param[in] index v4l2 buffer id
  94. *
  95. * @returns 0 in case of success, negative otherwise
  96. */
  97. int ff_v4l2_buffer_initialize(V4L2Buffer* avbuf, int index);
  98. /**
  99. * Enqueues a V4L2Buffer
  100. *
  101. * @param[in] avbuf V4L2Bfuffer to push to the driver
  102. *
  103. * @returns 0 in case of success, negative otherwise
  104. */
  105. int ff_v4l2_buffer_enqueue(V4L2Buffer* avbuf);
  106. #endif // AVCODEC_V4L2_BUFFERS_H