| 1 | /* |
| 2 | * Copyright (C) 2020 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_VPX_PACKETIZER_H__ |
| 19 | #define __PJMEDIA_VPX_PACKETIZER_H__ |
| 20 | |
| 21 | /** |
| 22 | * @file vpx_packetizer.h |
| 23 | * @brief Packetizes VPX bitstream into RTP payload and vice versa. |
| 24 | */ |
| 25 | |
| 26 | #include <pj/types.h> |
| 27 | |
| 28 | PJ_BEGIN_DECL |
| 29 | |
| 30 | /** |
| 31 | * Opaque declaration for VPX packetizer. |
| 32 | */ |
| 33 | typedef struct pjmedia_vpx_packetizer pjmedia_vpx_packetizer; |
| 34 | |
| 35 | |
| 36 | /** |
| 37 | * VPX packetizer setting. |
| 38 | */ |
| 39 | typedef struct pjmedia_vpx_packetizer_cfg |
| 40 | { |
| 41 | /** |
| 42 | * VPX format id. |
| 43 | * Default: PJMEDIA_FORMAT_VP8 |
| 44 | */ |
| 45 | pj_uint32_t fmt_id; |
| 46 | |
| 47 | /** |
| 48 | * MTU size. |
| 49 | * Default: PJMEDIA_MAX_VID_PAYLOAD_SIZE |
| 50 | */ |
| 51 | unsigned mtu; |
| 52 | } |
| 53 | pjmedia_vpx_packetizer_cfg; |
| 54 | |
| 55 | /** |
| 56 | * Use this function to initialize VPX packetizer config. |
| 57 | * |
| 58 | * @param cfg The VPX packetizer config to be initialized. |
| 59 | */ |
| 60 | PJ_DECL(void) pjmedia_vpx_packetizer_cfg_default( |
| 61 | pjmedia_vpx_packetizer_cfg *cfg); |
| 62 | |
| 63 | |
| 64 | /** |
| 65 | * Create VPX packetizer. |
| 66 | * |
| 67 | * @param pool The memory pool. |
| 68 | * @param cfg Packetizer settings, if NULL, default setting |
| 69 | * will be used. |
| 70 | * @param p_pktz Pointer to receive the packetizer. |
| 71 | * |
| 72 | * @return PJ_SUCCESS on success. |
| 73 | */ |
| 74 | PJ_DECL(pj_status_t) pjmedia_vpx_packetizer_create( |
| 75 | pj_pool_t *pool, |
| 76 | const pjmedia_vpx_packetizer_cfg *cfg, |
| 77 | pjmedia_vpx_packetizer **p_pktz); |
| 78 | |
| 79 | |
| 80 | /** |
| 81 | * Generate an RTP payload from a VPX picture bitstream. Note that this |
| 82 | * function will apply in-place processing, so the bitstream may be modified |
| 83 | * during the packetization. |
| 84 | * |
| 85 | * @param pktz The packetizer. |
| 86 | * @param bits_len The length of the bitstream. |
| 87 | * @param bits_pos The bitstream offset to be packetized. |
| 88 | * @param is_keyframe The frame is keyframe. |
| 89 | * @param payload The output payload. |
| 90 | * @param payload_len The output payload length, on input it represents max |
| 91 | * payload length. |
| 92 | * |
| 93 | * @return PJ_SUCCESS on success. |
| 94 | */ |
| 95 | PJ_DECL(pj_status_t) pjmedia_vpx_packetize(const pjmedia_vpx_packetizer *pktz, |
| 96 | pj_size_t bits_len, |
| 97 | unsigned *bits_pos, |
| 98 | pj_bool_t is_keyframe, |
| 99 | pj_uint8_t **payload, |
| 100 | pj_size_t *payload_len); |
| 101 | |
| 102 | |
| 103 | /** |
| 104 | * Append an RTP payload to an VPX picture bitstream. Note that in case of |
| 105 | * noticing packet lost, application should keep calling this function with |
| 106 | * payload pointer set to NULL, as the packetizer need to update its internal |
| 107 | * state. |
| 108 | * |
| 109 | * @param pktz The packetizer. |
| 110 | * @param payload The payload to be unpacketized. |
| 111 | * @param payload_len The payload length. |
| 112 | * @param payload_desc_len The payload description length. |
| 113 | * |
| 114 | * @return PJ_SUCCESS on success. |
| 115 | */ |
| 116 | PJ_DECL(pj_status_t) pjmedia_vpx_unpacketize(pjmedia_vpx_packetizer *pktz, |
| 117 | const pj_uint8_t *payload, |
| 118 | pj_size_t payload_len, |
| 119 | unsigned *payload_desc_len); |
| 120 | |
| 121 | PJ_END_DECL |
| 122 | |
| 123 | #endif /* __PJMEDIA_VPX_PACKETIZER_H__ */ |