video-frame.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain Bailey <[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. #include "../util/bmem.h"
  16. #include "video-io.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. struct video_frame {
  21. uint8_t *data[MAX_AV_PLANES];
  22. uint32_t linesize[MAX_AV_PLANES];
  23. };
  24. EXPORT void video_frame_init(struct video_frame *frame,
  25. enum video_format format, uint32_t width,
  26. uint32_t height);
  27. static inline void video_frame_free(struct video_frame *frame)
  28. {
  29. if (frame) {
  30. bfree(frame->data[0]);
  31. memset(frame, 0, sizeof(struct video_frame));
  32. }
  33. }
  34. static inline struct video_frame *
  35. video_frame_create(enum video_format format, uint32_t width, uint32_t height)
  36. {
  37. struct video_frame *frame;
  38. frame = (struct video_frame *)bzalloc(sizeof(struct video_frame));
  39. video_frame_init(frame, format, width, height);
  40. return frame;
  41. }
  42. static inline void video_frame_destroy(struct video_frame *frame)
  43. {
  44. if (frame) {
  45. bfree(frame->data[0]);
  46. bfree(frame);
  47. }
  48. }
  49. EXPORT void video_frame_copy(struct video_frame *dst,
  50. const struct video_frame *src,
  51. enum video_format format, uint32_t height);
  52. #ifdef __cplusplus
  53. }
  54. #endif