Changeset 3776 for pjproject/trunk/pjmedia/include/pjmedia/vid_codec.h
- Timestamp:
- Sep 29, 2011 8:31:15 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia/vid_codec.h
r3715 r3776 36 36 PJ_BEGIN_DECL 37 37 38 /** 39 * @defgroup PJMEDIA_VID_CODEC Video Codecs 40 * @ingroup PJMEDIA_CODEC 41 * @{ 42 */ 43 38 44 #define PJMEDIA_VID_CODEC_MAX_DEC_FMT_CNT 8 39 45 #define PJMEDIA_VID_CODEC_MAX_FPS_CNT 16 46 47 /** 48 * This enumeration specifies the packetization property of video encoding 49 * process. The value is bitmask, and smaller value will have higher priority 50 * to be used. 51 */ 52 typedef enum pjmedia_vid_packing 53 { 54 /** 55 * This specifies that the packetization is unknown, or if nothing 56 * is supported. 57 */ 58 PJMEDIA_VID_PACKING_UNKNOWN, 59 60 /** 61 * This specifies that the result of video encoding process will be 62 * segmented into packets, which is suitable for RTP transmission. 63 * The maximum size of the packets is set in \a enc_mtu field of 64 * pjmedia_vid_codec_param. 65 */ 66 PJMEDIA_VID_PACKING_PACKETS = 1, 67 68 /** 69 * This specifies that video encoding function will produce a whole 70 * or full frame from the source frame. This is normally used for 71 * encoding video for offline storage such as to an AVI file. The 72 * maximum size of the packets is set in \a enc_mtu field of 73 * pjmedia_vid_codec_param. 74 */ 75 PJMEDIA_VID_PACKING_WHOLE = 2 76 77 } pjmedia_vid_packing; 40 78 41 79 /** … … 56 94 /**< Supported encoding source 57 95 format IDs */ 96 unsigned packings; /**< Supported or requested packings, 97 strategies, bitmask from 98 pjmedia_vid_packing */ 58 99 unsigned fps_cnt; /**< # of supported frame-rates, can be 59 100 zero (support any frame-rate) */ 60 101 pjmedia_ratio fps[PJMEDIA_VID_CODEC_MAX_FPS_CNT]; 61 102 /**< Supported frame-rates */ 62 pj_bool_t has_rtp_pack; /**< Support RTP packetization */ 103 63 104 } pjmedia_vid_codec_info; 64 105 … … 77 118 { 78 119 pjmedia_dir dir; /**< Direction */ 120 pjmedia_vid_packing packing; /**< Packetization strategy. */ 121 79 122 pjmedia_format enc_fmt; /**< Encoded format */ 123 pjmedia_codec_fmtp enc_fmtp; /**< Encoder fmtp params */ 124 unsigned enc_mtu; /**< MTU or max payload size setting*/ 125 80 126 pjmedia_format dec_fmt; /**< Decoded format */ 81 82 pjmedia_codec_fmtp enc_fmtp; /**< Encoder fmtp params */83 127 pjmedia_codec_fmtp dec_fmtp; /**< Decoder fmtp params */ 84 128 85 unsigned enc_mtu; /**< MTU or max payload size setting*/86 129 } pjmedia_vid_codec_param; 87 130 … … 112 155 { 113 156 /** 114 * Initialize codec using the specified attribute. 115 * 116 * Application should call #pjmedia_vid_codec_init() instead of 117 * calling this function directly. 118 * 119 * @param codec The codec instance. 120 * @param pool Pool to use when the codec needs to allocate 121 * some memory. 122 * 123 * @return PJ_SUCCESS on success. 157 * See #pjmedia_vid_codec_init(). 124 158 */ 125 159 pj_status_t (*init)(pjmedia_vid_codec *codec, … … 127 161 128 162 /** 129 * Open the codec and initialize with the specified parameter. 130 * Upon successful initialization, the codec may modify the parameter 131 * and fills in the unspecified values (such as size or frame rate of 132 * the encoder format, as it may need to be negotiated with remote 133 * preferences via SDP fmtp). 134 * 135 * Application should call #pjmedia_vid_codec_open() instead of 136 * calling this function directly. 137 * 138 * @param codec The codec instance. 139 * @param param Codec initialization parameter. 140 * 141 * @return PJ_SUCCESS on success. 163 * See #pjmedia_vid_codec_open(). 142 164 */ 143 165 pj_status_t (*open)(pjmedia_vid_codec *codec, … … 145 167 146 168 /** 147 * Close and shutdown codec, releasing all resources allocated by 148 * this codec, if any. 149 * 150 * Application should call #pjmedia_vid_codec_close() instead of 151 * calling this function directly. 152 * 153 * @param codec The codec instance. 154 * 155 * @return PJ_SUCCESS on success. 169 * See #pjmedia_vid_codec_close(). 156 170 */ 157 171 pj_status_t (*close)(pjmedia_vid_codec *codec); 158 172 159 173 /** 160 * Modify the codec parameter after the codec is open. 161 * Note that not all codec parameters can be modified during run-time. 162 * When the parameter cannot be changed, this function will return 163 * non-PJ_SUCCESS, and the original parameters will not be changed. 164 * 165 * Application should call #pjmedia_vid_codec_modify() instead of 166 * calling this function directly. 167 * 168 * @param codec The codec instance. 169 * @param param The new codec parameter. 170 * 171 * @return PJ_SUCCESS on success. 174 * See #pjmedia_vid_codec_modify(). 172 175 */ 173 176 pj_status_t (*modify)(pjmedia_vid_codec *codec, … … 175 178 176 179 /** 177 * Get the codec parameter after the codec is opened. 178 * 179 * Application should call #pjmedia_vid_codec_get_param() instead of 180 * calling this function directly. 181 * 182 * @param codec The codec instance. 183 * @param param The codec parameter. 184 * 185 * @return PJ_SUCCESS on success. 180 * See #pjmedia_vid_codec_get_param(). 186 181 */ 187 182 pj_status_t (*get_param)(pjmedia_vid_codec *codec, … … 189 184 190 185 /** 191 * Instruct the codec to generate a payload/packet from a picture 192 * bitstream to be sent (via network). The maximum payload size or 193 * MTU is configurable via enc_mtu field of #pjmedia_vid_codec_param. 194 * For a long bitstream, application usually need to call this function 195 * multiple times until the whole bitstream is sent. Note that, for 196 * performance reason, the packetization will be done in-place, so the 197 * original bitstream may be modified by this function. 198 * 199 * Application should call #pjmedia_vid_codec_packetize() instead of 200 * calling this function directly. 201 * 202 * @param codec The codec instance 203 * @param bits The picture bitstream. 204 * @param bits_len The length of the bitstream. 205 * @param bits_pos On input, the start position of the bitstream 206 * to be packetized. On output, the next position for 207 * next packet. 208 * @param pkt The pointer of the generated payload. 209 * @param pkt_len The payload length. 210 * 211 * @return PJ_SUCCESS on success. 212 */ 213 pj_status_t (*packetize) (pjmedia_vid_codec *codec, 214 pj_uint8_t *bits, 215 pj_size_t bits_len, 216 unsigned *bits_pos, 217 const pj_uint8_t **pkt, 218 pj_size_t *pkt_len); 186 * See #pjmedia_vid_codec_encode_begin(). 187 */ 188 pj_status_t (*encode_begin)(pjmedia_vid_codec *codec, 189 const pjmedia_frame *input, 190 unsigned out_size, 191 pjmedia_frame *output, 192 pj_bool_t *has_more); 219 193 220 194 /** 221 * Instruct the codec to parse a payload and append it into a picture 222 * bitstream. A picture bitstreams may need to be reconstructed from 223 * one or more payloads. Note that this function will not provide the 224 * detection of picture boundary, so application should manage the 225 * picture boundary detection by itself, e.g: for RTP delivery, payloads 226 * belong to the same picture will share the same RTP timestamp and also 227 * there is marker bit in the RTP header that is usually reserved for 228 * end-of-picture flag. Also note that in case of noticing packet lost, 229 * application should keep calling this function with payload pointer 230 * set to NULL, as the packetizer need to update its internal state. 231 * 232 * Application should call #pjmedia_vid_codec_unpacketize() instead of 233 * calling this function directly. 234 * 235 * @param codec The codec instance 236 * @param pkt The input packet. 237 * @param pkt_size Size of the packet. 238 * @param timestamp The timestamp of the first sample in the packet. 239 * @param frame_cnt On input, specifies the maximum number of frames 240 * in the array. On output, the codec must fill 241 * with number of frames detected in the packet. 242 * @param frames On output, specifies the frames that have been 243 * detected in the packet. 244 * 245 * @return PJ_SUCCESS on success. 246 */ 247 pj_status_t (*unpacketize)(pjmedia_vid_codec *codec, 248 const pj_uint8_t *payload, 249 pj_size_t payload_len, 250 pj_uint8_t *bits, 251 pj_size_t bits_len, 252 unsigned *bits_pos); 253 254 /** 255 * Instruct the codec to encode the specified input frame. The input 256 * MUST contain only one picture with appropriate format as specified 257 * in opening the codec. 258 * 259 * Application should call #pjmedia_vid_codec_encode() instead of 260 * calling this function directly. 261 * 262 * @param codec The codec instance. 263 * @param input The input frame. 264 * @param out_size The length of buffer in the output frame. 265 * @param output The output frame. 266 * 267 * @return PJ_SUCCESS on success; 268 */ 269 pj_status_t (*encode)(pjmedia_vid_codec *codec, 270 const pjmedia_frame *input, 271 unsigned out_size, 195 * See #pjmedia_vid_codec_encode_more() 196 */ 197 pj_status_t (*encode_more)(pjmedia_vid_codec *codec, 198 unsigned out_size, 199 pjmedia_frame *output, 200 pj_bool_t *has_more); 201 202 203 /* 204 * See #pjmedia_vid_codec_decode(). 205 */ 206 pj_status_t (*decode)(pjmedia_vid_codec *codec, 207 pj_size_t count, 208 pjmedia_frame packets[], 209 unsigned out_size, 272 210 pjmedia_frame *output); 273 211 274 /**275 * Instruct the codec to decode the specified input frame. The input276 * frame MUST contain exactly one picture. Note that the decoded picture277 * format may different to the current setting, e.g: the format specified278 * in the #pjmedia_vid_codec_param when opening the codec, in this case the279 * PJMEDIA_EVENT_FMT_CHANGED event will be emitted by the codec. The codec280 * parameter will also be updated, and application can query the format by281 * using #get_param().282 *283 * Application should call #pjmedia_vid_codec_decode() instead of284 * calling this function directly.285 *286 * @param codec The codec instance.287 * @param input The input frame.288 * @param out_size The length of buffer in the output frame.289 * @param output The output frame.290 *291 * @return PJ_SUCCESS on success;292 */293 pj_status_t (*decode)(pjmedia_vid_codec *codec,294 const pjmedia_frame *input,295 unsigned out_size,296 pjmedia_frame *output);297 298 212 /** 299 * Instruct the codec to recover a missing frame. 300 * 301 * Application should call #pjmedia_vid_codec_recover() instead of 302 * calling this function directly. 303 * 304 * @param codec The codec instance. 305 * @param out_size The length of buffer in the output frame. 306 * @param output The output frame where generated signal 307 * will be placed. 308 * 309 * @return PJ_SUCCESS on success; 213 * See #pjmedia_vid_codec_recover() 310 214 */ 311 215 pj_status_t (*recover)(pjmedia_vid_codec *codec, … … 554 458 * @return PJ_SUCCESS on success. 555 459 */ 556 PJ_DECL(pj_status_t) pjmedia_vid_codec_mgr_enum_codecs(557 pjmedia_vid_codec_mgr *mgr, 558 unsigned *count,559 560 460 PJ_DECL(pj_status_t) 461 pjmedia_vid_codec_mgr_enum_codecs(pjmedia_vid_codec_mgr *mgr, 462 unsigned *count, 463 pjmedia_vid_codec_info info[], 464 unsigned *prio); 561 465 562 466 … … 605 509 * the buffer is not long enough. 606 510 */ 607 PJ_DECL(char*) pjmedia_vid_codec_info_to_id( 608 const pjmedia_vid_codec_info *info, 609 char *id, unsigned max_len ); 511 PJ_DECL(char*) pjmedia_vid_codec_info_to_id(const pjmedia_vid_codec_info *info, 512 char *id, unsigned max_len ); 610 513 611 514 … … 758 661 * @return PJ_SUCCESS on success. 759 662 */ 760 PJ_INLINE(pj_status_t) pjmedia_vid_codec_open( 761 pjmedia_vid_codec *codec, 762 pjmedia_vid_codec_param *param ) 663 PJ_INLINE(pj_status_t) pjmedia_vid_codec_open(pjmedia_vid_codec *codec, 664 pjmedia_vid_codec_param *param) 763 665 { 764 666 return (*codec->op->open)(codec, param); … … 791 693 * @return PJ_SUCCESS on success. 792 694 */ 793 PJ_INLINE(pj_status_t) pjmedia_vid_codec_modify(794 pjmedia_vid_codec *codec, 795 695 PJ_INLINE(pj_status_t) 696 pjmedia_vid_codec_modify(pjmedia_vid_codec *codec, 697 const pjmedia_vid_codec_param *param) 796 698 { 797 699 return (*codec->op->modify)(codec, param); … … 807 709 * @return PJ_SUCCESS on success. 808 710 */ 809 PJ_INLINE(pj_status_t) pjmedia_vid_codec_get_param(810 pjmedia_vid_codec *codec, 811 711 PJ_INLINE(pj_status_t) 712 pjmedia_vid_codec_get_param(pjmedia_vid_codec *codec, 713 pjmedia_vid_codec_param *param) 812 714 { 813 715 return (*codec->op->get_param)(codec, param); 814 716 } 815 717 816 817 /** 818 * Instruct the codec to generate a payload/packet from a picture819 * bitstream to be sent (via network). The maximum payload size or820 * MTU is configurable via enc_mtu field of #pjmedia_vid_codec_param.821 * For a long bitstream, application usually need to call this function822 * multiple times until the whole bitstream is sent. Note that, for823 * performance reason, the packetization will be done in-place, sothe824 * original bitstream may be modified by this function.825 * 826 * @param codec The codec instance827 * @param bits The picture bitstream.828 * @param bits_len The length of the bitstream.829 * @param bits_pos On input, the start position of the bitstream830 * to be packetized. On output, the next position for831 * next packet.832 * @param pkt The pointer of the generated payload.833 * @param pkt_len The payload length.834 * 835 * @return PJ_SUCCESS on success.836 * /837 PJ_INLINE(pj_status_t) pjmedia_vid_codec_packetize( 838 pjmedia_vid_codec *codec, 839 pj_uint8_t *bits,840 pj_size_t bits_len,841 unsigned *bits_pos,842 const pj_uint8_t **pkt,843 pj_size_t *pkt_len)844 { 845 return (*codec->op-> packetize)(codec, bits, bits_len, bits_pos,846 pkt, pkt_len);718 /** 719 * Encode the specified input frame. The input MUST contain only one picture 720 * with the appropriate format as specified when opening the codec. Depending 721 * on the packing or packetization set in the \a packing param, the process 722 * may produce multiple encoded packets or payloads to represent the picture. 723 * This is true for example for PJMEDIA_VID_PACKING_PACKETS packing. In this 724 * case, the \a has_more field will be set to PJ_TRUE, and application should 725 * call pjmedia_vid_codec_encode_more() to get the remaining results from the 726 * codec. 727 * 728 * @param codec The codec instance. 729 * @param input The input frame. 730 * @param out_size The length of buffer in the output frame. This 731 * should be at least the same as the configured 732 * encoding MTU of the codec. 733 * @param output The output frame. 734 * @param has_more PJ_TRUE if more payloads are available; application 735 * should then call pjmedia_vid_codec_encode_more() 736 * to retrieve the remaining results. 737 * 738 * @return PJ_SUCCESS on success; 739 */ 740 PJ_INLINE(pj_status_t) 741 pjmedia_vid_codec_encode_begin( pjmedia_vid_codec *codec, 742 const pjmedia_frame *input, 743 unsigned out_size, 744 pjmedia_frame *output, 745 pj_bool_t *has_more) 746 { 747 return (*codec->op->encode_begin)(codec, input, out_size, output, 748 has_more); 847 749 } 848 750 849 850 /** 851 * Instruct the codec to parse a payload and append it into a picture 852 * bitstream. A picture bitstreams may need to be reconstructed from 853 * one or more payloads. Note that this function will not provide the 854 * detection of picture boundary, so application should manage the 855 * picture boundary detection by itself, e.g: for RTP delivery, payloads 856 * belong to the same picture will share the same RTP timestamp and also 857 * there is marker bit in the RTP header that is usually reserved for 858 * end-of-picture flag. Also note that in case of noticing packet lost, 859 * application should keep calling this function with payload pointer 860 * set to NULL, as the packetizer need to update its internal state. 861 * 862 * @param codec The codec instance 863 * @param pkt The input packet. 864 * @param pkt_size Size of the packet. 865 * @param timestamp The timestamp of the first sample in the packet. 866 * @param frame_cnt On input, specifies the maximum number of frames 867 * in the array. On output, the codec must fill 868 * with number of frames detected in the packet. 869 * @param frames On output, specifies the frames that have been 870 * detected in the packet. 871 * 872 * @return PJ_SUCCESS on success. 873 */ 874 PJ_INLINE(pj_status_t) pjmedia_vid_codec_unpacketize( 875 pjmedia_vid_codec *codec, 876 const pj_uint8_t *payload, 877 pj_size_t payload_len, 878 pj_uint8_t *bits, 879 pj_size_t bits_len, 880 unsigned *bits_pos ) 881 { 882 return (*codec->op->unpacketize)(codec, payload, payload_len, bits, 883 bits_len, bits_pos); 751 /** 752 * Retrieve more encoded packets/payloads from the codec. Application 753 * should call this function repeatedly until \a has_more flag is set 754 * to PJ_FALSE. 755 * 756 * @param codec The codec instance. 757 * @param out_size The length of buffer in the output frame. This 758 * should be at least the same as as the configured 759 * encoding MTU of the codec. 760 * @param output The output frame. 761 * @param has_more PJ_TRUE if more payloads are available, which in 762 * this case application should call \a encode_more() 763 * to retrieve them. 764 * 765 * @return PJ_SUCCESS on success; 766 */ 767 PJ_INLINE(pj_status_t) 768 pjmedia_vid_codec_encode_more( pjmedia_vid_codec *codec, 769 unsigned out_size, 770 pjmedia_frame *output, 771 pj_bool_t *has_more) 772 { 773 return (*codec->op->encode_more)(codec, out_size, output, has_more); 884 774 } 885 775 886 887 /** 888 * Instruct the codec to encode the specified input frame. The input 889 * MUST contain only one picture with appropriate format as specified 890 * in opening the codec. 891 * 892 * @param codec The codec instance. 893 * @param input The input frame. 776 /** 777 * Decode the input packets into one picture. If the packing is set to 778 * PJMEDIA_VID_PACKING_PACKETS when opening the codec, the codec is set 779 * to decode multiple encoded packets into one picture. These encoded 780 * packets are typically retrieved from the jitter buffer. If the packing 781 * is set to PJMEDIA_VID_PACKING_WHOLE, then this decode function can only 782 * accept one frame as the input. 783 * 784 * Note that the decoded picture format may different to the configured 785 * setting (i.e. the format specified in the #pjmedia_vid_codec_param when 786 * opening the codec), in this case the PJMEDIA_EVENT_FMT_CHANGED event will 787 * be emitted by the codec to notify the event. The codec parameter will 788 * also be updated, and application can query the format by using 789 * pjmedia_vid_codec_get_param(). 790 * 791 * @param codec The codec instance. 792 * @param pkt_count Number of packets in the input. 793 * @param packets Array of input packets, each containing an encoded 794 * frame. 894 795 * @param out_size The length of buffer in the output frame. 895 796 * @param output The output frame. … … 897 798 * @return PJ_SUCCESS on success; 898 799 */ 899 PJ_INLINE(pj_status_t) pjmedia_vid_codec_ encode(900 pjmedia_vid_codec *codec,901 const pjmedia_frame *input,902 unsigned out_size,903 904 { 905 return (*codec->op-> encode)(codec, input, out_size, output);800 PJ_INLINE(pj_status_t) pjmedia_vid_codec_decode(pjmedia_vid_codec *codec, 801 pj_size_t pkt_count, 802 pjmedia_frame packets[], 803 unsigned out_size, 804 pjmedia_frame *output) 805 { 806 return (*codec->op->decode)(codec, pkt_count, packets, out_size, output); 906 807 } 907 808 908 909 /** 910 * Instruct the codec to decode the specified input frame. The input 911 * frame MUST contain exactly one picture. Note that the decoded picture 912 * format may different to the current setting, e.g: the format specified 913 * in the #pjmedia_vid_codec_param when opening the codec, in this case the 914 * PJMEDIA_EVENT_FMT_CHANGED event will be emitted by the codec. The codec 915 * parameter will also be updated, and application can query the format by 916 * using #get_param(). 917 * 918 * @param codec The codec instance. 919 * @param input The input frame. 920 * @param out_size The length of buffer in the output frame. 921 * @param output The output frame. 922 * 923 * @return PJ_SUCCESS on success; 924 */ 925 PJ_INLINE(pj_status_t) pjmedia_vid_codec_decode( 926 pjmedia_vid_codec *codec, 927 const pjmedia_frame *input, 928 unsigned out_size, 929 pjmedia_frame *output) 930 { 931 return (*codec->op->decode)(codec, input, out_size, output); 932 } 933 934 935 /** 936 * Instruct the codec to recover a missing frame. 937 * 938 * @param codec The codec instance. 809 /** 810 * Recover a missing frame. 811 * 812 * @param codec The codec instance. 939 813 * @param out_size The length of buffer in the output frame. 940 814 * @param output The output frame where generated signal … … 943 817 * @return PJ_SUCCESS on success; 944 818 */ 945 PJ_INLINE(pj_status_t) pjmedia_vid_codec_recover( 946 pjmedia_vid_codec *codec, 947 unsigned out_size, 948 pjmedia_frame *output) 819 PJ_INLINE(pj_status_t) pjmedia_vid_codec_recover(pjmedia_vid_codec *codec, 820 unsigned out_size, 821 pjmedia_frame *output) 949 822 { 950 823 if (codec->op && codec->op->recover) … … 961 834 /** 962 835 * @defgroup PJMEDIA_CODEC_VID_CODECS Supported video codecs 963 * @ingroup PJMEDIA_CODEC 964 * @brief Documentation about individual video codec supported by PJMEDIA 965 * @{ 966 * Please see the APIs provided by the individual codecs below. 967 */ 968 /** 969 * @} 836 * @ingroup PJMEDIA_VID_CODEC 970 837 */ 971 838
Note: See TracChangeset
for help on using the changeset viewer.