util.h 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (C) 2014-2015 Teluu Inc. (http://www.teluu.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #ifndef __PJMEDIA_VIDEODEV_UTIL_H__
  19. #define __PJMEDIA_VIDEODEV_UTIL_H__
  20. #include <pjmedia/converter.h>
  21. #include <pjmedia/format.h>
  22. #include <pjmedia/types.h>
  23. /*
  24. * Video device utility functions to resize and rotate video frames.
  25. */
  26. typedef struct pjmedia_vid_dev_conv
  27. {
  28. pjmedia_converter *conv;
  29. pjmedia_format fmt;
  30. pjmedia_rect_size src_size;
  31. pjmedia_rect_size dst_size;
  32. pjmedia_rect_size res_size; /* Size after resizing */
  33. pjmedia_orient rotation;
  34. pjmedia_rect_size rot_size; /* Size after rotation */
  35. void *conv_buf;
  36. pj_size_t src_frame_size;
  37. pj_size_t conv_frame_size;
  38. pj_bool_t fit_to_h;
  39. pj_bool_t handle_rotation;
  40. pj_bool_t maintain_aspect_ratio;
  41. pj_bool_t match_src_dst;
  42. pj_int32_t pad;
  43. pj_size_t wxh;
  44. } pjmedia_vid_dev_conv;
  45. /**
  46. * Create converter.
  47. * The process:
  48. * frame --> resize --> rotate --> center
  49. * (if handle_rotation (if maintain_aspect_ratio
  50. * == PJ_TRUE) == PJ_TRUE)
  51. *
  52. * handle_rotation will specify whether the converter will need to do the
  53. * rotation as well. If PJ_FALSE, the video device will handle the rotation
  54. * and pass the already-rotated frame.
  55. *
  56. * maintain_aspect_ratio defines whether aspect ratio should be maintained
  57. * when rotating the image.
  58. * If PJ_TRUE, a frame of size w x h will be resized and rotated to
  59. * a new frame of size new_w x new_h (new_h and new_h have the same
  60. * aspect ratio as w x h). Then the new frame will be centered-fit into
  61. * the original frame with black area inserted to fill the gaps.
  62. * Disabling this setting will only resize the frame of size w x h to h x w,
  63. * and then rotate it to fit the original size of w x h. It will achieve
  64. * a slightly faster performance but the resulting image will be stretched.
  65. * The feature to maintain aspect ratio is only supported for certain formats
  66. * (currently, only if fmt.id equals to I420).
  67. */
  68. pj_status_t
  69. pjmedia_vid_dev_conv_create_converter(pjmedia_vid_dev_conv *conv,
  70. pj_pool_t *pool,
  71. pjmedia_format *fmt,
  72. pjmedia_rect_size src_size,
  73. pjmedia_rect_size dst_size,
  74. pj_bool_t handle_rotation,
  75. pj_bool_t maintain_aspect_ratio);
  76. /* Set rotation */
  77. void pjmedia_vid_dev_conv_set_rotation(pjmedia_vid_dev_conv *conv,
  78. pjmedia_orient rotation);
  79. /* Resize the buffer and rotate it, if necessary */
  80. pj_status_t pjmedia_vid_dev_conv_resize_and_rotate(pjmedia_vid_dev_conv *conv,
  81. void *src_buf,
  82. void **result);
  83. /* Destroy converter */
  84. void pjmedia_vid_dev_conv_destroy_converter(pjmedia_vid_dev_conv *conv);
  85. #endif /* __PJMEDIA_VIDEODEV_UTIL_H__ */