Changeset 3493 for pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-codec/h263_packetizer.h
- Timestamp:
- Mar 31, 2011 5:29:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-codec/h263_packetizer.h
r3486 r3493 23 23 /** 24 24 * @file h263_packetizer.h 25 * @brief Packetizes H.263 bitstream into RTP payload.25 * @brief Packetizes/unpacketizes H.263 bitstream into RTP payload. 26 26 */ 27 27 28 #include <pj/errno.h> 28 #include <pj/pool.h> 29 #include <pj/types.h> 29 30 30 31 PJ_BEGIN_DECL 31 32 32 /**33 * Find synchronization point (PSC, slice, GSBC, EOS, EOSBS) in H.26334 * bitstream, in reversed manner.35 */36 PJ_INLINE(pj_uint8_t*) pjmedia_h263_find_sync_point_rev(pj_uint8_t *data,37 pj_size_t data_len)38 {39 pj_uint8_t *p = data+data_len-1;40 41 while (p > data && *p && *(p+1))42 --p;43 44 if (p == data)45 return (data + data_len);46 47 return p;48 }49 33 50 34 /** 51 * Generate an RTP payload from H.263 frame bitstream, in-place processing.35 * Opaque declaration for H.263 packetizer. 52 36 */ 53 PJ_INLINE(pj_status_t) pjmedia_h263_packetize(pj_uint8_t *buf, 54 pj_size_t buf_len, 55 unsigned *pos, 56 int max_payload_len, 57 const pj_uint8_t **payload, 58 pj_size_t *payload_len) 59 { 60 pj_uint8_t *p, *p_end; 37 typedef struct pjmedia_h263_packetizer pjmedia_h263_packetizer; 61 38 62 p = buf + *pos;63 p_end = buf + buf_len;64 65 /* Put two octets payload header */66 if ((p_end-p > 2) && *p==0 && *(p+1)==0) {67 /* The bitstream starts with synchronization point, just override68 * the two zero octets (sync point mark) for payload header.69 */70 *p = 0x04;71 } else {72 /* Not started in synchronization point, we will use two octets73 * preceeding the bitstream for payload header!74 */75 76 if (*pos < 2) {77 /* Invalid H263 bitstream, it's not started with PSC */78 return PJ_EINVAL;79 }80 81 p -= 2;82 *p = 0;83 }84 *(p+1) = 0;85 86 /* When bitstream truncation needed because of payload length/MTU87 * limitation, try to use sync point for the payload boundary.88 */89 if (p_end-p > max_payload_len) {90 p_end = pjmedia_h263_find_sync_point_rev(p+2, max_payload_len-2);91 }92 93 *payload = p;94 *payload_len = p_end-p;95 *pos = p_end - buf;96 97 return PJ_SUCCESS;98 }99 39 100 40 /** 101 * Append RTP payload to a H.263 picture bitstream.41 * Enumeration of H.263 packetization modes. 102 42 */ 103 PJ_INLINE(pj_status_t) pjmedia_h263_unpacketize(const pj_uint8_t *payload, 104 pj_size_t payload_len, 105 pj_uint8_t *bits, 106 pj_size_t *bits_len) 43 typedef enum 107 44 { 108 pj_uint8_t P, V, PLEN; 109 const pj_uint8_t *p=payload; 110 pj_size_t max_len = *bits_len; 45 /** 46 * H.263 RTP packetization using RFC 4629. 47 */ 48 PJMEDIA_H263_PACKETIZER_MODE_RFC4629, 111 49 112 P = *p & 0x04; 113 V = *p & 0x02; 114 PLEN = ((*p & 0x01) << 5) + ((*(p+1) & 0xF8)>>3); 50 /** 51 * H.263 RTP packetization using legacy RFC 2190. 52 * This is currently not supported. 53 */ 54 PJMEDIA_H263_PACKETIZER_MODE_RFC2190, 115 55 116 /* Get bitstream pointer */ 117 p += 2; 118 if (V) 119 p += 1; /* Skip VRC data */ 120 if (PLEN) 121 p += PLEN; /* Skip extra picture header data */ 56 } pjmedia_h263_packetizer_mode; 122 57 123 /* Get bitstream length */124 payload_len -= (p-payload);125 58 126 *bits_len = payload_len + (P?2:0); 127 PJ_ASSERT_RETURN(max_len >= *bits_len, PJ_ETOOSMALL); 59 /** 60 * H.263 packetizer configuration. 61 */ 62 typedef struct pjmedia_h263_packetizer_cfg 63 { 64 /** 65 * Maximum payload length. 66 * Default: PJMEDIA_MAX_MTU 67 */ 68 int mtu; 128 69 129 /* Add two zero octets when payload flagged with sync point */130 if (P) {131 *bits++ = 0;132 *bits++ = 0;133 }70 /** 71 * Packetization mode. 72 * Default: PJMEDIA_H263_PACKETIZER_MODE_RFC4629 73 */ 74 pjmedia_h263_packetizer_mode mode; 134 75 135 /* Add the bitstream */ 136 pj_memcpy(bits, p, payload_len); 76 } pjmedia_h263_packetizer_cfg; 137 77 138 return PJ_SUCCESS; 139 } 78 79 /** 80 * Create H.263 packetizer. 81 * 82 * @param pool The memory pool. 83 * @param cfg Packetizer settings, if NULL, default setting 84 * will be used. 85 * @param p_pktz Pointer to receive the packetizer. 86 * 87 * @return PJ_SUCCESS on success. 88 */ 89 PJ_DECL(pj_status_t) pjmedia_h263_packetizer_create( 90 pj_pool_t *pool, 91 const pjmedia_h263_packetizer_cfg *cfg, 92 pjmedia_h263_packetizer **p_pktz); 93 94 95 /** 96 * Generate an RTP payload from a H.263 picture bitstream. Note that this 97 * function will apply in-place processing, so the bitstream may be modified 98 * during the packetization. 99 * 100 * @param pktz The packetizer. 101 * @param bits The picture bitstream to be packetized. 102 * @param bits_len The length of the bitstream. 103 * @param bits_pos The bitstream offset to be packetized. 104 * @param payload The output payload. 105 * @param payload_len The output payload length. 106 * 107 * @return PJ_SUCCESS on success. 108 */ 109 PJ_DECL(pj_status_t) pjmedia_h263_packetize(pjmedia_h263_packetizer *pktz, 110 pj_uint8_t *bits, 111 pj_size_t bits_len, 112 unsigned *bits_pos, 113 const pj_uint8_t **payload, 114 pj_size_t *payload_len); 115 116 117 /** 118 * Append an RTP payload to an H.263 picture bitstream. Note that in case of 119 * noticing packet lost, application should keep calling this function with 120 * payload pointer set to NULL, as the packetizer need to update its internal 121 * state. 122 * 123 * @param pktz The packetizer. 124 * @param payload The payload to be unpacketized. 125 * @param payload_len The payload length. 126 * @param bits The bitstream buffer. 127 * @param bits_size The bitstream buffer size. 128 * @param bits_pos The bitstream offset to put the unpacketized payload 129 * in the bitstream, upon return, this will be updated 130 * to the latest offset as a result of the unpacketized 131 * payload. 132 * 133 * @return PJ_SUCCESS on success. 134 */ 135 PJ_DECL(pj_status_t) pjmedia_h263_unpacketize(pjmedia_h263_packetizer *pktz, 136 const pj_uint8_t *payload, 137 pj_size_t payload_len, 138 pj_uint8_t *bits, 139 pj_size_t bits_size, 140 unsigned *bits_pos); 140 141 141 142
Note: See TracChangeset
for help on using the changeset viewer.