v4l2-mjpeg.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. Copyright (C) 2020 by Morten Bøgeskov <[email protected]>
  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 mjpeg decoding
  23. */
  24. struct v4l2_mjpeg_decoder {
  25. AVCodec *codec;
  26. AVCodecContext *context;
  27. AVPacket *packet;
  28. AVFrame *frame;
  29. };
  30. /**
  31. * Initialize the mjpeg decoder.
  32. * The decoder must be destroyed on failure.
  33. *
  34. * @param props the decoder structure
  35. * @return non-zero on failure
  36. */
  37. int v4l2_init_mjpeg(struct v4l2_mjpeg_decoder *decoder);
  38. /**
  39. * Free any data associated with the decoder.
  40. *
  41. * @param decoder the decoder structure
  42. */
  43. void v4l2_destroy_mjpeg(struct v4l2_mjpeg_decoder *decoder);
  44. /**
  45. * Decode a jpeg into an obs frame
  46. *
  47. * @param out the obs frame to decode into
  48. * @param data the jpeg data
  49. * @param length length of the data
  50. * @param decoder the decoder as initialized by v4l2_init_mjpeg
  51. * @return non-zero on failure
  52. */
  53. int v4l2_decode_mjpeg(struct obs_source_frame *out, uint8_t *data,
  54. size_t length, struct v4l2_mjpeg_decoder *decoder);
  55. #ifdef __cplusplus
  56. }
  57. #endif