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.

106 lines
3.1KB

  1. /*
  2. * V4L2 mem2mem 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_M2M_H
  24. #define AVCODEC_V4L2_M2M_H
  25. #include <semaphore.h>
  26. #include <unistd.h>
  27. #include <dirent.h>
  28. #include <linux/videodev2.h>
  29. #include "libavcodec/avcodec.h"
  30. #include "v4l2_context.h"
  31. #define container_of(ptr, type, member) ({ \
  32. const __typeof__(((type *)0)->member ) *__mptr = (ptr); \
  33. (type *)((char *)__mptr - offsetof(type,member) );})
  34. #define V4L_M2M_DEFAULT_OPTS \
  35. { "num_output_buffers", "Number of buffers in the output context",\
  36. OFFSET(output.num_buffers), AV_OPT_TYPE_INT, { .i64 = 16 }, 6, INT_MAX, FLAGS }
  37. typedef struct V4L2m2mContext
  38. {
  39. AVClass *class;
  40. char devname[PATH_MAX];
  41. int fd;
  42. /* the codec context queues */
  43. V4L2Context capture;
  44. V4L2Context output;
  45. /* refcount of buffers held by the user */
  46. atomic_uint refcount;
  47. /* dynamic stream reconfig */
  48. AVCodecContext *avctx;
  49. sem_t refsync;
  50. int reinit;
  51. /* null frame/packet received */
  52. int draining;
  53. } V4L2m2mContext;
  54. /**
  55. * Probes the video nodes looking for the required codec capabilities.
  56. *
  57. * @param[in] ctx The AVCodecContext instantiated by the encoder/decoder.
  58. *
  59. * @returns 0 if a driver is found, a negative number otherwise.
  60. */
  61. int ff_v4l2_m2m_codec_init(AVCodecContext *avctx);
  62. /**
  63. * Releases all the codec resources if all AVBufferRefs have been returned to the
  64. * ctx. Otherwise keep the driver open.
  65. *
  66. * @param[in] The AVCodecContext instantiated by the encoder/decoder.
  67. *
  68. * @returns 0
  69. *
  70. */
  71. int ff_v4l2_m2m_codec_end(AVCodecContext *avctx);
  72. /**
  73. * Reinitializes the V4L2m2mContext when the driver cant continue processing
  74. * with the capture parameters.
  75. *
  76. * @param[in] ctx The V4L2m2mContext instantiated by the encoder/decoder.
  77. *
  78. * @returns 0 in case of success, negative number otherwise
  79. */
  80. int ff_v4l2_m2m_codec_reinit(V4L2m2mContext *ctx);
  81. /**
  82. * Reinitializes the V4L2m2mContext when the driver cant continue processing
  83. * with the any of the current V4L2Contexts (ie, changes in output and capture).
  84. *
  85. * @param[in] ctx The V4L2m2mContext instantiated by the encoder/decoder.
  86. *
  87. * @returns 0 in case of success, negative number otherwise
  88. */
  89. int ff_v4l2_m2m_codec_full_reinit(V4L2m2mContext *ctx);
  90. #endif /* AVCODEC_V4L2_M2M_H */