v4l2-decoder.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. Copyright (C) 2020 by Morten Bøgeskov <source@kosmisk.dk>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #pragma once
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <libavcodec/avcodec.h>
  19. #include <libavformat/avformat.h>
  20. #include <libavutil/pixfmt.h>
  21. /**
  22. * Data structure for decoder
  23. */
  24. struct v4l2_decoder {
  25. const AVCodec *codec;
  26. AVCodecContext *context;
  27. AVPacket *packet;
  28. AVFrame *frame;
  29. };
  30. /**
  31. * Initialize the decoder.
  32. * The decoder must be destroyed on failure.
  33. *
  34. * @param decoder the decoder structure
  35. * @param pixfmt which codec is used
  36. * @return non-zero on failure
  37. */
  38. int v4l2_init_decoder(struct v4l2_decoder *decoder, int pixfmt);
  39. /**
  40. * Free any data associated with the decoder.
  41. *
  42. * @param decoder the decoder structure
  43. */
  44. void v4l2_destroy_decoder(struct v4l2_decoder *decoder);
  45. /**
  46. * Decode a jpeg or h264 frame into an obs frame
  47. *
  48. * @param out the obs frame to decode into
  49. * @param data the codec data
  50. * @param length length of the data
  51. * @param decoder the decoder as initialized by v4l2_init_decoder
  52. * @return non-zero on failure
  53. */
  54. int v4l2_decode_frame(struct obs_source_frame *out, uint8_t *data, size_t length, struct v4l2_decoder *decoder);
  55. #ifdef __cplusplus
  56. }
  57. #endif