Ignore:
Timestamp:
Feb 28, 2011 6:59:47 PM (13 years ago)
Author:
nanang
Message:

Re #1182:

  • Renamed vstreamutil.c to vid_steamutil.c just for filename format consistency reason.
  • Updated sample app simpleua.c and vid_streamutil.c to sync with updated API, e.g: strip session usage, two media ports exported video streams for each dir.
  • Added vid_streamutil.c capability to be able to stream video file (involving transcoding when video codec used in the file different to the video stream codec), also updated AVI player and ffmpeg codecs to be able to read and decode XVID/MPEG4 codec.
  • Fixed bug wrong media type check in stream.c and vid_stream.c in creating stream info from SDP.
  • Minor update: docs, logs, app samples makefiles.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/vid_stream.c

    r3420 r3425  
    8585    pjmedia_endpt           *endpt;         /**< Media endpoint.            */ 
    8686    pjmedia_vid_codec_mgr   *codec_mgr;     /**< Codec manager.             */ 
     87    pjmedia_vid_stream_info  info;          /**< Stream info.               */ 
    8788 
    8889    pjmedia_vid_channel     *enc;           /**< Encoding channel.          */ 
     
    129130 
    130131#if TRACE_JB 
    131     pj_oshandle_t           trace_jb_fd;            /**< Jitter tracing file handle.*/ 
    132     char                   *trace_jb_buf;           /**< Jitter tracing buffer.     */ 
     132    pj_oshandle_t            trace_jb_fd;   /**< Jitter tracing file handle.*/ 
     133    char                    *trace_jb_buf;  /**< Jitter tracing buffer.     */ 
    133134#endif 
    134135 
    135     pjmedia_vid_codec       *codec;                 /**< Codec instance being used. */ 
    136     pjmedia_vid_codec_info   codec_info;           /**< Codec param.                */ 
    137     pjmedia_vid_codec_param  codec_param;          /**< Codec param.                */ 
    138  
    139     pjmedia_vid_stream_info     info; 
     136    pjmedia_vid_codec       *codec;         /**< Codec instance being used. */ 
    140137}; 
    141138 
     
    627624        status = pjmedia_jbuf_reset(stream->jb); 
    628625        PJ_LOG(4,(channel->port.info.name.ptr, "Jitter buffer reset")); 
    629  
    630626    } else { 
    631  
    632         /* Video stream */ 
    633  
    634627        /* Just put the payload into jitter buffer */ 
    635628        pjmedia_jbuf_put_frame3(stream->jb, payload, payloadlen, 0,  
     
    928921    if (frame->bit_info & PJMEDIA_VID_CODEC_EVENT_FMT_CHANGED) { 
    929922        /* Update param from codec */ 
    930         stream->codec->op->get_param(stream->codec, &stream->codec_param); 
     923        stream->codec->op->get_param(stream->codec, stream->info.codec_param); 
    931924 
    932925        /* Update decoding channel port info */ 
    933         stream->dec->port.info.fmt = stream->codec_param.dec_fmt; 
     926        pjmedia_format_copy(&stream->dec->port.info.fmt, 
     927                            &stream->info.codec_param->dec_fmt); 
    934928    } 
    935929     
     
    965959    /* Init vars */ 
    966960    if (dir==PJMEDIA_DIR_DECODING) { 
    967         type_name = "vstrmdec"; 
     961        type_name = "vstdec"; 
    968962        fmt = &info->codec_param->dec_fmt; 
    969963    } else { 
    970         type_name = "vstrmenc"; 
     964        type_name = "vstenc"; 
    971965        fmt = &info->codec_param->enc_fmt; 
    972966    } 
     
    10541048    PJ_ASSERT_RETURN(stream != NULL, PJ_ENOMEM); 
    10551049 
     1050    /* Copy stream info */ 
     1051    pj_memcpy(&stream->info, info, sizeof(*info)); 
     1052 
    10561053    /* Get codec manager */ 
    10571054    stream->codec_mgr = pjmedia_vid_codec_mgr_instance(); 
     
    10641061 
    10651062    /* Create and initialize codec: */ 
    1066     stream->codec_info = info->codec_info; 
    10671063    status = pjmedia_vid_codec_mgr_alloc_codec(stream->codec_mgr,  
    10681064                                               &info->codec_info, 
     
    10731069 
    10741070    /* Get codec param: */ 
    1075     if (info->codec_param) 
    1076         stream->codec_param = *info->codec_param; 
    1077     else { 
     1071    if (info->codec_param) { 
     1072        stream->info.codec_param = pjmedia_vid_codec_param_clone( 
     1073                                                        pool, 
     1074                                                        info->codec_param); 
     1075    } else { 
     1076        pjmedia_vid_codec_param def_param; 
     1077 
    10781078        status = pjmedia_vid_codec_mgr_get_default_param(stream->codec_mgr,  
    10791079                                                         &info->codec_info, 
    1080                                                          &stream->codec_param); 
     1080                                                         &def_param); 
    10811081        if (status != PJ_SUCCESS) 
    10821082            return status; 
     1083        stream->info.codec_param = pjmedia_vid_codec_param_clone( 
     1084                                                        pool, 
     1085                                                        &def_param); 
     1086        pj_assert(stream->info.codec_param); 
    10831087    } 
    10841088 
    10851089    vfd_enc = pjmedia_format_get_video_format_detail( 
    1086                                             &stream->codec_param.enc_fmt, 1); 
     1090                                        &stream->info.codec_param->enc_fmt, 
     1091                                        PJ_TRUE); 
    10871092 
    10881093    /* Init stream: */ 
     
    11171122 
    11181123    /* Init codec param */ 
    1119     stream->codec_param.dir = info->dir; 
    1120     stream->codec_param.enc_mtu = PJMEDIA_MAX_MTU - sizeof(pjmedia_rtp_hdr); 
     1124    stream->info.codec_param->dir = info->dir; 
     1125    stream->info.codec_param->enc_mtu = PJMEDIA_MAX_MTU -  
     1126                                        sizeof(pjmedia_rtp_hdr); 
    11211127 
    11221128    /* Init and open the codec. */ 
     
    11241130    if (status != PJ_SUCCESS) 
    11251131        return status; 
    1126     status = stream->codec->op->open(stream->codec, &stream->codec_param); 
     1132    status = stream->codec->op->open(stream->codec, stream->info.codec_param); 
    11271133    if (status != PJ_SUCCESS) 
    11281134        return status; 
     
    11401146    /* Validate the frame size */ 
    11411147    if (stream->frame_size == 0 ||  
    1142         stream->frame_size > PJMEDIA_MAX_VIDEO_FRAME_SIZE) 
     1148        stream->frame_size > PJMEDIA_MAX_VIDEO_ENC_FRAME_SIZE) 
    11431149    { 
    1144         stream->frame_size = PJMEDIA_MAX_VIDEO_FRAME_SIZE; 
     1150        stream->frame_size = PJMEDIA_MAX_VIDEO_ENC_FRAME_SIZE; 
    11451151    } 
    11461152 
     
    11511157    /* Create decoder channel */ 
    11521158    status = create_channel( pool, stream, PJMEDIA_DIR_DECODING,  
    1153                              info->codec_info.pt, info, &stream->dec); 
     1159                             info->rx_pt, info, &stream->dec); 
    11541160    if (status != PJ_SUCCESS) 
    11551161        return status; 
     
    14081414 
    14091415/* 
     1416 * Get stream statistics. 
     1417 */ 
     1418PJ_DEF(pj_status_t) pjmedia_vid_stream_get_stat( 
     1419                                            const pjmedia_vid_stream *stream, 
     1420                                            pjmedia_rtcp_stat *stat) 
     1421{ 
     1422    PJ_ASSERT_RETURN(stream && stat, PJ_EINVAL); 
     1423 
     1424    pj_memcpy(stat, &stream->rtcp.stat, sizeof(pjmedia_rtcp_stat)); 
     1425    return PJ_SUCCESS; 
     1426} 
     1427 
     1428 
     1429/* 
     1430 * Reset the stream statistics in the middle of a stream session. 
     1431 */ 
     1432PJ_DEF(pj_status_t) pjmedia_vid_stream_reset_stat(pjmedia_vid_stream *stream) 
     1433{ 
     1434    PJ_ASSERT_RETURN(stream, PJ_EINVAL); 
     1435 
     1436    pjmedia_rtcp_init_stat(&stream->rtcp.stat); 
     1437 
     1438    return PJ_SUCCESS; 
     1439} 
     1440 
     1441 
     1442#if defined(PJMEDIA_HAS_RTCP_XR) && (PJMEDIA_HAS_RTCP_XR != 0) 
     1443/* 
     1444 * Get stream extended statistics. 
     1445 */ 
     1446PJ_DEF(pj_status_t) pjmedia_stream_get_stat_xr( 
     1447                                            const pjmedia_vid_stream *stream, 
     1448                                            pjmedia_rtcp_xr_stat *stat) 
     1449{ 
     1450    PJ_ASSERT_RETURN(stream && stat, PJ_EINVAL); 
     1451 
     1452    if (stream->rtcp.xr_enabled) { 
     1453        pj_memcpy(stat, &stream->rtcp.xr_session.stat, 
     1454                  sizeof(pjmedia_rtcp_xr_stat)); 
     1455        return PJ_SUCCESS; 
     1456    } 
     1457    return PJ_ENOTFOUND; 
     1458} 
     1459#endif 
     1460 
     1461/* 
     1462 * Get jitter buffer state. 
     1463 */ 
     1464PJ_DEF(pj_status_t) pjmedia_vid_stream_get_stat_jbuf( 
     1465                                            const pjmedia_vid_stream *stream, 
     1466                                            pjmedia_jb_state *state) 
     1467{ 
     1468    PJ_ASSERT_RETURN(stream && state, PJ_EINVAL); 
     1469    return pjmedia_jbuf_get_state(stream->jb, state); 
     1470} 
     1471 
     1472 
     1473/* 
     1474 * Get the stream info. 
     1475 */ 
     1476PJ_DEF(pj_status_t) pjmedia_vid_stream_get_info( 
     1477                                            const pjmedia_vid_stream *stream, 
     1478                                            pjmedia_vid_stream_info *info) 
     1479{ 
     1480    PJ_ASSERT_RETURN(stream && info, PJ_EINVAL); 
     1481    pj_memcpy(info, &stream->info, sizeof(*info)); 
     1482    return PJ_SUCCESS; 
     1483} 
     1484 
     1485 
     1486/* 
    14101487 * Start stream. 
    14111488 */ 
     
    14341511} 
    14351512 
    1436  
    1437 /* 
    1438  * Get stream statistics. 
    1439  */ 
    1440 PJ_DEF(pj_status_t) pjmedia_vid_stream_get_stat( 
    1441                                             const pjmedia_vid_stream *stream, 
    1442                                             pjmedia_rtcp_stat *stat) 
    1443 { 
    1444     PJ_ASSERT_RETURN(stream && stat, PJ_EINVAL); 
    1445  
    1446     pj_memcpy(stat, &stream->rtcp.stat, sizeof(pjmedia_rtcp_stat)); 
    1447     return PJ_SUCCESS; 
    1448 } 
    1449  
    1450  
    1451 /* 
    1452  * Reset the stream statistics in the middle of a stream session. 
    1453  */ 
    1454 PJ_DEF(pj_status_t) pjmedia_vid_stream_reset_stat(pjmedia_vid_stream *stream) 
    1455 { 
    1456     PJ_ASSERT_RETURN(stream, PJ_EINVAL); 
    1457  
    1458     pjmedia_rtcp_init_stat(&stream->rtcp.stat); 
    1459  
    1460     return PJ_SUCCESS; 
    1461 } 
    1462  
    1463  
    1464 #if defined(PJMEDIA_HAS_RTCP_XR) && (PJMEDIA_HAS_RTCP_XR != 0) 
    1465 /* 
    1466  * Get stream extended statistics. 
    1467  */ 
    1468 PJ_DEF(pj_status_t) pjmedia_stream_get_stat_xr( 
    1469                                             const pjmedia_vid_stream *stream, 
    1470                                             pjmedia_rtcp_xr_stat *stat) 
    1471 { 
    1472     PJ_ASSERT_RETURN(stream && stat, PJ_EINVAL); 
    1473  
    1474     if (stream->rtcp.xr_enabled) { 
    1475         pj_memcpy(stat, &stream->rtcp.xr_session.stat, 
    1476                   sizeof(pjmedia_rtcp_xr_stat)); 
    1477         return PJ_SUCCESS; 
    1478     } 
    1479     return PJ_ENOTFOUND; 
    1480 } 
    1481 #endif 
    1482  
    1483 /* 
    1484  * Get jitter buffer state. 
    1485  */ 
    1486 PJ_DEF(pj_status_t) pjmedia_vid_stream_get_stat_jbuf( 
    1487                                             const pjmedia_vid_stream *stream, 
    1488                                             pjmedia_jb_state *state) 
    1489 { 
    1490     PJ_ASSERT_RETURN(stream && state, PJ_EINVAL); 
    1491     return pjmedia_jbuf_get_state(stream->jb, state); 
    1492 } 
    14931513 
    14941514/* 
     
    15791599     */ 
    15801600    pt = pj_strtoul(&local_m->desc.fmt[0]); 
     1601    si->rx_pt = pt; 
    15811602    if (pt < 96) { 
    15821603        const pjmedia_vid_codec_info *p_info; 
     
    16601681 
    16611682    /* Get local fmtp for our decoder. */ 
    1662     pjmedia_stream_info_parse_fmtp(pool, local_m, pt, 
     1683    pjmedia_stream_info_parse_fmtp(pool, local_m, si->rx_pt, 
    16631684                                   &si->codec_param->dec_fmtp); 
    16641685 
     
    17181739 
    17191740    /* Media type must be audio */ 
    1720     if (pj_stricmp(&local_m->desc.media, &ID_VIDEO) == 0) 
     1741    if (pj_stricmp(&local_m->desc.media, &ID_VIDEO) != 0) 
    17211742        return PJMEDIA_EINVALIMEDIATYPE; 
    17221743 
Note: See TracChangeset for help on using the changeset viewer.