blob: a676a04b8a047a97bc572fe1715e4db650bbab54 [file] [log] [blame]
Nanang Izzuddind91af572011-03-31 17:29:54 +00001/* $Id$ */
2/*
3 * Copyright (C) 2011 Teluu Inc. (http://www.teluu.com)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __PJMEDIA_H264_PACKETIZER_H__
20#define __PJMEDIA_H264_PACKETIZER_H__
21
22/**
23 * @file h264_packetizer.h
24 * @brief Packetizes H.264 bitstream into RTP payload and vice versa.
25 */
26
27#include <pj/types.h>
28
29PJ_BEGIN_DECL
30
31/**
32 * Opaque declaration for H.264 packetizer.
33 */
34typedef struct pjmedia_h264_packetizer pjmedia_h264_packetizer;
35
36
37/**
38 * Enumeration of H.264 packetization modes.
39 */
40typedef enum
41{
42 /**
43 * Single NAL unit packetization mode will only generate payloads
44 * containing a complete single NAL unit packet. As H.264 NAL unit
45 * size can be very large, this mode is usually not applicable for
46 * network environments with MTU size limitation.
47 */
48 PJMEDIA_H264_PACKETIZER_MODE_SINGLE_NAL,
49
50 /**
51 * Non-interleaved packetization mode will generate payloads with the
52 * following possible formats:
53 * - single NAL unit packets,
54 * - NAL units aggregation STAP-A packets,
55 * - fragmented NAL unit FU-A packets.
56 */
57 PJMEDIA_H264_PACKETIZER_MODE_NON_INTERLEAVED,
58
59 /**
60 * Interleaved packetization mode will generate payloads with the
61 * following possible formats:
62 * - single NAL unit packets,
63 * - NAL units aggregation STAP-A & STAP-B packets,
64 * - fragmented NAL unit FU-A & FU-B packets.
65 * This packetization mode is currently unsupported.
66 */
67 PJMEDIA_H264_PACKETIZER_MODE_INTERLEAVED,
68} pjmedia_h264_packetizer_mode;
69
70
71/**
72 * H.264 packetizer setting.
73 */
74typedef struct pjmedia_h264_packetizer_cfg
75{
76 /**
77 * Maximum payload length.
78 * Default: PJMEDIA_MAX_MTU
79 */
80 int mtu;
81
82 /**
83 * Packetization mode.
84 * Default: PJMEDIA_H264_PACKETIZER_MODE_NON_INTERLEAVED
85 */
86 pjmedia_h264_packetizer_mode mode;
87}
88pjmedia_h264_packetizer_cfg;
89
90
91/**
92 * Create H.264 packetizer.
93 *
94 * @param pool The memory pool.
95 * @param cfg Packetizer settings, if NULL, default setting
96 * will be used.
97 * @param p_pktz Pointer to receive the packetizer.
98 *
99 * @return PJ_SUCCESS on success.
100 */
101PJ_DECL(pj_status_t) pjmedia_h264_packetizer_create(
102 pj_pool_t *pool,
103 const pjmedia_h264_packetizer_cfg *cfg,
104 pjmedia_h264_packetizer **p_pktz);
105
106
107/**
108 * Generate an RTP payload from a H.264 picture bitstream. Note that this
109 * function will apply in-place processing, so the bitstream may be modified
110 * during the packetization.
111 *
112 * @param pktz The packetizer.
113 * @param bits The picture bitstream to be packetized.
114 * @param bits_len The length of the bitstream.
115 * @param bits_pos The bitstream offset to be packetized.
116 * @param payload The output payload.
117 * @param payload_len The output payload length.
118 *
119 * @return PJ_SUCCESS on success.
120 */
121PJ_DECL(pj_status_t) pjmedia_h264_packetize(pjmedia_h264_packetizer *pktz,
122 pj_uint8_t *bits,
123 pj_size_t bits_len,
124 unsigned *bits_pos,
125 const pj_uint8_t **payload,
126 pj_size_t *payload_len);
127
128
129/**
130 * Append an RTP payload to an H.264 picture bitstream. Note that in case of
131 * noticing packet lost, application should keep calling this function with
132 * payload pointer set to NULL, as the packetizer need to update its internal
133 * state.
134 *
135 * @param pktz The packetizer.
136 * @param payload The payload to be unpacketized.
137 * @param payload_len The payload length.
138 * @param bits The bitstream buffer.
139 * @param bits_size The bitstream buffer size.
140 * @param bits_pos The bitstream offset to put the unpacketized payload
141 * in the bitstream, upon return, this will be updated
142 * to the latest offset as a result of the unpacketized
143 * payload.
144 *
145 * @return PJ_SUCCESS on success.
146 */
147PJ_DECL(pj_status_t) pjmedia_h264_unpacketize(pjmedia_h264_packetizer *pktz,
148 const pj_uint8_t *payload,
149 pj_size_t payload_len,
150 pj_uint8_t *bits,
151 pj_size_t bits_len,
152 unsigned *bits_pos);
153
154
155PJ_END_DECL
156
157#endif /* __PJMEDIA_H264_PACKETIZER_H__ */