Changeset 3461 for pjproject


Ignore:
Timestamp:
Mar 17, 2011 11:33:34 AM (13 years ago)
Author:
bennylp
Message:

Re #1215 (framework):

  • vstream:
    • allow NULL pool parameter which means vstream will create one
    • Updated remote FPS detection to only be performed if decoder returns frame (however the FPS detection is currently disabled as some endpoints changes fps continuously, causing renderer restart continuously too).
  • codec:
    • Updated video codec info to have RTP packetization support flag, also update endpoint in generating SDP to only include codecs whose RTP packetization support.
    • Added dynamic payload types for video codecs.
    • (minor) separate video PT into separate enum in pjmedia-codec/types.h
  • H264 initial experiment.

generated frames (for libx264 sake).

  • Replaced PJ_EUNKNOWN in some places with the appropriate error code.
Location:
pjproject/branches/projects/2.0-dev/pjmedia
Files:
8 edited

Legend:

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

    r3358 r3461  
    3939 
    4040/** 
    41  * These are the dynamic payload types that are used by codecs in 
     41 * These are the dynamic payload types that are used by audio codecs in 
    4242 * this library. Also see the header file <pjmedia/codec.h> for list 
    4343 * of static payload types. 
    4444 */ 
    45 enum 
     45enum pjmedia_audio_pt 
    4646{ 
    4747    /* According to IANA specifications, dynamic payload types are to be in 
     
    9999 
    100100/** 
     101 * These are the dynamic payload types that are used by video codecs in 
     102 * this library. 
     103 */ 
     104enum pjmedia_video_pt 
     105{ 
     106     /* Video payload types */ 
     107     PJMEDIA_RTP_PT_VID_START = (PJMEDIA_RTP_PT_DYNAMIC-1), 
     108     PJMEDIA_RTP_PT_H263P, 
     109     PJMEDIA_RTP_PT_H264, 
     110 
     111     /* Caution! 
     112      * Ensure the value of the last pt above is <= 127. 
     113      */ 
     114}; 
     115 
     116 
     117/** 
    101118 * @} 
    102119 */ 
  • pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/format.h

    r3449 r3461  
    183183    PJMEDIA_FORMAT_H263     = PJMEDIA_FORMAT_PACK('H', '2', '6', '3'), 
    184184    PJMEDIA_FORMAT_H263P    = PJMEDIA_FORMAT_PACK('P', '2', '6', '3'), 
     185    PJMEDIA_FORMAT_H264     = PJMEDIA_FORMAT_PACK('H', '2', '6', '4'), 
    185186 
    186187    PJMEDIA_FORMAT_MJPEG    = PJMEDIA_FORMAT_PACK('M', 'J', 'P', 'G'), 
     
    443444                       clock_rate / channel_count / 1000000)); 
    444445#elif PJ_HAS_FLOATING_POINT 
    445     return ((unsigned)(usec_ptime * clock_rate / channel_count / 1000000.0)); 
     446    return ((unsigned)(1.0*usec_ptime * clock_rate / channel_count / 1000000)); 
    446447#else 
    447448    return ((unsigned)(usec_ptime / 1000L * clock_rate / \ 
     
    449450#endif 
    450451} 
     452 
     453/** 
     454 * Variant of #PJMEDIA_SPF() which takes frame rate instead of ptime. 
     455 */ 
     456PJ_INLINE(unsigned) PJMEDIA_SPF2(unsigned clock_rate, const pjmedia_ratio *fr, 
     457                                 unsigned channel_count) 
     458{ 
     459#if PJ_HAS_INT64 
     460    return ((unsigned)((pj_uint64_t)clock_rate * fr->num \ 
     461                       / fr->denum / channel_count)); 
     462#elif PJ_HAS_FLOATING_POINT 
     463    return ((unsigned)(1.0 * clock_rate * fr->num /fr->denum /channel_count)); 
     464#else 
     465    return ((unsigned)(1L * clock_rate * fr->num / fr->denum / channel_count)); 
     466#endif 
     467} 
     468 
    451469 
    452470/** 
  • pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/vid_codec.h

    r3425 r3461  
    5959    pjmedia_ratio       fps[PJMEDIA_VID_CODEC_MAX_FPS_CNT]; 
    6060                                        /**< Supported frame-rates          */ 
     61    pj_bool_t           has_rtp_pack;   /**< Support RTP packetization      */ 
    6162} pjmedia_vid_codec_info; 
    6263 
  • pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/vid_stream.h

    r3425 r3461  
    160160 * 
    161161 * @param endpt         Media endpoint. 
    162  * @param pool          Pool to allocate memory for the stream. A large 
    163  *                      number of memory may be needed because jitter 
     162 * @param pool          Optional pool to allocate memory for the stream. If 
     163 *                      this is not specified, one will be created internally. 
     164 *                      A large number of memory may be needed because jitter 
    164165 *                      buffer needs to preallocate some storage. 
    165  * @param info          Stream information. 
    166  * @param tp            Stream transport instance used to transmit  
    167  *                      and receive RTP/RTCP packets to/from the underlying  
    168  *                      transport.  
     166 * @param info          Stream information to create the stream. Upon return, 
     167 *                      this info will be updated with the information from 
     168 *                      the instantiated codec. Note that if the "pool" 
     169 *                      argument is NULL, some fields in this "info" parameter 
     170 *                      will be allocated from the internal pool of the 
     171 *                      stream, which means that they will only remain valid 
     172 *                      as long as the stream is not destroyed. 
     173 * @param tp            Media transport instance used to transmit and receive 
     174 *                      RTP/RTCP packets to/from the underlying network. 
    169175 * @param user_data     Arbitrary user data (for future callback feature). 
    170176 * @param p_stream      Pointer to receive the video stream. 
     
    175181                                        pjmedia_endpt *endpt, 
    176182                                        pj_pool_t *pool, 
    177                                         const pjmedia_vid_stream_info *info, 
     183                                        pjmedia_vid_stream_info *info, 
    178184                                        pjmedia_transport *tp, 
    179185                                        void *user_data, 
  • pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-codec/ffmpeg_codecs.c

    r3435 r3461  
    246246{ 
    247247    { 
    248         {PJMEDIA_FORMAT_H263P,  {"H263-1998",9},    PJMEDIA_RTP_PT_H263}, 
     248        {PJMEDIA_FORMAT_H263P,  {"H263-1998",9},    PJMEDIA_RTP_PT_H263P}, 
    249249        PJMEDIA_FORMAT_H263,    1000000,    2000000, 
    250250        &h263_packetize, &h263_unpacketize, &h263_parse_fmtp, 
     
    258258    }, 
    259259    { 
     260        {PJMEDIA_FORMAT_H264,   {"H264",4},         PJMEDIA_RTP_PT_H264}, 
     261    }, 
     262    { 
    260263        {PJMEDIA_FORMAT_H261,   {"H261",4},         PJMEDIA_RTP_PT_H261}, 
    261264    }, 
     
    264267    }, 
    265268    { 
    266         {PJMEDIA_FORMAT_MPEG4,  {"MP4V",4},         PJMEDIA_RTP_PT_MPV}, 
     269        {PJMEDIA_FORMAT_MPEG4,  {"MP4V",4}}, 
    267270    }, 
    268271    { 
    269         {PJMEDIA_FORMAT_XVID,   {"XVID",4},         PJMEDIA_RTP_PT_MPV}, 
     272        {PJMEDIA_FORMAT_XVID,   {"XVID",4}}, 
    270273        PJMEDIA_FORMAT_MPEG4, 
    271274    }, 
     
    452455                PJ_TODO(NOTIFY_APP_ABOUT_THIS_NEW_ENCODING_FORMAT); 
    453456            } else { 
    454                 return PJ_EUNKNOWN; 
     457                return PJMEDIA_EBADFMT; 
    455458            } 
    456459        } 
     
    532535    avcodec_init(); 
    533536    avcodec_register_all(); 
     537    av_log_set_level(AV_LOG_ERROR); 
    534538 
    535539    /* Enum FFMPEG codecs */ 
     
    649653        if (desc->info.clock_rate == 0) 
    650654            desc->info.clock_rate = 90000; 
     655 
     656        /* Set RTP packetization support flag in the codec info */ 
     657        desc->info.has_rtp_pack = (desc->packetize != NULL) && 
     658                                  (desc->unpacketize != NULL); 
    651659    } 
    652660 
     
    9941002            if (vfd->avg_bps) { 
    9951003                ctx->bit_rate = vfd->avg_bps; 
    996                 if (vfd->max_bps) 
     1004                if (vfd->max_bps > vfd->avg_bps) 
    9971005                    ctx->bit_rate_tolerance = vfd->max_bps - vfd->avg_bps; 
     1006            } 
     1007 
     1008            /* Libx264 experimental setting (it rejects ffmpeg defaults) */ 
     1009            if (ff->param.enc_fmt.id == PJMEDIA_FORMAT_H264) { 
     1010                ctx->me_range = 16; 
     1011                ctx->max_qdiff = 4; 
     1012                ctx->qmin = 10; 
     1013                ctx->qmax = 51; 
     1014                ctx->qcompress = 0.6f; 
    9981015            } 
    9991016 
     
    10271044        if (err < 0) { 
    10281045            print_ffmpeg_err(err); 
    1029             return PJ_EUNKNOWN; 
     1046            return PJMEDIA_CODEC_EFAILED; 
    10301047        } 
    10311048 
     
    12191236 
    12201237    avcodec_get_frame_defaults(&avframe); 
     1238    avframe.pts = input->timestamp.u64; 
    12211239     
    12221240    for (i = 0; i < ff->enc_vfi->plane_cnt; ++i) { 
     
    12491267    if (err < 0) { 
    12501268        print_ffmpeg_err(err); 
    1251         return PJ_EUNKNOWN; 
     1269        return PJMEDIA_CODEC_EFAILED; 
    12521270    } else { 
    12531271        output->size = err; 
     
    13011319 
    13021320    output->bit_info = 0; 
     1321    output->timestamp = input->timestamp; 
    13031322 
    13041323#if LIBAVCODEC_VERSION_MAJOR >= 52 && LIBAVCODEC_VERSION_MINOR >= 72 
     
    13161335#endif 
    13171336    if (err < 0) { 
     1337        output->type = PJMEDIA_FRAME_TYPE_NONE; 
     1338        output->size = 0; 
    13181339        print_ffmpeg_err(err); 
    1319         return PJ_EUNKNOWN; 
     1340        return PJMEDIA_CODEC_EFAILED; 
    13201341    } else if (got_picture) { 
    13211342        pjmedia_video_apply_fmt_param *vafp = &ff->dec_vafp; 
     
    13471368            ff->dec_vfi = pjmedia_get_video_format_info(NULL, ff->param.dec_fmt.id); 
    13481369            if (!ff->dec_vfi) 
    1349                 return PJ_EUNKNOWN; 
     1370                return PJ_ENOTSUP; 
    13501371            pj_bzero(&ff->dec_vafp, sizeof(ff->dec_vafp)); 
    13511372            ff->dec_vafp.size = ff->param.dec_fmt.det.vid.size; 
     
    13851406        } 
    13861407 
     1408        output->type = PJMEDIA_FRAME_TYPE_VIDEO; 
    13871409        output->size = vafp->framebytes; 
    13881410    } else { 
    1389         return PJ_EUNKNOWN; 
    1390     } 
    1391  
     1411        output->type = PJMEDIA_FRAME_TYPE_NONE; 
     1412        output->size = 0; 
     1413    } 
     1414     
    13921415    return PJ_SUCCESS; 
    13931416} 
  • pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/endpoint.c

    r3450 r3461  
    546546    pj_status_t status; 
    547547 
     548    PJ_UNUSED_ARG(options); 
     549 
    548550    /* Make sure video codec manager is instantiated */ 
    549551    if (!pjmedia_vid_codec_mgr_instance()) 
     
    584586        } 
    585587 
    586         /* Payload type */ 
    587         if (codec_info[i].pt == 255) { 
    588             PJ_TODO(ALLOCATE_DYNAMIC_PAYLOAD_TYPE); 
     588        /* Must support RTP packetization and bidirectional */ 
     589        if (!codec_info[i].has_rtp_pack || 
     590            codec_info[i].dir != PJMEDIA_DIR_ENCODING_DECODING) 
     591        { 
    589592            continue; 
    590593        } 
  • pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/ffmpeg_util.c

    r3425 r3461  
    5555    {PJMEDIA_FORMAT_H263,       CODEC_ID_H263}, 
    5656    {PJMEDIA_FORMAT_H263P,      CODEC_ID_H263P}, 
     57    {PJMEDIA_FORMAT_H264,       CODEC_ID_H264}, 
    5758    {PJMEDIA_FORMAT_MPEG1VIDEO, CODEC_ID_MPEG1VIDEO}, 
    5859    {PJMEDIA_FORMAT_MPEG2VIDEO, CODEC_ID_MPEG2VIDEO}, 
  • pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/vid_stream.c

    r3435 r3461  
    5555#endif 
    5656 
     57#ifndef PJMEDIA_VSTREAM_SIZE 
     58#   define PJMEDIA_VSTREAM_SIZE 1000 
     59#endif 
     60 
     61#ifndef PJMEDIA_VSTREAM_INC 
     62#   define PJMEDIA_VSTREAM_INC  1000 
     63#endif 
    5764 
    5865 
     
    8390struct pjmedia_vid_stream 
    8491{ 
     92    pj_pool_t               *own_pool;      /**< Internal pool.             */ 
    8593    pjmedia_endpt           *endpt;         /**< Media endpoint.            */ 
    8694    pjmedia_vid_codec_mgr   *codec_mgr;     /**< Codec manager.             */ 
     
    766774 
    767775    while (processed < frame_out.size) { 
    768         pj_uint8_t *payload, *rtp_pkt; 
     776        pj_uint8_t *payload; 
     777        pj_uint8_t *rtp_pkt; 
    769778        pj_size_t payload_len; 
    770779 
     
    775784                                           frame_out.size, 
    776785                                           &processed, 
    777                                            &payload, &payload_len); 
     786                                           (const pj_uint8_t**)&payload, 
     787                                           &payload_len); 
    778788        if (status != PJ_SUCCESS) { 
    779789            LOGERR_((channel->port.info.name.ptr,  
     
    843853    pjmedia_vid_channel *channel = stream->dec; 
    844854    pjmedia_frame frame_in; 
    845     pj_bool_t fps_changed = PJ_FALSE; 
    846     pjmedia_ratio new_fps = {0}; 
     855    pj_uint32_t last_ts = 0; 
     856    int frm_first_seq = 0, frm_last_seq = 0; 
    847857    pj_status_t status; 
    848858 
     
    860870        char ptype; 
    861871        pj_size_t psize, data_len; 
    862         pj_uint32_t ts, last_ts; 
     872        pj_uint32_t ts; 
    863873        int seq; 
    864         pj_bool_t got_frame, check_fps; 
     874        pj_bool_t got_frame; 
    865875        unsigned i; 
    866876 
    867877        channel->buf_len = 0; 
    868         last_ts = 0; 
    869878        got_frame = PJ_FALSE; 
    870         check_fps = PJ_FALSE; 
    871879 
    872880        /* Lock jitter buffer mutex first */ 
     
    875883        for (i=0; ; ++i) { 
    876884            /* Get frame from jitter buffer. */ 
    877             pjmedia_jbuf_peek_frame(stream->jb, i, &p, &psize, &ptype, 
    878                                     NULL, &ts, &seq); 
     885            pjmedia_jbuf_peek_frame(stream->jb, i, (const void**)&p, 
     886                                    &psize, &ptype, NULL, &ts, &seq); 
    879887            if (ptype == PJMEDIA_JB_NORMAL_FRAME) { 
    880888                if (last_ts == 0) { 
    881889                    last_ts = ts; 
    882                     check_fps = stream->last_dec_ts && 
    883                                 (seq - stream->last_dec_seq == 1) && 
    884                                 (last_ts > stream->last_dec_ts); 
     890                    frm_first_seq = seq; 
    885891                } 
    886892 
     
    897903                                                           data, &data_len); 
    898904                channel->buf_len += data_len; 
     905                frm_last_seq = seq; 
    899906            } else if (ptype == PJMEDIA_JB_ZERO_EMPTY_FRAME) { 
    900907                /* No more packet in the jitter buffer */ 
     
    911918            return PJ_SUCCESS; 
    912919        } 
    913  
    914         /* Learn remote frame rate */ 
    915         if (check_fps) { 
    916             pj_uint32_t ts_diff; 
    917             pjmedia_video_format_detail *vfd; 
    918  
    919             ts_diff = last_ts - stream->last_dec_ts; 
    920             vfd = pjmedia_format_get_video_format_detail( 
    921                                     &channel->port.info.fmt, PJ_TRUE); 
    922             if (ts_diff * vfd->fps.num != 
    923                 stream->info.codec_info.clock_rate * vfd->fps.denum) 
    924             { 
    925                 /* Frame rate changed */ 
    926                 fps_changed = PJ_TRUE; 
    927                 new_fps.num = stream->info.codec_info.clock_rate; 
    928                 new_fps.denum = ts_diff; 
    929             } 
    930         } 
    931  
    932         /* Update last frame seq and timestamp */ 
    933         stream->last_dec_seq = seq - 1; 
    934         stream->last_dec_ts = last_ts; 
    935920    } 
    936921 
     
    940925    frame_in.bit_info = 0; 
    941926    frame_in.type = PJMEDIA_FRAME_TYPE_VIDEO; 
     927    frame_in.timestamp.u64 = last_ts; 
    942928 
    943929    status = stream->codec->op->decode(stream->codec, &frame_in, 
     
    960946    } 
    961947 
    962     if (fps_changed) { 
    963         pjmedia_video_format_detail *vfd; 
    964  
    965         /* Update decoding channel port info */ 
    966         vfd = pjmedia_format_get_video_format_detail( 
    967                                 &channel->port.info.fmt, PJ_TRUE); 
    968         vfd->fps = new_fps; 
    969  
    970         /* Update stream info */ 
    971         vfd = pjmedia_format_get_video_format_detail( 
    972                                 &stream->info.codec_param->dec_fmt, PJ_TRUE); 
    973         vfd->fps = new_fps; 
    974  
    975         /* Set bit_info */ 
    976         frame->bit_info |= PJMEDIA_VID_CODEC_EVENT_FMT_CHANGED; 
    977  
    978         PJ_LOG(4, (channel->port.info.name.ptr, "Frame rate changed to %.2ffps", 
    979                    (1.0 * new_fps.num / new_fps.denum))); 
    980     } 
     948    /* Learn remote frame rate after successful decoding */ 
     949    if (0 && frame->type == PJMEDIA_FRAME_TYPE_VIDEO && frame->size) 
     950    { 
     951        /* Only check remote frame rate when timestamp is not wrapping and 
     952         * sequence is increased by 1. 
     953         */ 
     954        if (last_ts > stream->last_dec_ts && 
     955            frm_first_seq - stream->last_dec_seq == 1) 
     956        { 
     957            pj_uint32_t ts_diff; 
     958            pjmedia_video_format_detail *vfd; 
     959 
     960            ts_diff = last_ts - stream->last_dec_ts; 
     961            vfd = pjmedia_format_get_video_format_detail( 
     962                                    &channel->port.info.fmt, PJ_TRUE); 
     963            if ((int)(stream->info.codec_info.clock_rate / ts_diff) != 
     964                vfd->fps.num / vfd->fps.denum) 
     965            { 
     966                /* Frame rate changed, update decoding port info */ 
     967                vfd->fps.num = stream->info.codec_info.clock_rate; 
     968                vfd->fps.denum = ts_diff; 
     969 
     970                /* Update stream info */ 
     971                stream->info.codec_param->dec_fmt.det.vid.fps = vfd->fps; 
     972 
     973                /* Set bit_info */ 
     974                frame->bit_info |= PJMEDIA_VID_CODEC_EVENT_FMT_CHANGED; 
     975 
     976                PJ_LOG(5, (channel->port.info.name.ptr, "Frame rate changed to %.2ffps", 
     977                           (1.0 * vfd->fps.num / vfd->fps.denum))); 
     978            } 
     979        } 
     980 
     981        /* Update last frame seq and timestamp */ 
     982        stream->last_dec_seq = frm_last_seq; 
     983        stream->last_dec_ts = last_ts; 
     984    } 
     985 
     986#if PJ_LOG_MAX_LEVEL >= 5 
     987    if (frame->bit_info & PJMEDIA_VID_CODEC_EVENT_FMT_CHANGED) { 
     988        pjmedia_port_info *pi = &channel->port.info; 
     989 
     990        PJ_LOG(5, (channel->port.info.name.ptr, 
     991                   "Decoding format changed to %dx%d %c%c%c%c %.2ffps", 
     992                   pi->fmt.det.vid.size.w, pi->fmt.det.vid.size.h, 
     993                   ((pi->fmt.id & 0x000000FF) >> 0), 
     994                   ((pi->fmt.id & 0x0000FF00) >> 8), 
     995                   ((pi->fmt.id & 0x00FF0000) >> 16), 
     996                   ((pi->fmt.id & 0xFF000000) >> 24), 
     997                   (1.0*pi->fmt.det.vid.fps.num/pi->fmt.det.vid.fps.denum))); 
     998    } 
     999#endif 
    9811000 
    9821001    return PJ_SUCCESS; 
     
    10011020    const char *type_name; 
    10021021    pjmedia_format *fmt; 
     1022    pjmedia_port_info *pi; 
    10031023     
    10041024    pj_assert(info->type == PJMEDIA_TYPE_VIDEO); 
     
    10171037        fmt = &info->codec_param->enc_fmt; 
    10181038    } 
    1019  
    10201039    name.ptr = (char*) pj_pool_alloc(pool, M); 
    10211040    name.slen = pj_ansi_snprintf(name.ptr, M, "%s%p", type_name, stream); 
     1041    pi = &channel->port.info; 
    10221042 
    10231043    /* Init channel info. */ 
     
    10591079 
    10601080    /* Init port. */ 
    1061     pjmedia_port_info_init2(&channel->port.info, &name, 
     1081    pjmedia_port_info_init2(pi, &name, 
    10621082                            PJMEDIA_PORT_SIGNATURE('V', 'C', 'H', 'N'), 
    10631083                            dir, fmt); 
     
    10651085        channel->port.get_frame = &get_frame; 
    10661086    } else { 
     1087        pi->fmt.id = info->codec_param->dec_fmt.id; 
    10671088        channel->port.put_frame = &put_frame; 
    10681089    } 
     
    10701091    /* Init port. */ 
    10711092    channel->port.port_data.pdata = stream; 
     1093 
     1094    PJ_LOG(5, (name.ptr, "%s channel created %dx%d %c%c%c%c%s%.*s %.2ffps", 
     1095               (dir==PJMEDIA_DIR_ENCODING?"Encoding":"Decoding"), 
     1096               pi->fmt.det.vid.size.w, pi->fmt.det.vid.size.h, 
     1097               ((pi->fmt.id & 0x000000FF) >> 0), 
     1098               ((pi->fmt.id & 0x0000FF00) >> 8), 
     1099               ((pi->fmt.id & 0x00FF0000) >> 16), 
     1100               ((pi->fmt.id & 0xFF000000) >> 24), 
     1101               (dir==PJMEDIA_DIR_ENCODING?"->":"<-"), 
     1102               info->codec_info.encoding_name.slen, 
     1103               info->codec_info.encoding_name.ptr, 
     1104               (1.0*pi->fmt.det.vid.fps.num/pi->fmt.det.vid.fps.denum))); 
    10721105 
    10731106    /* Done. */ 
     
    10831116                                        pjmedia_endpt *endpt, 
    10841117                                        pj_pool_t *pool, 
    1085                                         const pjmedia_vid_stream_info *info, 
     1118                                        pjmedia_vid_stream_info *info, 
    10861119                                        pjmedia_transport *tp, 
    10871120                                        void *user_data, 
     
    10891122{ 
    10901123    enum { M = 32 }; 
     1124    pj_pool_t *own_pool = NULL; 
    10911125    pjmedia_vid_stream *stream; 
    10921126    unsigned jb_init, jb_max, jb_min_pre, jb_max_pre, len; 
     
    10961130    pj_status_t status; 
    10971131 
     1132    if (!pool) { 
     1133        own_pool = pjmedia_endpt_create_pool( endpt, "vstrm%p", 
     1134                                              PJMEDIA_VSTREAM_SIZE, 
     1135                                              PJMEDIA_VSTREAM_INC); 
     1136        PJ_ASSERT_RETURN(own_pool != NULL, PJ_ENOMEM); 
     1137        pool = own_pool; 
     1138    } 
     1139 
    10981140    /* Allocate stream */ 
    10991141    stream = PJ_POOL_ZALLOC_T(pool, pjmedia_vid_stream); 
    11001142    PJ_ASSERT_RETURN(stream != NULL, PJ_ENOMEM); 
    1101  
    1102     /* Copy stream info */ 
    1103     pj_memcpy(&stream->info, info, sizeof(*info)); 
     1143    stream->own_pool = own_pool; 
    11041144 
    11051145    /* Get codec manager */ 
     
    11211161 
    11221162    /* Get codec param: */ 
    1123     if (info->codec_param) { 
    1124         stream->info.codec_param = pjmedia_vid_codec_param_clone( 
    1125                                                         pool, 
    1126                                                         info->codec_param); 
    1127     } else { 
     1163    if (!info->codec_param) { 
    11281164        pjmedia_vid_codec_param def_param; 
    11291165 
     
    11331169        if (status != PJ_SUCCESS) 
    11341170            return status; 
    1135         stream->info.codec_param = pjmedia_vid_codec_param_clone( 
    1136                                                         pool, 
    1137                                                         &def_param); 
    1138         pj_assert(stream->info.codec_param); 
     1171 
     1172        info->codec_param = pjmedia_vid_codec_param_clone(pool, &def_param); 
     1173        pj_assert(info->codec_param); 
    11391174    } 
    11401175 
    11411176    vfd_enc = pjmedia_format_get_video_format_detail( 
    1142                                         &stream->info.codec_param->enc_fmt, 
    1143                                         PJ_TRUE); 
     1177                                        &info->codec_param->enc_fmt, PJ_TRUE); 
    11441178 
    11451179    /* Init stream: */ 
     
    11741208 
    11751209    /* Init codec param */ 
    1176     stream->info.codec_param->dir = info->dir; 
    1177     stream->info.codec_param->enc_mtu = PJMEDIA_MAX_MTU -  
    1178                                         sizeof(pjmedia_rtp_hdr); 
     1210    info->codec_param->dir = info->dir; 
     1211    info->codec_param->enc_mtu = PJMEDIA_MAX_MTU - sizeof(pjmedia_rtp_hdr); 
    11791212 
    11801213    /* Init and open the codec. */ 
     
    11821215    if (status != PJ_SUCCESS) 
    11831216        return status; 
    1184     status = stream->codec->op->open(stream->codec, stream->info.codec_param); 
     1217    status = stream->codec->op->open(stream->codec, info->codec_param); 
    11851218    if (status != PJ_SUCCESS) 
    11861219        return status; 
     
    13311364#endif 
    13321365 
     1366    /* Save the stream info */ 
     1367    pj_memcpy(&stream->info, info, sizeof(*info)); 
     1368    stream->info.codec_param = pjmedia_vid_codec_param_clone( 
     1369                                                pool, info->codec_param); 
     1370 
    13331371    /* Success! */ 
    13341372    *p_stream = stream; 
    13351373 
    1336     PJ_LOG(5,(THIS_FILE, "Stream %s created", stream->name.ptr)); 
     1374    PJ_LOG(5,(THIS_FILE, "Video stream %s created", stream->name.ptr)); 
    13371375 
    13381376    return PJ_SUCCESS; 
     
    14351473#endif 
    14361474 
     1475    if (stream->own_pool) { 
     1476        pj_pool_t *pool = stream->own_pool; 
     1477        stream->own_pool = NULL; 
     1478        pj_pool_release(pool); 
     1479    } 
     1480 
    14371481    return PJ_SUCCESS; 
    14381482} 
    1439  
    14401483 
    14411484 
Note: See TracChangeset for help on using the changeset viewer.