| 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 | |
| 21 | #include <pjmedia/converter.h> |
| 22 | #include <pjmedia/format.h> |
| 23 | #include <pjmedia/types.h> |
| 24 | |
| 25 | /* |
| 26 | * Video device utility functions to resize and rotate video frames. |
| 27 | */ |
| 28 | |
| 29 | typedef struct pjmedia_vid_dev_conv |
| 30 | { |
| 31 | pjmedia_converter *conv; |
| 32 | pjmedia_format fmt; |
| 33 | pjmedia_rect_size src_size; |
| 34 | pjmedia_rect_size dst_size; |
| 35 | pjmedia_rect_size res_size; /* Size after resizing */ |
| 36 | pjmedia_orient rotation; |
| 37 | pjmedia_rect_size rot_size; /* Size after rotation */ |
| 38 | |
| 39 | void *conv_buf; |
| 40 | pj_size_t src_frame_size; |
| 41 | pj_size_t conv_frame_size; |
| 42 | |
| 43 | pj_bool_t fit_to_h; |
| 44 | pj_bool_t handle_rotation; |
| 45 | pj_bool_t maintain_aspect_ratio; |
| 46 | pj_bool_t match_src_dst; |
| 47 | pj_int32_t pad; |
| 48 | pj_size_t wxh; |
| 49 | } pjmedia_vid_dev_conv; |
| 50 | |
| 51 | /** |
| 52 | * Create converter. |
| 53 | * The process: |
| 54 | * frame --> resize --> rotate --> center |
| 55 | * (if handle_rotation (if maintain_aspect_ratio |
| 56 | * == PJ_TRUE) == PJ_TRUE) |
| 57 | * |
| 58 | * handle_rotation will specify whether the converter will need to do the |
| 59 | * rotation as well. If PJ_FALSE, the video device will handle the rotation |
| 60 | * and pass the already-rotated frame. |
| 61 | * |
| 62 | * maintain_aspect_ratio defines whether aspect ratio should be maintained |
| 63 | * when rotating the image. |
| 64 | * If PJ_TRUE, a frame of size w x h will be resized and rotated to |
| 65 | * a new frame of size new_w x new_h (new_h and new_h have the same |
| 66 | * aspect ratio as w x h). Then the new frame will be centered-fit into |
| 67 | * the original frame with black area inserted to fill the gaps. |
| 68 | * Disabling this setting will only resize the frame of size w x h to h x w, |
| 69 | * and then rotate it to fit the original size of w x h. It will achieve |
| 70 | * a slightly faster performance but the resulting image will be stretched. |
| 71 | * The feature to maintain aspect ratio is only supported for certain formats |
| 72 | * (currently, only if fmt.id equals to I420). |
| 73 | */ |
| 74 | pj_status_t |
| 75 | pjmedia_vid_dev_conv_create_converter(pjmedia_vid_dev_conv *conv, |
| 76 | pj_pool_t *pool, |
| 77 | pjmedia_format *fmt, |
| 78 | pjmedia_rect_size src_size, |
| 79 | pjmedia_rect_size dst_size, |
| 80 | pj_bool_t handle_rotation, |
| 81 | pj_bool_t maintain_aspect_ratio); |
| 82 | |
| 83 | /* Set rotation */ |
| 84 | void pjmedia_vid_dev_conv_set_rotation(pjmedia_vid_dev_conv *conv, |
| 85 | pjmedia_orient rotation); |
| 86 | |
| 87 | /* Resize the buffer and rotate it, if necessary */ |
| 88 | pj_status_t pjmedia_vid_dev_conv_resize_and_rotate(pjmedia_vid_dev_conv *conv, |
| 89 | void *src_buf, |
| 90 | void **result); |
| 91 | |
| 92 | /* Destroy converter */ |
| 93 | void pjmedia_vid_dev_conv_destroy_converter(pjmedia_vid_dev_conv *conv); |
| 94 | |
| 95 | #endif /* __PJMEDIA_VIDEODEV_UTIL_H__ */ |