- Timestamp:
- May 10, 2011 12:21:57 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/2.0-dev/pjmedia/src/test/vid_codec_test.c
r3493 r3564 10 10 #define BYPASS_PACKETIZER 0 11 11 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 12 21 typedef struct codec_port_data_t 13 22 { 14 23 pjmedia_vid_codec *codec; 15 pjmedia_ port *dn_port;24 pjmedia_vid_port *rdr_port; 16 25 pj_uint8_t *enc_buf; 17 26 pj_size_t enc_buf_size; … … 78 87 status = codec->op->decode(codec, &enc_frame, frame->size, frame); 79 88 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 } 80 103 } 81 104 #endif 82 105 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); 84 109 if (status != PJ_SUCCESS) goto on_error; 85 110 … … 131 156 } 132 157 133 static int encode_decode_test(pj_pool_t *pool, const char *codec_id, 134 pjmedia_format_id raw_fmt_id) 158 static int encode_decode_test(pj_pool_t *pool, const char *codec_id) 135 159 { 136 160 const pj_str_t port_name = {"codec", 5}; … … 167 191 168 192 193 #if CAPTURE_DEV == -1 169 194 /* Lookup colorbar source */ 170 195 status = pjmedia_vid_dev_lookup("Colorbar", "Colorbar generator", &cap_idx); … … 172 197 rc = 206; goto on_return; 173 198 } 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 174 228 175 229 /* Lookup SDL renderer */ … … 178 232 rc = 207; goto on_return; 179 233 } 180 181 raw_fmt_id = codec_info->dec_fmt_id[0];182 cap_idx = 0; /* Use dshow capture */183 184 #if 0185 // Now, the video port can do automatic conversion.186 /* Raw format ID "not specified", lets find common format among the codec187 * and the video devices188 */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 #endif218 234 219 235 /* Prepare codec */ … … 251 267 } 252 268 253 codec_param.dec_fmt.id = raw_fmt_id;254 269 status = codec->op->open(codec, &codec_param); 255 270 if (status != PJ_SUCCESS) { 256 271 rc = 252; goto on_return; 257 272 } 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; 258 278 259 279 #endif /* !BYPASS_CODEC */ … … 270 290 } 271 291 pjmedia_format_copy(&vport_param.vidparam.fmt, &codec_param.dec_fmt); 272 vport_param.vidparam.fmt.id = raw_fmt_id;273 292 vport_param.vidparam.dir = PJMEDIA_DIR_CAPTURE; 274 293 vport_param.active = PJ_TRUE; … … 310 329 311 330 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; 313 332 codec_port_data.enc_buf_size = codec_param.dec_fmt.det.vid.size.w * 314 333 codec_param.dec_fmt.det.vid.size.h * 4; … … 332 351 #if BYPASS_CODEC 333 352 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), 338 357 codec_param.dec_fmt.det.vid.size.w, 339 358 codec_param.dec_fmt.det.vid.size.h … … 411 430 goto on_return; 412 431 413 rc = encode_decode_test(pool, "h263 ", 0);432 rc = encode_decode_test(pool, "h263-1998"); 414 433 if (rc != 0) 415 434 goto on_return;
Note: See TracChangeset
for help on using the changeset viewer.