Changeset 3564


Ignore:
Timestamp:
May 10, 2011 12:21:57 PM (13 years ago)
Author:
nanang
Message:

Re #1214:

  • Fixed bug unsynchronized format between encoder and capture device.
  • Added format change detection.
  • Added capture device type setting.
File:
1 edited

Legend:

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

    r3493 r3564  
    1010#define BYPASS_PACKETIZER   0 
    1111 
     12/*  
     13 * Capture device setting:  
     14 *   -1 = colorbar,  
     15 *   -2 = any non-colorbar capture device (first found) 
     16 *    x = specified capture device id 
     17 */ 
     18#define CAPTURE_DEV         -1 
     19 
     20 
    1221typedef struct codec_port_data_t 
    1322{ 
    1423    pjmedia_vid_codec   *codec; 
    15     pjmedia_port        *dn_port; 
     24    pjmedia_vid_port    *rdr_port; 
    1625    pj_uint8_t          *enc_buf; 
    1726    pj_size_t            enc_buf_size; 
     
    7887        status = codec->op->decode(codec, &enc_frame, frame->size, frame); 
    7988        if (status != PJ_SUCCESS) goto on_error; 
     89 
     90        /* Detect format change */ 
     91        if (frame->bit_info & PJMEDIA_VID_CODEC_EVENT_FMT_CHANGED) { 
     92            pjmedia_vid_codec_param codec_param; 
     93 
     94            status = codec->op->get_param(codec, &codec_param); 
     95            if (status != PJ_SUCCESS) goto on_error; 
     96 
     97            status = pjmedia_vid_dev_stream_set_cap( 
     98                            pjmedia_vid_port_get_stream(port_data->rdr_port), 
     99                            PJMEDIA_VID_DEV_CAP_FORMAT, 
     100                            &codec_param.dec_fmt); 
     101            if (status != PJ_SUCCESS) goto on_error; 
     102        } 
    80103    } 
    81104#endif 
    82105 
    83     status = pjmedia_port_put_frame(port_data->dn_port, frame); 
     106    status = pjmedia_port_put_frame( 
     107                        pjmedia_vid_port_get_passive_port(port_data->rdr_port), 
     108                        frame); 
    84109    if (status != PJ_SUCCESS) goto on_error; 
    85110 
     
    131156} 
    132157 
    133 static int encode_decode_test(pj_pool_t *pool, const char *codec_id, 
    134                               pjmedia_format_id raw_fmt_id) 
     158static int encode_decode_test(pj_pool_t *pool, const char *codec_id) 
    135159{ 
    136160    const pj_str_t port_name = {"codec", 5}; 
     
    167191 
    168192 
     193#if CAPTURE_DEV == -1 
    169194    /* Lookup colorbar source */ 
    170195    status = pjmedia_vid_dev_lookup("Colorbar", "Colorbar generator", &cap_idx); 
     
    172197        rc = 206; goto on_return; 
    173198    } 
     199#elif CAPTURE_DEV == -2 
     200    /* Lookup any first non-colorbar source */ 
     201    { 
     202        unsigned i, cnt; 
     203        pjmedia_vid_dev_info info; 
     204 
     205        cap_idx = -1; 
     206        cnt = pjmedia_vid_dev_count(); 
     207        for (i = 0; i < cnt; ++i) { 
     208            status = pjmedia_vid_dev_get_info(i, &info); 
     209            if (status != PJ_SUCCESS) { 
     210                rc = 206; goto on_return; 
     211            } 
     212            if (info.dir & PJMEDIA_DIR_CAPTURE &&  
     213                pj_ansi_stricmp(info.driver, "Colorbar")) 
     214            { 
     215                cap_idx = i; 
     216                break; 
     217            } 
     218        } 
     219 
     220        if (cap_idx == -1) { 
     221            status = PJ_ENOTFOUND; 
     222            rc = 206; goto on_return; 
     223        } 
     224    } 
     225#else 
     226    cap_idx = CAPTURE_DEV; 
     227#endif 
    174228 
    175229    /* Lookup SDL renderer */ 
     
    178232        rc = 207; goto on_return; 
    179233    } 
    180  
    181     raw_fmt_id = codec_info->dec_fmt_id[0]; 
    182     cap_idx = 0; /* Use dshow capture */ 
    183  
    184 #if 0 
    185     // Now, the video port can do automatic conversion. 
    186     /* Raw format ID "not specified", lets find common format among the codec 
    187      * and the video devices 
    188      */ 
    189     if (raw_fmt_id == 0) { 
    190         pjmedia_vid_dev_info cap_info, rdr_info; 
    191         unsigned i, j, k; 
    192  
    193         pjmedia_vid_dev_get_info(cap_idx, &cap_info); 
    194         pjmedia_vid_dev_get_info(rdr_idx, &rdr_info); 
    195  
    196         for (i=0; i<codec_info->dec_fmt_id_cnt && !raw_fmt_id; ++i) { 
    197             for (j=0; j<cap_info.fmt_cnt && !raw_fmt_id; ++j) { 
    198                 if (codec_info->dec_fmt_id[i]==(int)cap_info.fmt[j].id) { 
    199                     for (k=0; k<rdr_info.fmt_cnt && !raw_fmt_id; ++k) { 
    200                         if (codec_info->dec_fmt_id[i]==(int)rdr_info.fmt[k].id) 
    201                         { 
    202                             raw_fmt_id = codec_info->dec_fmt_id[i]; 
    203                         } 
    204                     } 
    205                 } 
    206             } 
    207         } 
    208  
    209         if (raw_fmt_id == 0) { 
    210             PJ_LOG(3, (THIS_FILE, "  No common format ID among the codec " 
    211                        "and the video devices")); 
    212             status = PJ_ENOTFOUND; 
    213             rc = 210; 
    214             goto on_return; 
    215         } 
    216     } 
    217 #endif 
    218234 
    219235    /* Prepare codec */ 
     
    251267        } 
    252268 
    253         codec_param.dec_fmt.id = raw_fmt_id; 
    254269        status = codec->op->open(codec, &codec_param); 
    255270        if (status != PJ_SUCCESS) { 
    256271            rc = 252; goto on_return; 
    257272        } 
     273 
     274        /* After opened, codec will update the param, let's sync encoder &  
     275         * decoder format detail. 
     276         */ 
     277        codec_param.dec_fmt.det = codec_param.enc_fmt.det; 
    258278 
    259279#endif /* !BYPASS_CODEC */ 
     
    270290    } 
    271291    pjmedia_format_copy(&vport_param.vidparam.fmt, &codec_param.dec_fmt); 
    272     vport_param.vidparam.fmt.id = raw_fmt_id; 
    273292    vport_param.vidparam.dir = PJMEDIA_DIR_CAPTURE; 
    274293    vport_param.active = PJ_TRUE; 
     
    310329 
    311330    codec_port_data.codec = codec; 
    312     codec_port_data.dn_port = pjmedia_vid_port_get_passive_port(renderer); 
     331    codec_port_data.rdr_port = renderer; 
    313332    codec_port_data.enc_buf_size = codec_param.dec_fmt.det.vid.size.w * 
    314333                                   codec_param.dec_fmt.det.vid.size.h * 4; 
     
    332351#if BYPASS_CODEC 
    333352    PJ_LOG(3, (THIS_FILE, "  starting loopback test: %c%c%c%c %dx%d", 
    334         ((raw_fmt_id & 0x000000FF) >> 0), 
    335         ((raw_fmt_id & 0x0000FF00) >> 8), 
    336         ((raw_fmt_id & 0x00FF0000) >> 16), 
    337         ((raw_fmt_id & 0xFF000000) >> 24), 
     353        ((codec_param.dec_fmt.id & 0x000000FF) >> 0), 
     354        ((codec_param.dec_fmt.id & 0x0000FF00) >> 8), 
     355        ((codec_param.dec_fmt.id & 0x00FF0000) >> 16), 
     356        ((codec_param.dec_fmt.id & 0xFF000000) >> 24), 
    338357        codec_param.dec_fmt.det.vid.size.w, 
    339358        codec_param.dec_fmt.det.vid.size.h 
     
    411430        goto on_return; 
    412431 
    413     rc = encode_decode_test(pool, "h263", 0); 
     432    rc = encode_decode_test(pool, "h263-1998"); 
    414433    if (rc != 0) 
    415434        goto on_return; 
Note: See TracChangeset for help on using the changeset viewer.