h264_packetizer.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (C) 2011 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_H264_PACKETIZER_H__
  19. #define __PJMEDIA_H264_PACKETIZER_H__
  20. /**
  21. * @file h264_packetizer.h
  22. * @brief Packetizes H.264 bitstream into RTP payload and vice versa.
  23. */
  24. #include <pj/types.h>
  25. PJ_BEGIN_DECL
  26. /**
  27. * Opaque declaration for H.264 packetizer.
  28. */
  29. typedef struct pjmedia_h264_packetizer pjmedia_h264_packetizer;
  30. /**
  31. * Enumeration of H.264 packetization modes.
  32. */
  33. typedef enum
  34. {
  35. /**
  36. * Single NAL unit packetization mode will only generate payloads
  37. * containing a complete single NAL unit packet. As H.264 NAL unit
  38. * size can be very large, this mode is usually not applicable for
  39. * network environments with MTU size limitation.
  40. */
  41. PJMEDIA_H264_PACKETIZER_MODE_SINGLE_NAL,
  42. /**
  43. * Non-interleaved packetization mode will generate payloads with the
  44. * following possible formats:
  45. * - single NAL unit packets,
  46. * - NAL units aggregation STAP-A packets,
  47. * - fragmented NAL unit FU-A packets.
  48. */
  49. PJMEDIA_H264_PACKETIZER_MODE_NON_INTERLEAVED,
  50. /**
  51. * Interleaved packetization mode will generate payloads with the
  52. * following possible formats:
  53. * - single NAL unit packets,
  54. * - NAL units aggregation STAP-A & STAP-B packets,
  55. * - fragmented NAL unit FU-A & FU-B packets.
  56. * This packetization mode is currently unsupported.
  57. */
  58. PJMEDIA_H264_PACKETIZER_MODE_INTERLEAVED,
  59. } pjmedia_h264_packetizer_mode;
  60. /**
  61. * H.264 packetizer setting.
  62. */
  63. typedef struct pjmedia_h264_packetizer_cfg
  64. {
  65. /**
  66. * Maximum payload length.
  67. * Default: PJMEDIA_MAX_MTU
  68. */
  69. int mtu;
  70. /**
  71. * Packetization mode.
  72. * Default: PJMEDIA_H264_PACKETIZER_MODE_NON_INTERLEAVED
  73. */
  74. pjmedia_h264_packetizer_mode mode;
  75. /**
  76. * NAL start code size used for unpacketizing.
  77. * Valid options are 3 (0, 0, 1) or 4 (0, 0, 0, 1).
  78. * Default: 3 (0, 0, 1)
  79. */
  80. unsigned unpack_nal_start;
  81. }
  82. pjmedia_h264_packetizer_cfg;
  83. /**
  84. * Create H.264 packetizer.
  85. *
  86. * @param pool The memory pool.
  87. * @param cfg Packetizer settings, if NULL, default setting
  88. * will be used.
  89. * @param p_pktz Pointer to receive the packetizer.
  90. *
  91. * @return PJ_SUCCESS on success.
  92. */
  93. PJ_DECL(pj_status_t) pjmedia_h264_packetizer_create(
  94. pj_pool_t *pool,
  95. const pjmedia_h264_packetizer_cfg *cfg,
  96. pjmedia_h264_packetizer **p_pktz);
  97. /**
  98. * Generate an RTP payload from a H.264 picture bitstream. Note that this
  99. * function will apply in-place processing, so the bitstream may be modified
  100. * during the packetization.
  101. *
  102. * @param pktz The packetizer.
  103. * @param bits The picture bitstream to be packetized.
  104. * @param bits_len The length of the bitstream.
  105. * @param bits_pos The bitstream offset to be packetized.
  106. * @param payload The output payload.
  107. * @param payload_len The output payload length.
  108. *
  109. * @return PJ_SUCCESS on success.
  110. */
  111. PJ_DECL(pj_status_t) pjmedia_h264_packetize(pjmedia_h264_packetizer *pktz,
  112. pj_uint8_t *bits,
  113. pj_size_t bits_len,
  114. unsigned *bits_pos,
  115. const pj_uint8_t **payload,
  116. pj_size_t *payload_len);
  117. /**
  118. * Append an RTP payload to an H.264 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_len 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_h264_unpacketize(pjmedia_h264_packetizer *pktz,
  136. const pj_uint8_t *payload,
  137. pj_size_t payload_len,
  138. pj_uint8_t *bits,
  139. pj_size_t bits_len,
  140. unsigned *bits_pos);
  141. PJ_END_DECL
  142. #endif /* __PJMEDIA_H264_PACKETIZER_H__ */