Changeset 5050
- Timestamp:
- Apr 7, 2015 11:23:41 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-videodev/colorbar_dev.c
r4722 r5050 18 18 */ 19 19 #include <pjmedia-videodev/videodev_imp.h> 20 #include <pjmedia/clock.h> 20 21 #include <pj/assert.h> 21 22 #include <pj/log.h> … … 28 29 PJMEDIA_VIDEO_DEV_HAS_CBAR_SRC != 0 29 30 30 31 31 32 32 #define THIS_FILE "colorbar_dev.c" … … 35 35 #define DEFAULT_HEIGHT 288 //480 36 36 #define DEFAULT_FPS 25 37 37 38 38 39 /* cbar_ device info */ … … 100 101 pj_timestamp ts; 101 102 unsigned ts_inc; 103 104 /* For active capturer only */ 105 pjmedia_clock *clock; 106 pj_uint8_t *clock_buf; 102 107 }; 103 108 … … 189 194 unsigned i; 190 195 191 cf->dev_count = 1; 196 cf->dev_count = 2; 197 192 198 cf->dev_info = (struct cbar_dev_info*) 193 199 pj_pool_calloc(cf->pool, cf->dev_count, 194 200 sizeof(struct cbar_dev_info)); 195 201 202 /* Passive capturer */ 196 203 ddi = &cf->dev_info[0]; 197 204 pj_bzero(ddi, sizeof(*ddi)); … … 203 210 ddi->info.dir = PJMEDIA_DIR_CAPTURE; 204 211 ddi->info.has_callback = PJ_FALSE; 212 213 ddi->info.caps = PJMEDIA_VID_DEV_CAP_FORMAT; 214 ddi->info.fmt_cnt = sizeof(cbar_fmts)/sizeof(cbar_fmts[0]); 215 for (i = 0; i < ddi->info.fmt_cnt; i++) { 216 pjmedia_format *fmt = &ddi->info.fmt[i]; 217 pjmedia_format_init_video(fmt, cbar_fmts[i].fmt_id, 218 DEFAULT_WIDTH, DEFAULT_HEIGHT, 219 DEFAULT_FPS, 1); 220 } 221 222 /* Active capturer */ 223 ddi = &cf->dev_info[1]; 224 pj_bzero(ddi, sizeof(*ddi)); 225 pj_ansi_strncpy(ddi->info.name, "Colorbar-active", 226 sizeof(ddi->info.name)); 227 ddi->info.driver[sizeof(ddi->info.driver)-1] = '\0'; 228 pj_ansi_strncpy(ddi->info.driver, "Colorbar", sizeof(ddi->info.driver)); 229 ddi->info.driver[sizeof(ddi->info.driver)-1] = '\0'; 230 ddi->info.dir = PJMEDIA_DIR_CAPTURE; 231 ddi->info.has_callback = PJ_TRUE; 205 232 206 233 ddi->info.caps = PJMEDIA_VID_DEV_CAP_FORMAT; … … 376 403 } 377 404 405 406 static void clock_cb(const pj_timestamp *ts, void *user_data) 407 { 408 struct cbar_stream *stream = (struct cbar_stream*)user_data; 409 pjmedia_frame f; 410 pj_status_t status; 411 412 PJ_UNUSED_ARG(ts); 413 414 pj_bzero(&f, sizeof(f)); 415 f.buf = stream->clock_buf; 416 f.size = stream->vafp.framebytes; 417 status = cbar_stream_get_frame(&stream->base, &f); 418 if (status == PJ_SUCCESS) { 419 (*stream->vid_cb.capture_cb)(&stream->base, stream->user_data, &f); 420 } 421 } 422 423 378 424 /* API: create stream */ 379 425 static pj_status_t cbar_factory_create_stream( … … 439 485 } 440 486 */ 487 488 /* Active role? */ 489 if (param->cap_id == 1 && cb && cb->capture_cb) { 490 pjmedia_clock_param clock_param; 491 pj_status_t status; 492 493 /* Allocate buffer */ 494 strm->clock_buf = pj_pool_alloc(pool, strm->vafp.framebytes); 495 496 /* Create clock */ 497 pj_bzero(&clock_param, sizeof(clock_param)); 498 clock_param.usec_interval = PJMEDIA_PTIME(&vfd->fps); 499 clock_param.clock_rate = param->clock_rate; 500 status = pjmedia_clock_create2(pool, &clock_param, 501 PJMEDIA_CLOCK_NO_HIGHEST_PRIO, 502 &clock_cb, 503 strm, &strm->clock); 504 if (status != PJ_SUCCESS) { 505 pj_pool_release(pool); 506 return status; 507 } 508 } 509 441 510 /* Done */ 442 511 strm->base.op = &stream_op; … … 597 666 struct cbar_stream *stream = (struct cbar_stream*)strm; 598 667 599 PJ_UNUSED_ARG(stream);600 601 668 PJ_LOG(4, (THIS_FILE, "Starting cbar video stream")); 669 670 if (stream->clock) 671 return pjmedia_clock_start(stream->clock); 602 672 603 673 return PJ_SUCCESS; … … 609 679 struct cbar_stream *stream = (struct cbar_stream*)strm; 610 680 611 PJ_UNUSED_ARG(stream);612 613 681 PJ_LOG(4, (THIS_FILE, "Stopping cbar video stream")); 682 683 if (stream->clock) 684 return pjmedia_clock_stop(stream->clock); 614 685 615 686 return PJ_SUCCESS; … … 626 697 cbar_stream_stop(strm); 627 698 699 if (stream->clock) 700 pjmedia_clock_destroy(stream->clock); 701 stream->clock = NULL; 702 628 703 pj_pool_release(stream->pool); 629 704
Note: See TracChangeset
for help on using the changeset viewer.