Ignore:
Timestamp:
Jul 15, 2011 10:19:59 AM (13 years ago)
Author:
nanang
Message:

Fix #1295: Added thin wrapper for audio and video codec operations.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/vid_codec.h

    r3640 r3663  
    114114     * Initialize codec using the specified attribute. 
    115115     * 
     116     * Application should call #pjmedia_vid_codec_init() instead of  
     117     * calling this function directly. 
     118     * 
    116119     * @param codec     The codec instance. 
    117120     * @param pool      Pool to use when the codec needs to allocate 
     
    130133     * preferences via SDP fmtp). 
    131134     * 
     135     * Application should call #pjmedia_vid_codec_open() instead of  
     136     * calling this function directly. 
     137     * 
    132138     * @param codec     The codec instance. 
    133139     * @param param     Codec initialization parameter. 
     
    141147     * Close and shutdown codec, releasing all resources allocated by 
    142148     * this codec, if any. 
     149     * 
     150     * Application should call #pjmedia_vid_codec_close() instead of  
     151     * calling this function directly. 
    143152     * 
    144153     * @param codec     The codec instance. 
     
    154163     * non-PJ_SUCCESS, and the original parameters will not be changed. 
    155164     * 
     165     * Application should call #pjmedia_vid_codec_modify() instead of  
     166     * calling this function directly. 
     167     * 
    156168     * @param codec     The codec instance. 
    157169     * @param param     The new codec parameter. 
     
    164176    /**  
    165177     * 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. 
    166181     * 
    167182     * @param codec     The codec instance. 
     
    181196     * performance reason, the packetization will be done in-place, so the 
    182197     * original bitstream may be modified by this function. 
     198     * 
     199     * Application should call #pjmedia_vid_codec_packetize() instead of  
     200     * calling this function directly. 
    183201     * 
    184202     * @param codec     The codec instance 
     
    212230     * set to NULL, as the packetizer need to update its internal state. 
    213231     * 
     232     * Application should call #pjmedia_vid_codec_unpacketize() instead of  
     233     * calling this function directly. 
     234     * 
    214235     * @param codec     The codec instance 
    215236     * @param pkt       The input packet. 
     
    236257     * in opening the codec. 
    237258     * 
     259     * Application should call #pjmedia_vid_codec_encode() instead of  
     260     * calling this function directly. 
     261     * 
    238262     * @param codec     The codec instance. 
    239263     * @param input     The input frame. 
     
    257281     * using #get_param(). 
    258282     * 
     283     * Application should call #pjmedia_vid_codec_decode() instead of  
     284     * calling this function directly. 
     285     * 
    259286     * @param codec     The codec instance. 
    260287     * @param input     The input frame. 
     
    271298    /** 
    272299     * Instruct the codec to recover a missing frame. 
     300     * 
     301     * Application should call #pjmedia_vid_codec_recover() instead of  
     302     * calling this function directly. 
    273303     * 
    274304     * @param codec     The codec instance. 
     
    433463 * @param sig       Codec's object signature (see signatures.h) 
    434464 */ 
    435 PJ_DECL(void) pjmedia_vid_codec_init(pjmedia_vid_codec *codec, 
    436                                      pjmedia_obj_sig sig); 
     465PJ_DECL(void) pjmedia_vid_codec_reset(pjmedia_vid_codec *codec, 
     466                                      pjmedia_obj_sig sig); 
    437467 
    438468/** 
     
    700730 
    701731 
     732/**  
     733 * Initialize codec using the specified attribute. 
     734 * 
     735 * @param codec     The codec instance. 
     736 * @param pool      Pool to use when the codec needs to allocate 
     737 *                  some memory. 
     738 * 
     739 * @return          PJ_SUCCESS on success. 
     740 */ 
     741PJ_INLINE(pj_status_t) pjmedia_vid_codec_init( pjmedia_vid_codec *codec,  
     742                                               pj_pool_t *pool ) 
     743{ 
     744    return (*codec->op->init)(codec, pool); 
     745} 
     746 
     747 
     748/**  
     749 * Open the codec and initialize with the specified parameter. 
     750 * Upon successful initialization, the codec may modify the parameter 
     751 * and fills in the unspecified values (such as size or frame rate of 
     752 * the encoder format, as it may need to be negotiated with remote 
     753 * preferences via SDP fmtp). 
     754 * 
     755 * @param codec     The codec instance. 
     756 * @param param     Codec initialization parameter. 
     757 * 
     758 * @return          PJ_SUCCESS on success. 
     759 */ 
     760PJ_INLINE(pj_status_t) pjmedia_vid_codec_open( 
     761                                            pjmedia_vid_codec *codec,  
     762                                            pjmedia_vid_codec_param *param ) 
     763{ 
     764    return (*codec->op->open)(codec, param); 
     765} 
     766 
     767 
     768/**  
     769 * Close and shutdown codec, releasing all resources allocated by 
     770 * this codec, if any. 
     771 * 
     772 * @param codec     The codec instance. 
     773 * 
     774 * @return          PJ_SUCCESS on success. 
     775 */ 
     776PJ_INLINE(pj_status_t) pjmedia_vid_codec_close( pjmedia_vid_codec *codec ) 
     777{ 
     778    return (*codec->op->close)(codec); 
     779} 
     780 
     781 
     782/**  
     783 * Modify the codec parameter after the codec is open.  
     784 * Note that not all codec parameters can be modified during run-time.  
     785 * When the parameter cannot be changed, this function will return  
     786 * non-PJ_SUCCESS, and the original parameters will not be changed. 
     787 * 
     788 * @param codec The codec instance. 
     789 * @param param The new codec parameter. 
     790 * 
     791 * @return              PJ_SUCCESS on success. 
     792 */ 
     793PJ_INLINE(pj_status_t) pjmedia_vid_codec_modify( 
     794                                    pjmedia_vid_codec *codec,  
     795                                    const pjmedia_vid_codec_param *param) 
     796{ 
     797    return (*codec->op->modify)(codec, param); 
     798} 
     799 
     800 
     801/**  
     802 * Get the codec parameter after the codec is opened.  
     803 * 
     804 * @param codec The codec instance. 
     805 * @param param The codec parameter. 
     806 * 
     807 * @return              PJ_SUCCESS on success. 
     808 */ 
     809PJ_INLINE(pj_status_t) pjmedia_vid_codec_get_param( 
     810                                    pjmedia_vid_codec *codec,  
     811                                    pjmedia_vid_codec_param *param) 
     812{ 
     813    return (*codec->op->get_param)(codec, param); 
     814} 
     815 
     816 
     817/** 
     818 * Instruct the codec to generate a payload/packet from a picture 
     819 * bitstream to be sent (via network). The maximum payload size or 
     820 * MTU is configurable via enc_mtu field of #pjmedia_vid_codec_param. 
     821 * For a long bitstream, application usually need to call this function 
     822 * multiple times until the whole bitstream is sent. Note that, for 
     823 * performance reason, the packetization will be done in-place, so the 
     824 * original bitstream may be modified by this function. 
     825 * 
     826 * @param codec The codec instance 
     827 * @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 bitstream 
     830 *                      to be packetized. On output, the next position for 
     831 *                      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 */ 
     837PJ_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); 
     847} 
     848 
     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 */ 
     874PJ_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); 
     884} 
     885 
     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. 
     894 * @param out_size      The length of buffer in the output frame. 
     895 * @param output        The output frame. 
     896 * 
     897 * @return              PJ_SUCCESS on success; 
     898 */ 
     899PJ_INLINE(pj_status_t) pjmedia_vid_codec_encode( 
     900                                            pjmedia_vid_codec *codec,  
     901                                            const pjmedia_frame *input, 
     902                                            unsigned out_size,  
     903                                            pjmedia_frame *output) 
     904{ 
     905    return (*codec->op->encode)(codec, input, out_size, output); 
     906} 
     907 
     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 */ 
     925PJ_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. 
     939 * @param out_size      The length of buffer in the output frame. 
     940 * @param output        The output frame where generated signal 
     941 *                      will be placed. 
     942 * 
     943 * @return              PJ_SUCCESS on success; 
     944 */ 
     945PJ_INLINE(pj_status_t) pjmedia_vid_codec_recover( 
     946                                            pjmedia_vid_codec *codec,  
     947                                            unsigned out_size,  
     948                                            pjmedia_frame *output) 
     949{ 
     950    if (codec->op && codec->op->recover) 
     951        return (*codec->op->recover)(codec, out_size, output); 
     952    else 
     953        return PJ_ENOTSUP; 
     954} 
    702955 
    703956 
Note: See TracChangeset for help on using the changeset viewer.