Ignore:
Timestamp:
Dec 10, 2010 11:04:30 AM (13 years ago)
Author:
bennylp
Message:

Migration of current video works from private repository to this repository. This closed #1176

File:
1 edited

Legend:

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

    r3327 r3392  
    11/* $Id$ */ 
    22/*  
    3  * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com) 
     3 * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
    55 * 
     
    2727 
    2828#include <pjmedia/config.h> 
    29 #include <pj/sock.h>        /* pjmedia_sock_info        */ 
    30 #include <pj/string.h>      /* pj_memcpy(), pj_memset() */ 
     29#include <pj/sock.h> 
     30#include <pj/types.h> 
     31 
    3132 
    3233/** 
     
    5354typedef enum pjmedia_type 
    5455{ 
    55     /** No type. */ 
    56     PJMEDIA_TYPE_NONE = 0, 
     56    /** Type is not specified. */ 
     57    PJMEDIA_TYPE_NONE, 
    5758 
    5859    /** The media is audio */ 
    59     PJMEDIA_TYPE_AUDIO = 1, 
     60    PJMEDIA_TYPE_AUDIO, 
    6061 
    6162    /** The media is video. */ 
    62     PJMEDIA_TYPE_VIDEO = 2, 
    63  
    64     /** Unknown media type, in this case the name will be specified in 
    65      *  encoding_name. 
    66      */ 
    67     PJMEDIA_TYPE_UNKNOWN = 3, 
     63    PJMEDIA_TYPE_VIDEO, 
    6864 
    6965    /** The media is application. */ 
    70     PJMEDIA_TYPE_APPLICATION = 4 
     66    PJMEDIA_TYPE_APPLICATION, 
     67 
     68    /** The media type is unknown or unsupported. */ 
     69    PJMEDIA_TYPE_UNKNOWN 
    7170 
    7271} pjmedia_type; 
     
    101100    PJMEDIA_DIR_NONE = 0, 
    102101 
    103     /** Encoding (outgoing to network) stream */ 
     102    /** Encoding (outgoing to network) stream, also known as capture */ 
    104103    PJMEDIA_DIR_ENCODING = 1, 
    105104 
    106     /** Decoding (incoming from network) stream. */ 
     105    /** Same as encoding direction. */ 
     106    PJMEDIA_DIR_CAPTURE = PJMEDIA_DIR_ENCODING, 
     107 
     108    /** Decoding (incoming from network) stream, also known as playback. */ 
    107109    PJMEDIA_DIR_DECODING = 2, 
    108110 
    109     /** Incoming and outgoing stream. */ 
    110     PJMEDIA_DIR_ENCODING_DECODING = 3 
     111    /** Same as decoding. */ 
     112    PJMEDIA_DIR_PLAYBACK = PJMEDIA_DIR_DECODING, 
     113 
     114    /** Same as decoding. */ 
     115    PJMEDIA_DIR_RENDER = PJMEDIA_DIR_DECODING, 
     116 
     117    /** Incoming and outgoing stream, same as PJMEDIA_DIR_CAPTURE_PLAYBACK */ 
     118    PJMEDIA_DIR_ENCODING_DECODING = 3, 
     119 
     120    /** Same as ENCODING_DECODING */ 
     121    PJMEDIA_DIR_CAPTURE_PLAYBACK = PJMEDIA_DIR_ENCODING_DECODING, 
     122 
     123    /** Same as ENCODING_DECODING */ 
     124    PJMEDIA_DIR_CAPTURE_RENDER = PJMEDIA_DIR_ENCODING_DECODING 
    111125 
    112126} pjmedia_dir; 
    113127 
    114128 
    115  
    116 /* Alternate names for media direction: */ 
    117  
    118 /** 
    119  * Direction is capturing audio frames. 
    120  */ 
    121 #define PJMEDIA_DIR_CAPTURE     PJMEDIA_DIR_ENCODING 
    122  
    123 /** 
    124  * Direction is playback of audio frames. 
    125  */ 
    126 #define PJMEDIA_DIR_PLAYBACK    PJMEDIA_DIR_DECODING 
    127  
    128 /** 
    129  * Direction is both capture and playback. 
    130  */ 
    131 #define PJMEDIA_DIR_CAPTURE_PLAYBACK    PJMEDIA_DIR_ENCODING_DECODING 
    132  
    133  
    134 /** 
    135  * Create 32bit port signature from ASCII characters. 
    136  */ 
    137 #define PJMEDIA_PORT_SIGNATURE(a,b,c,d)     \ 
    138             (a<<24 | b<<16 | c<<8 | d) 
    139  
    140  
    141129/** 
    142130 * Opaque declaration of media endpoint. 
    143131 */ 
    144132typedef struct pjmedia_endpt pjmedia_endpt; 
    145  
    146133 
    147134/* 
     
    150137typedef struct pjmedia_stream pjmedia_stream; 
    151138 
    152  
    153 /** 
    154  * Media socket info is used to describe the underlying sockets 
    155  * to be used as media transport. 
    156  */ 
    157 typedef struct pjmedia_sock_info 
    158 { 
    159     /** The RTP socket handle */ 
    160     pj_sock_t       rtp_sock; 
    161  
    162     /** Address to be advertised as the local address for the RTP 
    163      *  socket, which does not need to be equal as the bound 
    164      *  address (for example, this address can be the address resolved 
    165      *  with STUN). 
     139/** 
     140 * Enumeration for picture coordinate base. 
     141 */ 
     142typedef enum pjmedia_coord_base 
     143{ 
     144    /** 
     145     * This specifies that the pixel [0, 0] location is at the left-top 
     146     * position. 
    166147     */ 
    167     pj_sockaddr     rtp_addr_name; 
    168  
    169     /** The RTCP socket handle. */ 
    170     pj_sock_t       rtcp_sock; 
    171  
    172     /** Address to be advertised as the local address for the RTCP 
    173      *  socket, which does not need to be equal as the bound 
    174      *  address (for example, this address can be the address resolved 
    175      *  with STUN). 
     148    PJMEDIA_COORD_BASE_LEFT_TOP, 
     149 
     150    /** 
     151     * This specifies that the pixel [0, 0] location is at the left-bottom 
     152     * position. 
    176153     */ 
    177     pj_sockaddr     rtcp_addr_name; 
    178  
    179 } pjmedia_sock_info; 
    180  
    181  
    182 /** 
    183  * Macro for packing format. 
    184  */ 
    185 #define PJMEDIA_FORMAT_PACK(C1, C2, C3, C4) ( C4<<24 | C3<<16 | C2<<8 | C1 ) 
    186  
    187 /** 
    188  * This enumeration describes format ID.  
    189  */ 
    190 typedef enum pjmedia_format_id 
    191 { 
    192     /** 
    193      * 16bit linear 
    194      */ 
    195     PJMEDIA_FORMAT_L16      = 0, 
    196      
    197     /** 
    198      * Alias for PJMEDIA_FORMAT_L16 
    199      */ 
    200     PJMEDIA_FORMAT_PCM      = PJMEDIA_FORMAT_L16, 
    201  
    202     /** 
    203      * G.711 ALAW 
    204      */ 
    205     PJMEDIA_FORMAT_PCMA     = PJMEDIA_FORMAT_PACK('A', 'L', 'A', 'W'), 
    206  
    207     /** 
    208      * Alias for PJMEDIA_FORMAT_PCMA 
    209      */ 
    210     PJMEDIA_FORMAT_ALAW     = PJMEDIA_FORMAT_PCMA, 
    211  
    212     /** 
    213      * G.711 ULAW 
    214      */ 
    215     PJMEDIA_FORMAT_PCMU     = PJMEDIA_FORMAT_PACK('u', 'L', 'A', 'W'), 
    216  
    217     /** 
    218      * Aliaw for PJMEDIA_FORMAT_PCMU 
    219      */ 
    220     PJMEDIA_FORMAT_ULAW     = PJMEDIA_FORMAT_PCMU, 
    221  
    222     /** 
    223      * AMR narrowband 
    224      */ 
    225     PJMEDIA_FORMAT_AMR      = PJMEDIA_FORMAT_PACK(' ', 'A', 'M', 'R'), 
    226  
    227     /** 
    228      * ITU G.729 
    229      */ 
    230     PJMEDIA_FORMAT_G729     = PJMEDIA_FORMAT_PACK('G', '7', '2', '9'), 
    231  
    232     /** 
    233      * Internet Low Bit-Rate Codec (ILBC) 
    234      */ 
    235     PJMEDIA_FORMAT_ILBC     = PJMEDIA_FORMAT_PACK('I', 'L', 'B', 'C') 
    236  
    237 } pjmedia_format_id; 
    238  
    239  
    240 /** 
    241  * Media format information. 
    242  */ 
    243 typedef struct pjmedia_format 
    244 { 
    245     /** Format ID */ 
    246     pjmedia_format_id   id; 
    247  
    248     /** Bitrate. */ 
    249     pj_uint32_t         bitrate; 
    250  
    251     /** Flag to indicate whether VAD is enabled */ 
    252     pj_bool_t           vad; 
    253  
    254 } pjmedia_format; 
    255  
    256  
    257  
    258 /** 
    259  * This is a general purpose function set PCM samples to zero. 
    260  * Since this function is needed by many parts of the library, 
    261  * by putting this functionality in one place, it enables some. 
    262  * clever people to optimize this function. 
    263  * 
    264  * @param samples       The 16bit PCM samples. 
    265  * @param count         Number of samples. 
    266  */ 
    267 PJ_INLINE(void) pjmedia_zero_samples(pj_int16_t *samples, unsigned count) 
    268 { 
    269 #if 1 
    270     pj_bzero(samples, (count<<1)); 
    271 #elif 0 
    272     unsigned i; 
    273     for (i=0; i<count; ++i) samples[i] = 0; 
    274 #else 
    275     unsigned i; 
    276     count >>= 1; 
    277     for (i=0; i<count; ++i) ((pj_int32_t*)samples)[i] = (pj_int32_t)0; 
    278 #endif 
    279 } 
    280  
    281  
    282 /** 
    283  * This is a general purpose function to copy samples from/to buffers with 
    284  * equal size. Since this function is needed by many parts of the library, 
    285  * by putting this functionality in one place, it enables some. 
    286  * clever people to optimize this function. 
    287  */ 
    288 PJ_INLINE(void) pjmedia_copy_samples(pj_int16_t *dst, const pj_int16_t *src, 
    289                                      unsigned count) 
    290 { 
    291 #if 1 
    292     pj_memcpy(dst, src, (count<<1)); 
    293 #elif 0 
    294     unsigned i; 
    295     for (i=0; i<count; ++i) dst[i] = src[i]; 
    296 #else 
    297     unsigned i; 
    298     count >>= 1; 
    299     for (i=0; i<count; ++i) 
    300         ((pj_int32_t*)dst)[i] = ((pj_int32_t*)src)[i]; 
    301 #endif 
    302 } 
    303  
    304  
    305 /** 
    306  * This is a general purpose function to copy samples from/to buffers with 
    307  * equal size. Since this function is needed by many parts of the library, 
    308  * by putting this functionality in one place, it enables some. 
    309  * clever people to optimize this function. 
    310  */ 
    311 PJ_INLINE(void) pjmedia_move_samples(pj_int16_t *dst, const pj_int16_t *src, 
    312                                      unsigned count) 
    313 { 
    314 #if 1 
    315     pj_memmove(dst, src, (count<<1)); 
    316 #elif 0 
    317     unsigned i; 
    318     for (i=0; i<count; ++i) dst[i] = src[i]; 
    319 #else 
    320     unsigned i; 
    321     count >>= 1; 
    322     for (i=0; i<count; ++i) 
    323         ((pj_int32_t*)dst)[i] = ((pj_int32_t*)src)[i]; 
    324 #endif 
    325 } 
    326  
    327 /**  
    328  * Types of media frame.  
    329  */ 
    330 typedef enum pjmedia_frame_type 
    331 { 
    332     PJMEDIA_FRAME_TYPE_NONE,        /**< No frame.              */ 
    333     PJMEDIA_FRAME_TYPE_AUDIO,       /**< Normal audio frame.    */ 
    334     PJMEDIA_FRAME_TYPE_EXTENDED     /**< Extended audio frame.  */ 
    335  
    336 } pjmedia_frame_type; 
    337  
    338  
    339 /**  
    340  * This structure describes a media frame.  
    341  */ 
    342 typedef struct pjmedia_frame 
    343 { 
    344     pjmedia_frame_type   type;      /**< Frame type.                        */ 
    345     void                *buf;       /**< Pointer to buffer.                 */ 
    346     pj_size_t            size;      /**< Frame size in bytes.               */ 
    347     pj_timestamp         timestamp; /**< Frame timestamp.                   */ 
    348     pj_uint32_t          bit_info;  /**< Bit info of the frame, sample case: 
    349                                          a frame may not exactly start and end 
    350                                          at the octet boundary, so this field  
    351                                          may be used for specifying start &  
    352                                          end bit offset.                    */ 
    353 } pjmedia_frame; 
    354  
    355  
    356 /** 
    357  * The pjmedia_frame_ext is used to carry a more complex audio frames than 
    358  * the typical PCM audio frames, and it is signaled by setting the "type" 
    359  * field of a pjmedia_frame to PJMEDIA_FRAME_TYPE_EXTENDED. With this set, 
    360  * application may typecast pjmedia_frame to pjmedia_frame_ext. 
    361  * 
    362  * This structure may contain more than one audio frames, which subsequently 
    363  * will be called subframes in this structure. The subframes section 
    364  * immediately follows the end of this structure, and each subframe is 
    365  * represented by pjmedia_frame_ext_subframe structure. Every next 
    366  * subframe immediately follows the previous subframe, and all subframes 
    367  * are byte-aligned although its payload may not be byte-aligned. 
    368  */ 
    369  
    370 #pragma pack(1) 
    371 typedef struct pjmedia_frame_ext { 
    372     pjmedia_frame   base;           /**< Base frame info */ 
    373     pj_uint16_t     samples_cnt;    /**< Number of samples in this frame */ 
    374     pj_uint16_t     subframe_cnt;   /**< Number of (sub)frames in this frame */ 
    375  
    376     /* Zero or more (sub)frames follows immediately after this, 
    377      * each will be represented by pjmedia_frame_ext_subframe 
    378      */ 
    379 } pjmedia_frame_ext; 
    380 #pragma pack() 
    381  
    382 /** 
    383  * This structure represents the individual subframes in the 
    384  * pjmedia_frame_ext structure. 
    385  */ 
    386 #pragma pack(1) 
    387 typedef struct pjmedia_frame_ext_subframe { 
    388     pj_uint16_t     bitlen;         /**< Number of bits in the data */ 
    389     pj_uint8_t      data[1];        /**< Start of encoded data */ 
    390 } pjmedia_frame_ext_subframe; 
    391  
    392 #pragma pack() 
    393  
    394  
    395 /** 
    396  * Append one subframe to #pjmedia_frame_ext. 
    397  * 
    398  * @param frm               The #pjmedia_frame_ext. 
    399  * @param src               Subframe data. 
    400  * @param bitlen            Lenght of subframe, in bits. 
    401  * @param samples_cnt       Number of audio samples in subframe. 
    402  */ 
    403 PJ_INLINE(void) pjmedia_frame_ext_append_subframe(pjmedia_frame_ext *frm, 
    404                                                   const void *src, 
    405                                                   unsigned bitlen, 
    406                                                   unsigned samples_cnt) 
    407 { 
    408     pjmedia_frame_ext_subframe *fsub; 
    409     pj_uint8_t *p; 
    410     unsigned i; 
    411  
    412     p = (pj_uint8_t*)frm + sizeof(pjmedia_frame_ext); 
    413     for (i = 0; i < frm->subframe_cnt; ++i) { 
    414         fsub = (pjmedia_frame_ext_subframe*) p; 
    415         p += sizeof(fsub->bitlen) + ((fsub->bitlen+7) >> 3); 
    416     } 
    417  
    418     fsub = (pjmedia_frame_ext_subframe*) p; 
    419     fsub->bitlen = (pj_uint16_t)bitlen; 
    420     if (bitlen) 
    421         pj_memcpy(fsub->data, src, (bitlen+7) >> 3); 
    422  
    423     frm->subframe_cnt++; 
    424     frm->samples_cnt = (pj_uint16_t)(frm->samples_cnt + samples_cnt); 
    425 } 
    426  
    427 /** 
    428  * Get a subframe from #pjmedia_frame_ext. 
    429  * 
    430  * @param frm               The #pjmedia_frame_ext. 
    431  * @param n                 Subframe index, zero based. 
    432  * 
    433  * @return                  The n-th subframe, or NULL if n is out-of-range. 
    434  */ 
    435 PJ_INLINE(pjmedia_frame_ext_subframe*)  
    436 pjmedia_frame_ext_get_subframe(const pjmedia_frame_ext *frm, unsigned n) 
    437 { 
    438     pjmedia_frame_ext_subframe *sf = NULL; 
    439  
    440     if (n < frm->subframe_cnt) { 
    441         pj_uint8_t *p; 
    442         unsigned i; 
    443  
    444         p = (pj_uint8_t*)frm + sizeof(pjmedia_frame_ext); 
    445         for (i = 0; i < n; ++i) {        
    446             sf = (pjmedia_frame_ext_subframe*) p; 
    447             p += sizeof(sf->bitlen) + ((sf->bitlen+7) >> 3); 
    448         } 
    449          
    450         sf = (pjmedia_frame_ext_subframe*) p; 
    451     } 
    452  
    453     return sf; 
    454 } 
    455          
    456 /** 
    457  * Extract all frame payload to the specified buffer.  
    458  * 
    459  * @param frm               The frame. 
    460  * @param dst               Destination buffer. 
    461  * @param maxlen            Maximum size to copy (i.e. the size of the 
    462  *                          destination buffer). 
    463  * 
    464  * @return                  Total size of payload copied. 
    465  */ 
    466 PJ_INLINE(unsigned)  
    467 pjmedia_frame_ext_copy_payload(const pjmedia_frame_ext *frm, 
    468                                void *dst,  
    469                                unsigned maxlen) 
    470 { 
    471     unsigned i, copied=0; 
    472     for (i=0; i<frm->subframe_cnt; ++i) { 
    473         pjmedia_frame_ext_subframe *sf; 
    474         unsigned sz; 
    475  
    476         sf = pjmedia_frame_ext_get_subframe(frm, i); 
    477         if (!sf) 
    478             continue; 
    479  
    480         sz = ((sf->bitlen + 7) >> 3); 
    481         if (sz + copied > maxlen) 
    482             break; 
    483  
    484         pj_memcpy(((pj_uint8_t*)dst) + copied, sf->data, sz); 
    485         copied += sz; 
    486     } 
    487     return copied; 
    488 } 
    489  
    490  
    491 /** 
    492  * Pop out first n subframes from #pjmedia_frame_ext. 
    493  * 
    494  * @param frm               The #pjmedia_frame_ext. 
    495  * @param n                 Number of first subframes to be popped out. 
    496  * 
    497  * @return                  PJ_SUCCESS when successful. 
    498  */ 
    499 PJ_INLINE(pj_status_t)  
    500 pjmedia_frame_ext_pop_subframes(pjmedia_frame_ext *frm, unsigned n) 
    501 { 
    502     pjmedia_frame_ext_subframe *sf; 
    503     pj_uint8_t *move_src; 
    504     unsigned move_len; 
    505  
    506     if (frm->subframe_cnt <= n) { 
    507         frm->subframe_cnt = 0; 
    508         frm->samples_cnt = 0; 
    509         return PJ_SUCCESS; 
    510     } 
    511  
    512     move_src = (pj_uint8_t*)pjmedia_frame_ext_get_subframe(frm, n); 
    513     sf = pjmedia_frame_ext_get_subframe(frm, frm->subframe_cnt-1); 
    514     move_len = (pj_uint8_t*)sf - move_src + sizeof(sf->bitlen) +  
    515                ((sf->bitlen+7) >> 3); 
    516     pj_memmove((pj_uint8_t*)frm+sizeof(pjmedia_frame_ext),  
    517                move_src, move_len); 
    518              
    519     frm->samples_cnt = (pj_uint16_t) 
    520                    (frm->samples_cnt - n*frm->samples_cnt/frm->subframe_cnt); 
    521     frm->subframe_cnt = (pj_uint16_t) (frm->subframe_cnt - n); 
    522  
    523     return PJ_SUCCESS; 
    524 } 
     154    PJMEDIA_COORD_BASE_LEFT_BOTTOM 
     155 
     156} pjmedia_coord_base; 
     157 
     158/** 
     159 * This structure is used to represent rational numbers. 
     160 */ 
     161typedef struct pjmedia_ratio 
     162{ 
     163    int         num;    /** < Numerator. */ 
     164    int         denum;  /** < Denumerator. */ 
     165} pjmedia_ratio; 
     166 
     167/** 
     168 * This structure represent a coordinate. 
     169 */ 
     170typedef struct pjmedia_coord 
     171{ 
     172    int         x;      /**< X position of the coordinate */ 
     173    int         y;      /**< Y position of the coordinate */ 
     174} pjmedia_coord; 
     175 
     176/** 
     177 * This structure represents rectangle size. 
     178 */ 
     179typedef struct pjmedia_rect_size 
     180{ 
     181    unsigned    w;      /**< The width.         */ 
     182    unsigned    h;      /**< The height.        */ 
     183} pjmedia_rect_size; 
     184 
     185/** 
     186 * This structure describes a rectangle. 
     187 */ 
     188typedef struct pjmedia_rect 
     189{ 
     190    pjmedia_coord       coord;  /**< The position.      */ 
     191    pjmedia_rect_size   size;   /**< The size.          */ 
     192} pjmedia_rect; 
     193 
    525194 
    526195 
Note: See TracChangeset for help on using the changeset viewer.