video-frame.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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, enum video_format format, uint32_t width, uint32_t height);
  25. static inline void video_frame_free(struct video_frame *frame)
  26. {
  27. if (frame) {
  28. bfree(frame->data[0]);
  29. memset(frame, 0, sizeof(struct video_frame));
  30. }
  31. }
  32. static inline struct video_frame *video_frame_create(enum video_format format, uint32_t width, uint32_t height)
  33. {
  34. struct video_frame *frame;
  35. frame = (struct video_frame *)bzalloc(sizeof(struct video_frame));
  36. video_frame_init(frame, format, width, height);
  37. return frame;
  38. }
  39. static inline void video_frame_destroy(struct video_frame *frame)
  40. {
  41. if (frame) {
  42. bfree(frame->data[0]);
  43. bfree(frame);
  44. }
  45. }
  46. EXPORT void video_frame_copy(struct video_frame *dst, const struct video_frame *src, enum video_format format,
  47. uint32_t height);
  48. #ifdef __cplusplus
  49. }
  50. #endif